* [RFC] selinux: Keep genfscon prefix match semantics in userspace for wildcard
@ 2025-05-09 2:50 Takaya Saeki
2025-05-09 18:23 ` Stephen Smalley
0 siblings, 1 reply; 9+ messages in thread
From: Takaya Saeki @ 2025-05-09 2:50 UTC (permalink / raw)
To: Stephen Smalley, Paul Moore
Cc: selinux, Thiébaud Weksteen, Inseob Kim, Daniel Burgener,
Junichi Uekawa, Tatsuyuki Ishi
Hello Stephen, Paul, and all libselinux maintainers.
I'd like to ask your opinions about an idea to keep the semantics of genfs in
the userspace, before sending a patch to expose the new genfs_seclabel_wildcard
kernel capability to libselinux users in polcaps.h as
POLICYDB_CAP_GENFS_SECLABEL_WILDCARD.
As a background, we introduced the genfs wildcard feature to the kernel selinux
in https://lore.kernel.org/selinux/20250318083139.1515253-1-takayas@chromium.org/
(Thank you for your help and reviews!)
That enabled libselinux to use wildcards in genfs rules. There we changed the
semantics of genfs with the capability enabled in the kernel space from prefix
match to exact match with wildcards for kernel implementation simplicity.
I'm wondering whether we can keep the user-facing semantics of (genfscon ...)
statements in CIL files in the following way.
When secilc compiles a (genfscon ...) statement to the kernel binary format, it
adds a following `*` to the compiled kernel genfscon statement if the input has
(policycap genfs_seclabel_wildcard). If the input doesn't have one, secilc does
not add any following `*`. That keeps the behavior of (genfscon ...) in CIL
from the user perspective with and without the new wildcard capability. This is
similar to what our first kernel patch did, but done in the userspace by secilc
this time. So, the (genfscon ...) keeps the backward compatibility of prefix
match for libselinux users, while keeping the kernel implementation simple.
That would allow users to keep existing rules without modification.
I'd like to hear your opinions.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] selinux: Keep genfscon prefix match semantics in userspace for wildcard
2025-05-09 2:50 [RFC] selinux: Keep genfscon prefix match semantics in userspace for wildcard Takaya Saeki
@ 2025-05-09 18:23 ` Stephen Smalley
2025-05-12 14:31 ` James Carter
0 siblings, 1 reply; 9+ messages in thread
From: Stephen Smalley @ 2025-05-09 18:23 UTC (permalink / raw)
To: Takaya Saeki
Cc: Paul Moore, selinux, Thiébaud Weksteen, Inseob Kim,
Daniel Burgener, Junichi Uekawa, Tatsuyuki Ishi, James Carter
On Thu, May 8, 2025 at 10:50 PM Takaya Saeki <takayas@chromium.org> wrote:
>
> Hello Stephen, Paul, and all libselinux maintainers.
>
> I'd like to ask your opinions about an idea to keep the semantics of genfs in
> the userspace, before sending a patch to expose the new genfs_seclabel_wildcard
> kernel capability to libselinux users in polcaps.h as
> POLICYDB_CAP_GENFS_SECLABEL_WILDCARD.
>
> As a background, we introduced the genfs wildcard feature to the kernel selinux
> in https://lore.kernel.org/selinux/20250318083139.1515253-1-takayas@chromium.org/
> (Thank you for your help and reviews!)
> That enabled libselinux to use wildcards in genfs rules. There we changed the
> semantics of genfs with the capability enabled in the kernel space from prefix
> match to exact match with wildcards for kernel implementation simplicity.
>
> I'm wondering whether we can keep the user-facing semantics of (genfscon ...)
> statements in CIL files in the following way.
>
> When secilc compiles a (genfscon ...) statement to the kernel binary format, it
> adds a following `*` to the compiled kernel genfscon statement if the input has
> (policycap genfs_seclabel_wildcard). If the input doesn't have one, secilc does
> not add any following `*`. That keeps the behavior of (genfscon ...) in CIL
> from the user perspective with and without the new wildcard capability. This is
> similar to what our first kernel patch did, but done in the userspace by secilc
> this time. So, the (genfscon ...) keeps the backward compatibility of prefix
> match for libselinux users, while keeping the kernel implementation simple.
> That would allow users to keep existing rules without modification.
>
> I'd like to hear your opinions.
(added James to cc for the secilc question)
I'm assuming you mean libsepol rather than libselinux. I could be
wrong, but I believe that in general policy capabilities are only
declared once in the policy and typically in the base module, and
those settings are then applied globally to all policy modules. While
you can put one in a non-base module, it still has a global effect on
the final policy. Putting a policycap statement into every CIL module
that wants this behavior would possibly trigger an error (not sure
how/if libsepol/secilc handles duplicate policycap statements) and
regardless would enable it for the entire policy.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] selinux: Keep genfscon prefix match semantics in userspace for wildcard
2025-05-09 18:23 ` Stephen Smalley
@ 2025-05-12 14:31 ` James Carter
2025-05-12 14:47 ` Stephen Smalley
0 siblings, 1 reply; 9+ messages in thread
From: James Carter @ 2025-05-12 14:31 UTC (permalink / raw)
To: Stephen Smalley
Cc: Takaya Saeki, Paul Moore, selinux, Thiébaud Weksteen,
Inseob Kim, Daniel Burgener, Junichi Uekawa, Tatsuyuki Ishi
On Fri, May 9, 2025 at 2:23 PM Stephen Smalley
<stephen.smalley.work@gmail.com> wrote:
>
> On Thu, May 8, 2025 at 10:50 PM Takaya Saeki <takayas@chromium.org> wrote:
> >
> > Hello Stephen, Paul, and all libselinux maintainers.
> >
> > I'd like to ask your opinions about an idea to keep the semantics of genfs in
> > the userspace, before sending a patch to expose the new genfs_seclabel_wildcard
> > kernel capability to libselinux users in polcaps.h as
> > POLICYDB_CAP_GENFS_SECLABEL_WILDCARD.
> >
> > As a background, we introduced the genfs wildcard feature to the kernel selinux
> > in https://lore.kernel.org/selinux/20250318083139.1515253-1-takayas@chromium.org/
> > (Thank you for your help and reviews!)
> > That enabled libselinux to use wildcards in genfs rules. There we changed the
> > semantics of genfs with the capability enabled in the kernel space from prefix
> > match to exact match with wildcards for kernel implementation simplicity.
> >
> > I'm wondering whether we can keep the user-facing semantics of (genfscon ...)
> > statements in CIL files in the following way.
> >
> > When secilc compiles a (genfscon ...) statement to the kernel binary format, it
> > adds a following `*` to the compiled kernel genfscon statement if the input has
> > (policycap genfs_seclabel_wildcard). If the input doesn't have one, secilc does
> > not add any following `*`. That keeps the behavior of (genfscon ...) in CIL
> > from the user perspective with and without the new wildcard capability. This is
> > similar to what our first kernel patch did, but done in the userspace by secilc
> > this time. So, the (genfscon ...) keeps the backward compatibility of prefix
> > match for libselinux users, while keeping the kernel implementation simple.
> > That would allow users to keep existing rules without modification.
> >
> > I'd like to hear your opinions.
>
I agree with this approach. It should only be adding it when writing
the kernel binary policy.
> (added James to cc for the secilc question)
>
> I'm assuming you mean libsepol rather than libselinux. I could be
> wrong, but I believe that in general policy capabilities are only
> declared once in the policy and typically in the base module, and
> those settings are then applied globally to all policy modules. While
> you can put one in a non-base module, it still has a global effect on
> the final policy. Putting a policycap statement into every CIL module
> that wants this behavior would possibly trigger an error (not sure
> how/if libsepol/secilc handles duplicate policycap statements) and
> regardless would enable it for the entire policy.
The policy capability can only be declared once. It will give an error
if there is a duplicate.
But since the CIL modules are not compiled individually, it doesn't
matter where the policy capability is declared. CIL doesn't have the
concept of a base module, all modules are equal. Since Refpolicy
modules are converted to CIL in the policy infrastructure, there is a
base module, but that is because Refpolicy has the concept of a base
module, not because CIL does.
Jim
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] selinux: Keep genfscon prefix match semantics in userspace for wildcard
2025-05-12 14:31 ` James Carter
@ 2025-05-12 14:47 ` Stephen Smalley
2025-05-12 16:56 ` James Carter
0 siblings, 1 reply; 9+ messages in thread
From: Stephen Smalley @ 2025-05-12 14:47 UTC (permalink / raw)
To: James Carter
Cc: Takaya Saeki, Paul Moore, selinux, Thiébaud Weksteen,
Inseob Kim, Daniel Burgener, Junichi Uekawa, Tatsuyuki Ishi
On Mon, May 12, 2025 at 10:31 AM James Carter <jwcart2@gmail.com> wrote:
>
> On Fri, May 9, 2025 at 2:23 PM Stephen Smalley
> <stephen.smalley.work@gmail.com> wrote:
> >
> > On Thu, May 8, 2025 at 10:50 PM Takaya Saeki <takayas@chromium.org> wrote:
> > >
> > > Hello Stephen, Paul, and all libselinux maintainers.
> > >
> > > I'd like to ask your opinions about an idea to keep the semantics of genfs in
> > > the userspace, before sending a patch to expose the new genfs_seclabel_wildcard
> > > kernel capability to libselinux users in polcaps.h as
> > > POLICYDB_CAP_GENFS_SECLABEL_WILDCARD.
> > >
> > > As a background, we introduced the genfs wildcard feature to the kernel selinux
> > > in https://lore.kernel.org/selinux/20250318083139.1515253-1-takayas@chromium.org/
> > > (Thank you for your help and reviews!)
> > > That enabled libselinux to use wildcards in genfs rules. There we changed the
> > > semantics of genfs with the capability enabled in the kernel space from prefix
> > > match to exact match with wildcards for kernel implementation simplicity.
> > >
> > > I'm wondering whether we can keep the user-facing semantics of (genfscon ...)
> > > statements in CIL files in the following way.
> > >
> > > When secilc compiles a (genfscon ...) statement to the kernel binary format, it
> > > adds a following `*` to the compiled kernel genfscon statement if the input has
> > > (policycap genfs_seclabel_wildcard). If the input doesn't have one, secilc does
> > > not add any following `*`. That keeps the behavior of (genfscon ...) in CIL
> > > from the user perspective with and without the new wildcard capability. This is
> > > similar to what our first kernel patch did, but done in the userspace by secilc
> > > this time. So, the (genfscon ...) keeps the backward compatibility of prefix
> > > match for libselinux users, while keeping the kernel implementation simple.
> > > That would allow users to keep existing rules without modification.
> > >
> > > I'd like to hear your opinions.
> >
>
> I agree with this approach. It should only be adding it when writing
> the kernel binary policy.
>
> > (added James to cc for the secilc question)
> >
> > I'm assuming you mean libsepol rather than libselinux. I could be
> > wrong, but I believe that in general policy capabilities are only
> > declared once in the policy and typically in the base module, and
> > those settings are then applied globally to all policy modules. While
> > you can put one in a non-base module, it still has a global effect on
> > the final policy. Putting a policycap statement into every CIL module
> > that wants this behavior would possibly trigger an error (not sure
> > how/if libsepol/secilc handles duplicate policycap statements) and
> > regardless would enable it for the entire policy.
>
> The policy capability can only be declared once. It will give an error
> if there is a duplicate.
>
> But since the CIL modules are not compiled individually, it doesn't
> matter where the policy capability is declared. CIL doesn't have the
> concept of a base module, all modules are equal. Since Refpolicy
> modules are converted to CIL in the policy infrastructure, there is a
> base module, but that is because Refpolicy has the concept of a base
> module, not because CIL does.
I think the problem is that there are multiple CIL modules shipped in
Android (e.g. vendor, platform, oem, ...) and more than one of them
might contain this policycap statement to indicate that its genfscon
statements should be interpreted in this manner. So the final combined
policy that is fed to secilc could end up with duplicates unless they
filter them out, or secilc is modified to ignore dups.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] selinux: Keep genfscon prefix match semantics in userspace for wildcard
2025-05-12 14:47 ` Stephen Smalley
@ 2025-05-12 16:56 ` James Carter
2025-05-13 8:44 ` Inseob Kim
0 siblings, 1 reply; 9+ messages in thread
From: James Carter @ 2025-05-12 16:56 UTC (permalink / raw)
To: Stephen Smalley
Cc: Takaya Saeki, Paul Moore, selinux, Thiébaud Weksteen,
Inseob Kim, Daniel Burgener, Junichi Uekawa, Tatsuyuki Ishi
On Mon, May 12, 2025 at 10:47 AM Stephen Smalley
<stephen.smalley.work@gmail.com> wrote:
>
> On Mon, May 12, 2025 at 10:31 AM James Carter <jwcart2@gmail.com> wrote:
> >
> > On Fri, May 9, 2025 at 2:23 PM Stephen Smalley
> > <stephen.smalley.work@gmail.com> wrote:
> > >
> > > On Thu, May 8, 2025 at 10:50 PM Takaya Saeki <takayas@chromium.org> wrote:
> > > >
> > > > Hello Stephen, Paul, and all libselinux maintainers.
> > > >
> > > > I'd like to ask your opinions about an idea to keep the semantics of genfs in
> > > > the userspace, before sending a patch to expose the new genfs_seclabel_wildcard
> > > > kernel capability to libselinux users in polcaps.h as
> > > > POLICYDB_CAP_GENFS_SECLABEL_WILDCARD.
> > > >
> > > > As a background, we introduced the genfs wildcard feature to the kernel selinux
> > > > in https://lore.kernel.org/selinux/20250318083139.1515253-1-takayas@chromium.org/
> > > > (Thank you for your help and reviews!)
> > > > That enabled libselinux to use wildcards in genfs rules. There we changed the
> > > > semantics of genfs with the capability enabled in the kernel space from prefix
> > > > match to exact match with wildcards for kernel implementation simplicity.
> > > >
> > > > I'm wondering whether we can keep the user-facing semantics of (genfscon ...)
> > > > statements in CIL files in the following way.
> > > >
> > > > When secilc compiles a (genfscon ...) statement to the kernel binary format, it
> > > > adds a following `*` to the compiled kernel genfscon statement if the input has
> > > > (policycap genfs_seclabel_wildcard). If the input doesn't have one, secilc does
> > > > not add any following `*`. That keeps the behavior of (genfscon ...) in CIL
> > > > from the user perspective with and without the new wildcard capability. This is
> > > > similar to what our first kernel patch did, but done in the userspace by secilc
> > > > this time. So, the (genfscon ...) keeps the backward compatibility of prefix
> > > > match for libselinux users, while keeping the kernel implementation simple.
> > > > That would allow users to keep existing rules without modification.
> > > >
> > > > I'd like to hear your opinions.
> > >
> >
> > I agree with this approach. It should only be adding it when writing
> > the kernel binary policy.
> >
> > > (added James to cc for the secilc question)
> > >
> > > I'm assuming you mean libsepol rather than libselinux. I could be
> > > wrong, but I believe that in general policy capabilities are only
> > > declared once in the policy and typically in the base module, and
> > > those settings are then applied globally to all policy modules. While
> > > you can put one in a non-base module, it still has a global effect on
> > > the final policy. Putting a policycap statement into every CIL module
> > > that wants this behavior would possibly trigger an error (not sure
> > > how/if libsepol/secilc handles duplicate policycap statements) and
> > > regardless would enable it for the entire policy.
> >
> > The policy capability can only be declared once. It will give an error
> > if there is a duplicate.
> >
> > But since the CIL modules are not compiled individually, it doesn't
> > matter where the policy capability is declared. CIL doesn't have the
> > concept of a base module, all modules are equal. Since Refpolicy
> > modules are converted to CIL in the policy infrastructure, there is a
> > base module, but that is because Refpolicy has the concept of a base
> > module, not because CIL does.
>
> I think the problem is that there are multiple CIL modules shipped in
> Android (e.g. vendor, platform, oem, ...) and more than one of them
> might contain this policycap statement to indicate that its genfscon
> statements should be interpreted in this manner. So the final combined
> policy that is fed to secilc could end up with duplicates unless they
> filter them out, or secilc is modified to ignore dups.
I don't think it would be a problem to ignore duplicate policycap
statements. It should be a fairly small patch.
Jim
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] selinux: Keep genfscon prefix match semantics in userspace for wildcard
2025-05-12 16:56 ` James Carter
@ 2025-05-13 8:44 ` Inseob Kim
2025-05-13 9:33 ` Takaya Saeki
0 siblings, 1 reply; 9+ messages in thread
From: Inseob Kim @ 2025-05-13 8:44 UTC (permalink / raw)
To: James Carter
Cc: Stephen Smalley, Takaya Saeki, Paul Moore, selinux,
Thiébaud Weksteen, Daniel Burgener, Junichi Uekawa,
Tatsuyuki Ishi
On Tue, May 13, 2025 at 1:57 AM James Carter <jwcart2@gmail.com> wrote:
>
> On Mon, May 12, 2025 at 10:47 AM Stephen Smalley
> <stephen.smalley.work@gmail.com> wrote:
> >
> > On Mon, May 12, 2025 at 10:31 AM James Carter <jwcart2@gmail.com> wrote:
> > >
> > > On Fri, May 9, 2025 at 2:23 PM Stephen Smalley
> > > <stephen.smalley.work@gmail.com> wrote:
> > > >
> > > > On Thu, May 8, 2025 at 10:50 PM Takaya Saeki <takayas@chromium.org> wrote:
> > > > >
> > > > > Hello Stephen, Paul, and all libselinux maintainers.
> > > > >
> > > > > I'd like to ask your opinions about an idea to keep the semantics of genfs in
> > > > > the userspace, before sending a patch to expose the new genfs_seclabel_wildcard
> > > > > kernel capability to libselinux users in polcaps.h as
> > > > > POLICYDB_CAP_GENFS_SECLABEL_WILDCARD.
> > > > >
> > > > > As a background, we introduced the genfs wildcard feature to the kernel selinux
> > > > > in https://lore.kernel.org/selinux/20250318083139.1515253-1-takayas@chromium.org/
> > > > > (Thank you for your help and reviews!)
> > > > > That enabled libselinux to use wildcards in genfs rules. There we changed the
> > > > > semantics of genfs with the capability enabled in the kernel space from prefix
> > > > > match to exact match with wildcards for kernel implementation simplicity.
> > > > >
> > > > > I'm wondering whether we can keep the user-facing semantics of (genfscon ...)
> > > > > statements in CIL files in the following way.
> > > > >
> > > > > When secilc compiles a (genfscon ...) statement to the kernel binary format, it
> > > > > adds a following `*` to the compiled kernel genfscon statement if the input has
> > > > > (policycap genfs_seclabel_wildcard). If the input doesn't have one, secilc does
> > > > > not add any following `*`. That keeps the behavior of (genfscon ...) in CIL
> > > > > from the user perspective with and without the new wildcard capability. This is
> > > > > similar to what our first kernel patch did, but done in the userspace by secilc
> > > > > this time. So, the (genfscon ...) keeps the backward compatibility of prefix
> > > > > match for libselinux users, while keeping the kernel implementation simple.
> > > > > That would allow users to keep existing rules without modification.
> > > > >
> > > > > I'd like to hear your opinions.
> > > >
> > >
> > > I agree with this approach. It should only be adding it when writing
> > > the kernel binary policy.
> > >
> > > > (added James to cc for the secilc question)
> > > >
> > > > I'm assuming you mean libsepol rather than libselinux. I could be
> > > > wrong, but I believe that in general policy capabilities are only
> > > > declared once in the policy and typically in the base module, and
> > > > those settings are then applied globally to all policy modules. While
> > > > you can put one in a non-base module, it still has a global effect on
> > > > the final policy. Putting a policycap statement into every CIL module
> > > > that wants this behavior would possibly trigger an error (not sure
> > > > how/if libsepol/secilc handles duplicate policycap statements) and
> > > > regardless would enable it for the entire policy.
We keep backward compatibility of (genfscon ...) so they'll always be
prefix-matched. For example, (policycap genfs_seclabel_wildcard) in
./vendor/etc/selinux/vendor_sepolicy.cil won't affect how genfscon
statements in /system/etc/selinux/plat_sepolicy.cil work.
> > >
> > > The policy capability can only be declared once. It will give an error
> > > if there is a duplicate.
> > >
> > > But since the CIL modules are not compiled individually, it doesn't
> > > matter where the policy capability is declared. CIL doesn't have the
> > > concept of a base module, all modules are equal. Since Refpolicy
> > > modules are converted to CIL in the policy infrastructure, there is a
> > > base module, but that is because Refpolicy has the concept of a base
> > > module, not because CIL does.
> >
> > I think the problem is that there are multiple CIL modules shipped in
> > Android (e.g. vendor, platform, oem, ...) and more than one of them
> > might contain this policycap statement to indicate that its genfscon
> > statements should be interpreted in this manner. So the final combined
> > policy that is fed to secilc could end up with duplicates unless they
> > filter them out, or secilc is modified to ignore dups.
>
> I don't think it would be a problem to ignore duplicate policycap
> statements. It should be a fairly small patch.
> Jim
So, simply supporting this (allowing duplicated policycap statements)
will be enough even for the Android case.
--
Inseob Kim | Software Engineer | inseob@google.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] selinux: Keep genfscon prefix match semantics in userspace for wildcard
2025-05-13 8:44 ` Inseob Kim
@ 2025-05-13 9:33 ` Takaya Saeki
2025-05-13 13:08 ` James Carter
0 siblings, 1 reply; 9+ messages in thread
From: Takaya Saeki @ 2025-05-13 9:33 UTC (permalink / raw)
To: Inseob Kim
Cc: James Carter, Stephen Smalley, Paul Moore, selinux,
Thiébaud Weksteen, Daniel Burgener, Junichi Uekawa,
Tatsuyuki Ishi
On Tue, May 13, 2025 at 5:44 PM Inseob Kim <inseob@google.com> wrote:
>
> On Tue, May 13, 2025 at 1:57 AM James Carter <jwcart2@gmail.com> wrote:
> >
> > On Mon, May 12, 2025 at 10:47 AM Stephen Smalley
> > <stephen.smalley.work@gmail.com> wrote:
> > >
> > > On Mon, May 12, 2025 at 10:31 AM James Carter <jwcart2@gmail.com> wrote:
> > > >
> > > > On Fri, May 9, 2025 at 2:23 PM Stephen Smalley
> > > > <stephen.smalley.work@gmail.com> wrote:
> > > > >
> > > > > On Thu, May 8, 2025 at 10:50 PM Takaya Saeki <takayas@chromium.org> wrote:
> > > > > >
> > > > > > Hello Stephen, Paul, and all libselinux maintainers.
> > > > > >
> > > > > > I'd like to ask your opinions about an idea to keep the semantics of genfs in
> > > > > > the userspace, before sending a patch to expose the new genfs_seclabel_wildcard
> > > > > > kernel capability to libselinux users in polcaps.h as
> > > > > > POLICYDB_CAP_GENFS_SECLABEL_WILDCARD.
> > > > > >
> > > > > > As a background, we introduced the genfs wildcard feature to the kernel selinux
> > > > > > in https://lore.kernel.org/selinux/20250318083139.1515253-1-takayas@chromium.org/
> > > > > > (Thank you for your help and reviews!)
> > > > > > That enabled libselinux to use wildcards in genfs rules. There we changed the
> > > > > > semantics of genfs with the capability enabled in the kernel space from prefix
> > > > > > match to exact match with wildcards for kernel implementation simplicity.
> > > > > >
> > > > > > I'm wondering whether we can keep the user-facing semantics of (genfscon ...)
> > > > > > statements in CIL files in the following way.
> > > > > >
> > > > > > When secilc compiles a (genfscon ...) statement to the kernel binary format, it
> > > > > > adds a following `*` to the compiled kernel genfscon statement if the input has
> > > > > > (policycap genfs_seclabel_wildcard). If the input doesn't have one, secilc does
> > > > > > not add any following `*`. That keeps the behavior of (genfscon ...) in CIL
> > > > > > from the user perspective with and without the new wildcard capability. This is
> > > > > > similar to what our first kernel patch did, but done in the userspace by secilc
> > > > > > this time. So, the (genfscon ...) keeps the backward compatibility of prefix
> > > > > > match for libselinux users, while keeping the kernel implementation simple.
> > > > > > That would allow users to keep existing rules without modification.
> > > > > >
> > > > > > I'd like to hear your opinions.
> > > > >
> > > >
> > > > I agree with this approach. It should only be adding it when writing
> > > > the kernel binary policy.
> > > >
> > > > > (added James to cc for the secilc question)
> > > > >
> > > > > I'm assuming you mean libsepol rather than libselinux. I could be
Yes, thanks for the correction.
> > > > > wrong, but I believe that in general policy capabilities are only
> > > > > declared once in the policy and typically in the base module, and
> > > > > those settings are then applied globally to all policy modules. While
> > > > > you can put one in a non-base module, it still has a global effect on
> > > > > the final policy. Putting a policycap statement into every CIL module
> > > > > that wants this behavior would possibly trigger an error (not sure
> > > > > how/if libsepol/secilc handles duplicate policycap statements) and
> > > > > regardless would enable it for the entire policy.
>
> We keep backward compatibility of (genfscon ...) so they'll always be
> prefix-matched. For example, (policycap genfs_seclabel_wildcard) in
> ./vendor/etc/selinux/vendor_sepolicy.cil won't affect how genfscon
> statements in /system/etc/selinux/plat_sepolicy.cil work.
>
> > > >
> > > > The policy capability can only be declared once. It will give an error
> > > > if there is a duplicate.
> > > >
> > > > But since the CIL modules are not compiled individually, it doesn't
> > > > matter where the policy capability is declared. CIL doesn't have the
> > > > concept of a base module, all modules are equal. Since Refpolicy
> > > > modules are converted to CIL in the policy infrastructure, there is a
> > > > base module, but that is because Refpolicy has the concept of a base
> > > > module, not because CIL does.
> > >
> > > I think the problem is that there are multiple CIL modules shipped in
> > > Android (e.g. vendor, platform, oem, ...) and more than one of them
> > > might contain this policycap statement to indicate that its genfscon
> > > statements should be interpreted in this manner. So the final combined
> > > policy that is fed to secilc could end up with duplicates unless they
> > > filter them out, or secilc is modified to ignore dups.
> >
> > I don't think it would be a problem to ignore duplicate policycap
> > statements. It should be a fairly small patch.
> > Jim
>
> So, simply supporting this (allowing duplicated policycap statements)
> will be enough even for the Android case.
>
> --
> Inseob Kim | Software Engineer | inseob@google.com
Thank you all, so I think the idea seems acceptable from both perspectives of
Refpolicy and Android. I'd like to ask whether we have any path to generate a
kernel binary policy that does not involve .cil intermediates and secilc in
practical environments. Is patching secilc (libsepol, to be precise)
sufficient? We know it's enough for Android, but is also true for Refpolicy
environments? There are a lot of se.* tools and I'm not sure if secilc always
plays the role.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] selinux: Keep genfscon prefix match semantics in userspace for wildcard
2025-05-13 9:33 ` Takaya Saeki
@ 2025-05-13 13:08 ` James Carter
2025-05-14 1:55 ` Takaya Saeki
0 siblings, 1 reply; 9+ messages in thread
From: James Carter @ 2025-05-13 13:08 UTC (permalink / raw)
To: Takaya Saeki
Cc: Inseob Kim, Stephen Smalley, Paul Moore, selinux,
Thiébaud Weksteen, Daniel Burgener, Junichi Uekawa,
Tatsuyuki Ishi
On Tue, May 13, 2025 at 5:34 AM Takaya Saeki <takayas@chromium.org> wrote:
>
> On Tue, May 13, 2025 at 5:44 PM Inseob Kim <inseob@google.com> wrote:
> >
> > On Tue, May 13, 2025 at 1:57 AM James Carter <jwcart2@gmail.com> wrote:
> > >
> > > On Mon, May 12, 2025 at 10:47 AM Stephen Smalley
> > > <stephen.smalley.work@gmail.com> wrote:
> > > >
> > > > On Mon, May 12, 2025 at 10:31 AM James Carter <jwcart2@gmail.com> wrote:
> > > > >
> > > > > On Fri, May 9, 2025 at 2:23 PM Stephen Smalley
> > > > > <stephen.smalley.work@gmail.com> wrote:
> > > > > >
> > > > > > On Thu, May 8, 2025 at 10:50 PM Takaya Saeki <takayas@chromium.org> wrote:
> > > > > > >
> > > > > > > Hello Stephen, Paul, and all libselinux maintainers.
> > > > > > >
> > > > > > > I'd like to ask your opinions about an idea to keep the semantics of genfs in
> > > > > > > the userspace, before sending a patch to expose the new genfs_seclabel_wildcard
> > > > > > > kernel capability to libselinux users in polcaps.h as
> > > > > > > POLICYDB_CAP_GENFS_SECLABEL_WILDCARD.
> > > > > > >
> > > > > > > As a background, we introduced the genfs wildcard feature to the kernel selinux
> > > > > > > in https://lore.kernel.org/selinux/20250318083139.1515253-1-takayas@chromium.org/
> > > > > > > (Thank you for your help and reviews!)
> > > > > > > That enabled libselinux to use wildcards in genfs rules. There we changed the
> > > > > > > semantics of genfs with the capability enabled in the kernel space from prefix
> > > > > > > match to exact match with wildcards for kernel implementation simplicity.
> > > > > > >
> > > > > > > I'm wondering whether we can keep the user-facing semantics of (genfscon ...)
> > > > > > > statements in CIL files in the following way.
> > > > > > >
> > > > > > > When secilc compiles a (genfscon ...) statement to the kernel binary format, it
> > > > > > > adds a following `*` to the compiled kernel genfscon statement if the input has
> > > > > > > (policycap genfs_seclabel_wildcard). If the input doesn't have one, secilc does
> > > > > > > not add any following `*`. That keeps the behavior of (genfscon ...) in CIL
> > > > > > > from the user perspective with and without the new wildcard capability. This is
> > > > > > > similar to what our first kernel patch did, but done in the userspace by secilc
> > > > > > > this time. So, the (genfscon ...) keeps the backward compatibility of prefix
> > > > > > > match for libselinux users, while keeping the kernel implementation simple.
> > > > > > > That would allow users to keep existing rules without modification.
> > > > > > >
> > > > > > > I'd like to hear your opinions.
> > > > > >
> > > > >
> > > > > I agree with this approach. It should only be adding it when writing
> > > > > the kernel binary policy.
> > > > >
> > > > > > (added James to cc for the secilc question)
> > > > > >
> > > > > > I'm assuming you mean libsepol rather than libselinux. I could be
>
> Yes, thanks for the correction.
>
> > > > > > wrong, but I believe that in general policy capabilities are only
> > > > > > declared once in the policy and typically in the base module, and
> > > > > > those settings are then applied globally to all policy modules. While
> > > > > > you can put one in a non-base module, it still has a global effect on
> > > > > > the final policy. Putting a policycap statement into every CIL module
> > > > > > that wants this behavior would possibly trigger an error (not sure
> > > > > > how/if libsepol/secilc handles duplicate policycap statements) and
> > > > > > regardless would enable it for the entire policy.
> >
> > We keep backward compatibility of (genfscon ...) so they'll always be
> > prefix-matched. For example, (policycap genfs_seclabel_wildcard) in
> > ./vendor/etc/selinux/vendor_sepolicy.cil won't affect how genfscon
> > statements in /system/etc/selinux/plat_sepolicy.cil work.
> >
> > > > >
> > > > > The policy capability can only be declared once. It will give an error
> > > > > if there is a duplicate.
> > > > >
> > > > > But since the CIL modules are not compiled individually, it doesn't
> > > > > matter where the policy capability is declared. CIL doesn't have the
> > > > > concept of a base module, all modules are equal. Since Refpolicy
> > > > > modules are converted to CIL in the policy infrastructure, there is a
> > > > > base module, but that is because Refpolicy has the concept of a base
> > > > > module, not because CIL does.
> > > >
> > > > I think the problem is that there are multiple CIL modules shipped in
> > > > Android (e.g. vendor, platform, oem, ...) and more than one of them
> > > > might contain this policycap statement to indicate that its genfscon
> > > > statements should be interpreted in this manner. So the final combined
> > > > policy that is fed to secilc could end up with duplicates unless they
> > > > filter them out, or secilc is modified to ignore dups.
> > >
> > > I don't think it would be a problem to ignore duplicate policycap
> > > statements. It should be a fairly small patch.
> > > Jim
> >
> > So, simply supporting this (allowing duplicated policycap statements)
> > will be enough even for the Android case.
> >
> > --
> > Inseob Kim | Software Engineer | inseob@google.com
>
> Thank you all, so I think the idea seems acceptable from both perspectives of
> Refpolicy and Android. I'd like to ask whether we have any path to generate a
> kernel binary policy that does not involve .cil intermediates and secilc in
> practical environments. Is patching secilc (libsepol, to be precise)
> sufficient? We know it's enough for Android, but is also true for Refpolicy
> environments? There are a lot of se.* tools and I'm not sure if secilc always
> plays the role.
checkpolicy is the other way to generate a kernel binary policy, but
if you patch libsepol (specifically, genfs_write() in write.c) you'll
take care of both at the same time.
Jim
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] selinux: Keep genfscon prefix match semantics in userspace for wildcard
2025-05-13 13:08 ` James Carter
@ 2025-05-14 1:55 ` Takaya Saeki
0 siblings, 0 replies; 9+ messages in thread
From: Takaya Saeki @ 2025-05-14 1:55 UTC (permalink / raw)
To: James Carter
Cc: Inseob Kim, Stephen Smalley, Paul Moore, selinux,
Thiébaud Weksteen, Daniel Burgener, Junichi Uekawa,
Tatsuyuki Ishi
On Tue, May 13, 2025 at 10:08 PM James Carter <jwcart2@gmail.com> wrote:
>
> On Tue, May 13, 2025 at 5:34 AM Takaya Saeki <takayas@chromium.org> wrote:
> >
> > On Tue, May 13, 2025 at 5:44 PM Inseob Kim <inseob@google.com> wrote:
> > >
> > > On Tue, May 13, 2025 at 1:57 AM James Carter <jwcart2@gmail.com> wrote:
> > > >
> > > > On Mon, May 12, 2025 at 10:47 AM Stephen Smalley
> > > > <stephen.smalley.work@gmail.com> wrote:
> > > > >
> > > > > On Mon, May 12, 2025 at 10:31 AM James Carter <jwcart2@gmail.com> wrote:
> > > > > >
> > > > > > On Fri, May 9, 2025 at 2:23 PM Stephen Smalley
> > > > > > <stephen.smalley.work@gmail.com> wrote:
> > > > > > >
> > > > > > > On Thu, May 8, 2025 at 10:50 PM Takaya Saeki <takayas@chromium.org> wrote:
> > > > > > > >
> > > > > > > > Hello Stephen, Paul, and all libselinux maintainers.
> > > > > > > >
> > > > > > > > I'd like to ask your opinions about an idea to keep the semantics of genfs in
> > > > > > > > the userspace, before sending a patch to expose the new genfs_seclabel_wildcard
> > > > > > > > kernel capability to libselinux users in polcaps.h as
> > > > > > > > POLICYDB_CAP_GENFS_SECLABEL_WILDCARD.
> > > > > > > >
> > > > > > > > As a background, we introduced the genfs wildcard feature to the kernel selinux
> > > > > > > > in https://lore.kernel.org/selinux/20250318083139.1515253-1-takayas@chromium.org/
> > > > > > > > (Thank you for your help and reviews!)
> > > > > > > > That enabled libselinux to use wildcards in genfs rules. There we changed the
> > > > > > > > semantics of genfs with the capability enabled in the kernel space from prefix
> > > > > > > > match to exact match with wildcards for kernel implementation simplicity.
> > > > > > > >
> > > > > > > > I'm wondering whether we can keep the user-facing semantics of (genfscon ...)
> > > > > > > > statements in CIL files in the following way.
> > > > > > > >
> > > > > > > > When secilc compiles a (genfscon ...) statement to the kernel binary format, it
> > > > > > > > adds a following `*` to the compiled kernel genfscon statement if the input has
> > > > > > > > (policycap genfs_seclabel_wildcard). If the input doesn't have one, secilc does
> > > > > > > > not add any following `*`. That keeps the behavior of (genfscon ...) in CIL
> > > > > > > > from the user perspective with and without the new wildcard capability. This is
> > > > > > > > similar to what our first kernel patch did, but done in the userspace by secilc
> > > > > > > > this time. So, the (genfscon ...) keeps the backward compatibility of prefix
> > > > > > > > match for libselinux users, while keeping the kernel implementation simple.
> > > > > > > > That would allow users to keep existing rules without modification.
> > > > > > > >
> > > > > > > > I'd like to hear your opinions.
> > > > > > >
> > > > > >
> > > > > > I agree with this approach. It should only be adding it when writing
> > > > > > the kernel binary policy.
> > > > > >
> > > > > > > (added James to cc for the secilc question)
> > > > > > >
> > > > > > > I'm assuming you mean libsepol rather than libselinux. I could be
> >
> > Yes, thanks for the correction.
> >
> > > > > > > wrong, but I believe that in general policy capabilities are only
> > > > > > > declared once in the policy and typically in the base module, and
> > > > > > > those settings are then applied globally to all policy modules. While
> > > > > > > you can put one in a non-base module, it still has a global effect on
> > > > > > > the final policy. Putting a policycap statement into every CIL module
> > > > > > > that wants this behavior would possibly trigger an error (not sure
> > > > > > > how/if libsepol/secilc handles duplicate policycap statements) and
> > > > > > > regardless would enable it for the entire policy.
> > >
> > > We keep backward compatibility of (genfscon ...) so they'll always be
> > > prefix-matched. For example, (policycap genfs_seclabel_wildcard) in
> > > ./vendor/etc/selinux/vendor_sepolicy.cil won't affect how genfscon
> > > statements in /system/etc/selinux/plat_sepolicy.cil work.
> > >
> > > > > >
> > > > > > The policy capability can only be declared once. It will give an error
> > > > > > if there is a duplicate.
> > > > > >
> > > > > > But since the CIL modules are not compiled individually, it doesn't
> > > > > > matter where the policy capability is declared. CIL doesn't have the
> > > > > > concept of a base module, all modules are equal. Since Refpolicy
> > > > > > modules are converted to CIL in the policy infrastructure, there is a
> > > > > > base module, but that is because Refpolicy has the concept of a base
> > > > > > module, not because CIL does.
> > > > >
> > > > > I think the problem is that there are multiple CIL modules shipped in
> > > > > Android (e.g. vendor, platform, oem, ...) and more than one of them
> > > > > might contain this policycap statement to indicate that its genfscon
> > > > > statements should be interpreted in this manner. So the final combined
> > > > > policy that is fed to secilc could end up with duplicates unless they
> > > > > filter them out, or secilc is modified to ignore dups.
> > > >
> > > > I don't think it would be a problem to ignore duplicate policycap
> > > > statements. It should be a fairly small patch.
> > > > Jim
> > >
> > > So, simply supporting this (allowing duplicated policycap statements)
> > > will be enough even for the Android case.
> > >
> > > --
> > > Inseob Kim | Software Engineer | inseob@google.com
> >
> > Thank you all, so I think the idea seems acceptable from both perspectives of
> > Refpolicy and Android. I'd like to ask whether we have any path to generate a
> > kernel binary policy that does not involve .cil intermediates and secilc in
> > practical environments. Is patching secilc (libsepol, to be precise)
> > sufficient? We know it's enough for Android, but is also true for Refpolicy
> > environments? There are a lot of se.* tools and I'm not sure if secilc always
> > plays the role.
>
> checkpolicy is the other way to generate a kernel binary policy, but
> if you patch libsepol (specifically, genfs_write() in write.c) you'll
> take care of both at the same time.
> Jim
Great, then we will send actual patches soon. Thank you all for your
valuable input!
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-05-14 1:56 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-09 2:50 [RFC] selinux: Keep genfscon prefix match semantics in userspace for wildcard Takaya Saeki
2025-05-09 18:23 ` Stephen Smalley
2025-05-12 14:31 ` James Carter
2025-05-12 14:47 ` Stephen Smalley
2025-05-12 16:56 ` James Carter
2025-05-13 8:44 ` Inseob Kim
2025-05-13 9:33 ` Takaya Saeki
2025-05-13 13:08 ` James Carter
2025-05-14 1:55 ` Takaya Saeki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).