* [PATCH] selinux: reject a policy that both rejects and allows unknown classes
@ 2026-09-17 14:20 Christian Göttsche
2026-09-17 14:26 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Christian Göttsche @ 2026-09-17 14:20 UTC (permalink / raw)
To: selinux
Cc: Paul Moore, Stephen Smalley, Ondrej Mosnacek,
Christian Göttsche
From: Christian Göttsche <cgzones@googlemail.com>
handle-unknown is a single three-valued choice - deny, reject or allow -
but the policydb header spells it as two independent bits and
policydb_read() takes any combination of them.
libsepol writes exactly one of the three values
(POLICYDB_CONFIG_UNKNOWN_MASK & p->handle_unknown), so no policy built by
the reference toolchain carries this combination.
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
security/selinux/ss/policydb.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 4342258cb148..7eeaf7076c52 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -2844,7 +2844,8 @@ int policydb_read(struct policydb *p, struct policy_file *fp)
goto bad;
}
- if ((le32_to_cpu(buf[1]) & POLICYDB_CONFIG_MLS)) {
+ val = le32_to_cpu(buf[1]);
+ if (val & POLICYDB_CONFIG_MLS) {
p->mls_enabled = 1;
rc = -EINVAL;
@@ -2855,8 +2856,13 @@ int policydb_read(struct policydb *p, struct policy_file *fp)
goto bad;
}
}
- p->reject_unknown = !!(le32_to_cpu(buf[1]) & REJECT_UNKNOWN);
- p->allow_unknown = !!(le32_to_cpu(buf[1]) & ALLOW_UNKNOWN);
+ rc = -EINVAL;
+ if ((val & (REJECT_UNKNOWN | ALLOW_UNKNOWN)) == (REJECT_UNKNOWN | ALLOW_UNKNOWN)) {
+ pr_err("SELinux: policydb configuration both rejects and allows unknown classes and permissions\n");
+ goto bad;
+ }
+ p->reject_unknown = !!(val & REJECT_UNKNOWN);
+ p->allow_unknown = !!(val & ALLOW_UNKNOWN);
if (p->policyvers >= POLICYDB_VERSION_POLCAP) {
rc = ebitmap_read(&p->policycaps, fp);
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] selinux: reject a policy that both rejects and allows unknown classes
2026-09-17 14:20 [PATCH] selinux: reject a policy that both rejects and allows unknown classes Christian Göttsche
@ 2026-09-17 14:26 ` sashiko-bot
2026-09-18 14:12 ` Stephen Smalley
2026-09-24 21:08 ` Paul Moore
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-09-17 14:26 UTC (permalink / raw)
Cc: selinux
> From: Christian Göttsche <cgzones@googlemail.com>
>
> handle-unknown is a single three-valued choice - deny, reject or allow -
> but the policydb header spells it as two independent bits and
> policydb_read() takes any combination of them.
>
> libsepol writes exactly one of the three values
> (POLICYDB_CONFIG_UNKNOWN_MASK & p->handle_unknown), so no policy built by
> the reference toolchain carries this combination.
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260917142038.60637-1-cgoettsche@seltendoof.de?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] selinux: reject a policy that both rejects and allows unknown classes
2026-09-17 14:20 [PATCH] selinux: reject a policy that both rejects and allows unknown classes Christian Göttsche
2026-09-17 14:26 ` sashiko-bot
@ 2026-09-18 14:12 ` Stephen Smalley
2026-09-24 21:08 ` Paul Moore
2 siblings, 0 replies; 4+ messages in thread
From: Stephen Smalley @ 2026-09-18 14:12 UTC (permalink / raw)
To: cgzones; +Cc: selinux, Paul Moore, Ondrej Mosnacek
On Thu, Sep 17, 2026 at 10:20 AM Christian Göttsche
<cgoettsche@seltendoof.de> wrote:
>
> From: Christian Göttsche <cgzones@googlemail.com>
>
> handle-unknown is a single three-valued choice - deny, reject or allow -
> but the policydb header spells it as two independent bits and
> policydb_read() takes any combination of them.
>
> libsepol writes exactly one of the three values
> (POLICYDB_CONFIG_UNKNOWN_MASK & p->handle_unknown), so no policy built by
> the reference toolchain carries this combination.
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] selinux: reject a policy that both rejects and allows unknown classes
2026-09-17 14:20 [PATCH] selinux: reject a policy that both rejects and allows unknown classes Christian Göttsche
2026-09-17 14:26 ` sashiko-bot
2026-09-18 14:12 ` Stephen Smalley
@ 2026-09-24 21:08 ` Paul Moore
2 siblings, 0 replies; 4+ messages in thread
From: Paul Moore @ 2026-09-24 21:08 UTC (permalink / raw)
To: Christian Göttsche, selinux
Cc: Stephen Smalley, Ondrej Mosnacek, Christian Göttsche
On Sep 17, 2026 =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgoettsche@seltendoof.de> wrote:
>
> handle-unknown is a single three-valued choice - deny, reject or allow -
> but the policydb header spells it as two independent bits and
> policydb_read() takes any combination of them.
>
> libsepol writes exactly one of the three values
> (POLICYDB_CONFIG_UNKNOWN_MASK & p->handle_unknown), so no policy built by
> the reference toolchain carries this combination.
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
> ---
> security/selinux/ss/policydb.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
Merged into selinux/dev, thanks.
--
paul-moore.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-24 21:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17 14:20 [PATCH] selinux: reject a policy that both rejects and allows unknown classes Christian Göttsche
2026-09-17 14:26 ` sashiko-bot
2026-09-18 14:12 ` Stephen Smalley
2026-09-24 21:08 ` Paul Moore
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox