Skip to contentSkip to conversation

libsepol: drop broken warning on duplicate filename transitions

PATCH Applied Stephen Smalley 3 participants 5 messages May 13, 2020 – May 15, 2020 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 libsepol: drop broken warning on duplicate filename transitions

As per the issue below, libsepol segfaults on loading old kernel policies that contain duplicate filename transition rules. The segfault is due to the fact that the val_to_name arrays have not yet been populated at this point in the policydb_read() processing. Since this warning apparently never worked since it was first introduced, drop it and just silently discard the duplicate like the kernel does. I was not able to produce a policy with such duplicates using the current policy toolchain, either via CIL or via binary modules with manual semodule_link/expand.

Fixes 8fdb2255215a1f14 ("libsepol,checkpolicy: convert rangetrans and filenametrans to hashtabs")
---
 libsepol/src/policydb.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
libsepol/src/policydb.c +1 -8
index 5b289a52..3992ea56 100644
@@ -2655,15 +2655,8 @@ int filename_trans_read(policydb_t *p, struct policy_file *fp)
 			 * Some old policies were wrongly generated with
 			 * duplicate filename transition rules.  For backward
 			 * compatibility, do not reject such policies, just
-			 * issue a warning and ignore the duplicate.
+			 * ignore the duplicate.
 			 */
-			WARN(fp->handle,
-			     "Duplicate name-based type_transition %s %s:%s \"%s\":  %s, ignoring",
-			     p->p_type_val_to_name[ft->stype - 1],
-			     p->p_type_val_to_name[ft->ttype - 1],
-			     p->p_class_val_to_name[ft->tclass - 1],
-			     ft->name,
-			     p->p_type_val_to_name[otype->otype - 1]);
 			free(ft);
 			free(name);
 			free(otype);
Signature · 1 line
2.23.3
#1 lore raw
Quoted 24 lines · Stephen Smalley

As per the issue below, libsepol segfaults on loading old kernel policies that contain duplicate filename transition rules. The segfault is due to the fact that the val_to_name arrays have not yet been populated at this point in the policydb_read() processing. Since this warning apparently never worked since it was first introduced, drop it and just silently discard the duplicate like the kernel does. I was not able to produce a policy with such duplicates using the current policy toolchain, either via CIL or via binary modules with manual semodule_link/expand.

Fixes 8fdb2255215a1f14 ("libsepol,checkpolicy: convert rangetrans and filenametrans to hashtabs")
---
 libsepol/src/policydb.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
libsepol/src/policydb.c +0 -0
index 5b289a52..3992ea56 100644
@@ -2655,15 +2655,8 @@ int filename_trans_read(policydb_t *p, struct policy_file *fp)
                         * Some old policies were wrongly generated with
                         * duplicate filename transition rules.  For backward
                         * compatibility, do not reject such policies, just

libsepol/src/policydb.c int filename_trans_read(policydb_t *p, struct policy_file *fp) · line 2666

Quoted 10 lines
libsepol/src/policydb.c +1 -8
-                        * issue a warning and ignore the duplicate.
+                        * ignore the duplicate.
                         */
-                       WARN(fp->handle,
-                            "Duplicate name-based type_transition %s %s:%s \"%s\":  %s, ignoring",
-                            p->p_type_val_to_name[ft->stype - 1],
-                            p->p_type_val_to_name[ft->ttype - 1],
-                            p->p_class_val_to_name[ft->tclass - 1],
-                            ft->name,
-                            p->p_type_val_to_name[otype->otype - 1]);

Not sure if it's the same situation, but should we also do something about a similar pattern in checkpolicy/policy_define.c?

https://github.com/SELinuxProject/selinux/blob/63bf6afe5ed20e1d62f966de65882dc327fb2915/checkpolicy/policy_define.c#L3408

Quoted 6 lines
libsepol/src/policydb.c +0 -1
                        free(ft);
                        free(name);
                        free(otype);
--

2.23.3

Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
author maintainer
#2 lore raw
Quoted 41 lines · Ondrej Mosnacek
Quoted 24 lines · Stephen Smalley

As per the issue below, libsepol segfaults on loading old kernel policies that contain duplicate filename transition rules. The segfault is due to the fact that the val_to_name arrays have not yet been populated at this point in the policydb_read() processing. Since this warning apparently never worked since it was first introduced, drop it and just silently discard the duplicate like the kernel does. I was not able to produce a policy with such duplicates using the current policy toolchain, either via CIL or via binary modules with manual semodule_link/expand.

Fixes 8fdb2255215a1f14 ("libsepol,checkpolicy: convert rangetrans and filenametrans to hashtabs")
---
 libsepol/src/policydb.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
libsepol/src/policydb.c +0 -0
index 5b289a52..3992ea56 100644
@@ -2655,15 +2655,8 @@ int filename_trans_read(policydb_t *p, struct policy_file *fp)
                         * Some old policies were wrongly generated with
                         * duplicate filename transition rules.  For backward
                         * compatibility, do not reject such policies, just

libsepol/src/policydb.c int filename_trans_read(policydb_t *p, struct policy_file *fp) · line 2666

Quoted 10 lines
libsepol/src/policydb.c +1 -8
-                        * issue a warning and ignore the duplicate.
+                        * ignore the duplicate.
                         */
-                       WARN(fp->handle,
-                            "Duplicate name-based type_transition %s %s:%s \"%s\":  %s, ignoring",
-                            p->p_type_val_to_name[ft->stype - 1],
-                            p->p_type_val_to_name[ft->ttype - 1],
-                            p->p_class_val_to_name[ft->tclass - 1],
-                            ft->name,
-                            p->p_type_val_to_name[otype->otype - 1]);

Not sure if it's the same situation, but should we also do something about a similar pattern in checkpolicy/policy_define.c?

Quoted 1 line

https://github.com/SELinuxProject/selinux/blob/63bf6afe5ed20e1d62f966de65882dc327fb2915/checkpolicy/policy_define.c#L3408

No, in that case we are compiling source policy and we want to warn on it to encourage removal of duplicates (and we have populated the val_to_name arrays there so the warning works).

#3 lore raw
Quoted 42 lines · Stephen Smalley
Quoted 41 lines · Ondrej Mosnacek
Quoted 24 lines · Stephen Smalley

As per the issue below, libsepol segfaults on loading old kernel policies that contain duplicate filename transition rules. The segfault is due to the fact that the val_to_name arrays have not yet been populated at this point in the policydb_read() processing. Since this warning apparently never worked since it was first introduced, drop it and just silently discard the duplicate like the kernel does. I was not able to produce a policy with such duplicates using the current policy toolchain, either via CIL or via binary modules with manual semodule_link/expand.

Fixes 8fdb2255215a1f14 ("libsepol,checkpolicy: convert rangetrans and filenametrans to hashtabs")
---
 libsepol/src/policydb.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
libsepol/src/policydb.c +0 -0
index 5b289a52..3992ea56 100644
@@ -2655,15 +2655,8 @@ int filename_trans_read(policydb_t *p, struct policy_file *fp)
                         * Some old policies were wrongly generated with
                         * duplicate filename transition rules.  For backward
                         * compatibility, do not reject such policies, just

libsepol/src/policydb.c int filename_trans_read(policydb_t *p, struct policy_file *fp) · line 2666

Quoted 10 lines
libsepol/src/policydb.c +1 -8
-                        * issue a warning and ignore the duplicate.
+                        * ignore the duplicate.
                         */
-                       WARN(fp->handle,
-                            "Duplicate name-based type_transition %s %s:%s \"%s\":  %s, ignoring",
-                            p->p_type_val_to_name[ft->stype - 1],
-                            p->p_type_val_to_name[ft->ttype - 1],
-                            p->p_class_val_to_name[ft->tclass - 1],
-                            ft->name,
-                            p->p_type_val_to_name[otype->otype - 1]);

Not sure if it's the same situation, but should we also do something about a similar pattern in checkpolicy/policy_define.c?

Quoted 5 lines
Quoted 1 line

https://github.com/SELinuxProject/selinux/blob/63bf6afe5ed20e1d62f966de65882dc327fb2915/checkpolicy/policy_define.c#L3408

No, in that case we are compiling source policy and we want to warn on it to encourage removal of duplicates (and we have populated the val_to_name arrays there so the warning works).

Ok, makes sense. In that case:

Signature · 3 lines
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
#4 lore raw
Quoted 46 lines · Ondrej Mosnacek
Quoted 44 lines · Stephen Smalley
Quoted 42 lines · Ondrej Mosnacek
Quoted 24 lines · Stephen Smalley

As per the issue below, libsepol segfaults on loading old kernel policies that contain duplicate filename transition rules. The segfault is due to the fact that the val_to_name arrays have not yet been populated at this point in the policydb_read() processing. Since this warning apparently never worked since it was first introduced, drop it and just silently discard the duplicate like the kernel does. I was not able to produce a policy with such duplicates using the current policy toolchain, either via CIL or via binary modules with manual semodule_link/expand.

Fixes 8fdb2255215a1f14 ("libsepol,checkpolicy: convert rangetrans and filenametrans to hashtabs")
---
 libsepol/src/policydb.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
libsepol/src/policydb.c +0 -0
index 5b289a52..3992ea56 100644
@@ -2655,15 +2655,8 @@ int filename_trans_read(policydb_t *p, struct policy_file *fp)
                         * Some old policies were wrongly generated with
                         * duplicate filename transition rules.  For backward
                         * compatibility, do not reject such policies, just

libsepol/src/policydb.c int filename_trans_read(policydb_t *p, struct policy_file *fp) · line 2666

Quoted 10 lines
libsepol/src/policydb.c +1 -8
-                        * issue a warning and ignore the duplicate.
+                        * ignore the duplicate.
                         */
-                       WARN(fp->handle,
-                            "Duplicate name-based type_transition %s %s:%s \"%s\":  %s, ignoring",
-                            p->p_type_val_to_name[ft->stype - 1],
-                            p->p_type_val_to_name[ft->ttype - 1],
-                            p->p_class_val_to_name[ft->tclass - 1],
-                            ft->name,
-                            p->p_type_val_to_name[otype->otype - 1]);

Not sure if it's the same situation, but should we also do something about a similar pattern in checkpolicy/policy_define.c?

https://github.com/SELinuxProject/selinux/blob/63bf6afe5ed20e1d62f966de65882dc327fb2915/checkpolicy/policy_define.c#L3408

Quoted 8 lines
Quoted 3 lines

No, in that case we are compiling source policy and we want to warn on it to encourage removal of duplicates (and we have populated the val_to_name arrays there so the warning works).

Ok, makes sense. In that case:

Applied.