* [PATCH v2 1/2] selinux: enable per-file labeling for functionfs
@ 2025-08-27 22:22 Neill Kapron
2025-08-27 22:22 ` [PATCH v2 2/2] libsepol: Support functionfs_seclabel policycap Neill Kapron
2025-08-28 13:08 ` [PATCH v2 1/2] selinux: enable per-file labeling for functionfs Stephen Smalley
0 siblings, 2 replies; 5+ messages in thread
From: Neill Kapron @ 2025-08-27 22:22 UTC (permalink / raw)
To: Paul Moore, Stephen Smalley, Ondrej Mosnacek
Cc: Neill Kapron, kernel-team, linux-kernel, selinux
This patch adds support for genfscon per-file labeling of functionfs
files as well as support for userspace to apply labels after new
functionfs endpoints are created.
This allows for separate labels and therefore access control on a
per-endpoint basis. An example use case would be for the default
endpoint EP0 used as a restricted control endpoint, and additional
usb endpoints to be used by other more permissive domains.
It should be noted that if there are multiple functionfs mounts on a
system, genfs file labels will apply to all mounts, and therefore will not
likely be as useful as the userspace relabeling portion of this patch -
the addition to selinux_is_genfs_special_handling().
This patch introduces the functionfs_seclabel policycap to maintain
existing functionfs genfscon behavior unless explicitly enabled.
Signed-off-by: Neill Kapron <nkapron@google.com>
Changes since v1:
- Add functionfs_seclabel policycap
- Move new functionality to the end of existing lists
---
security/selinux/hooks.c | 8 ++++++--
security/selinux/include/policycap.h | 1 +
security/selinux/include/policycap_names.h | 1 +
security/selinux/include/security.h | 6 ++++++
4 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index e474cd7398ef..333bb6cba25e 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -476,7 +476,9 @@ static int selinux_is_genfs_special_handling(struct super_block *sb)
!strcmp(sb->s_type->name, "rootfs") ||
(selinux_policycap_cgroupseclabel() &&
(!strcmp(sb->s_type->name, "cgroup") ||
- !strcmp(sb->s_type->name, "cgroup2")));
+ !strcmp(sb->s_type->name, "cgroup2"))) ||
+ (selinux_policycap_functionfs_seclabel() &&
+ !strcmp(sb->s_type->name, "functionfs"));
}
static int selinux_is_sblabel_mnt(struct super_block *sb)
@@ -741,7 +743,9 @@ static int selinux_set_mnt_opts(struct super_block *sb,
!strcmp(sb->s_type->name, "binder") ||
!strcmp(sb->s_type->name, "bpf") ||
!strcmp(sb->s_type->name, "pstore") ||
- !strcmp(sb->s_type->name, "securityfs"))
+ !strcmp(sb->s_type->name, "securityfs") ||
+ (selinux_policycap_functionfs_seclabel() &&
+ strcmp(sb->s_type->name, "functionfs")))
sbsec->flags |= SE_SBGENFS;
if (!strcmp(sb->s_type->name, "sysfs") ||
diff --git a/security/selinux/include/policycap.h b/security/selinux/include/policycap.h
index 7405154e6c42..135a969f873c 100644
--- a/security/selinux/include/policycap.h
+++ b/security/selinux/include/policycap.h
@@ -17,6 +17,7 @@ enum {
POLICYDB_CAP_NETLINK_XPERM,
POLICYDB_CAP_NETIF_WILDCARD,
POLICYDB_CAP_GENFS_SECLABEL_WILDCARD,
+ POLICYDB_CAP_FUNCTIONFS_SECLABEL,
__POLICYDB_CAP_MAX
};
#define POLICYDB_CAP_MAX (__POLICYDB_CAP_MAX - 1)
diff --git a/security/selinux/include/policycap_names.h b/security/selinux/include/policycap_names.h
index d8962fcf2ff9..ff8882887651 100644
--- a/security/selinux/include/policycap_names.h
+++ b/security/selinux/include/policycap_names.h
@@ -20,6 +20,7 @@ const char *const selinux_policycap_names[__POLICYDB_CAP_MAX] = {
"netlink_xperm",
"netif_wildcard",
"genfs_seclabel_wildcard",
+ "functionfs_seclabel",
};
/* clang-format on */
diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h
index 7f19972f7922..0f954a40d3fc 100644
--- a/security/selinux/include/security.h
+++ b/security/selinux/include/security.h
@@ -203,6 +203,12 @@ static inline bool selinux_policycap_netlink_xperm(void)
selinux_state.policycap[POLICYDB_CAP_NETLINK_XPERM]);
}
+static inline bool selinux_policycap_functionfs_seclabel(void)
+{
+ return READ_ONCE(
+ selinux_state.policycap[POLICYDB_CAP_FUNCTIONFS_SECLABEL]);
+}
+
struct selinux_policy_convert_data;
struct selinux_load_state {
--
2.51.0.318.gd7df087d1a-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] libsepol: Support functionfs_seclabel policycap
2025-08-27 22:22 [PATCH v2 1/2] selinux: enable per-file labeling for functionfs Neill Kapron
@ 2025-08-27 22:22 ` Neill Kapron
2025-08-28 13:13 ` Stephen Smalley
2025-08-28 13:08 ` [PATCH v2 1/2] selinux: enable per-file labeling for functionfs Stephen Smalley
1 sibling, 1 reply; 5+ messages in thread
From: Neill Kapron @ 2025-08-27 22:22 UTC (permalink / raw)
To: Paul Moore, Stephen Smalley, Ondrej Mosnacek
Cc: Neill Kapron, kernel-team, linux-kernel, selinux
This adds the necessary userspace pieces to support the
functionfs_seclabel policycap which enables per-file labels in
functionfs and the ability for userspace to apply the labels.
With the policycap disabled, legacy behaviors are maintained and
per-file labeling is disallowed.
Signed-off-by: Neill Kapron <nkapron@google.com>
---
libsepol/include/sepol/policydb/polcaps.h | 1 +
libsepol/src/polcaps.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/libsepol/include/sepol/policydb/polcaps.h b/libsepol/include/sepol/policydb/polcaps.h
index 0835ea21..bbaebf1a 100644
--- a/libsepol/include/sepol/policydb/polcaps.h
+++ b/libsepol/include/sepol/policydb/polcaps.h
@@ -19,6 +19,7 @@ enum {
POLICYDB_CAP_NETLINK_XPERM,
POLICYDB_CAP_NETIF_WILDCARD,
POLICYDB_CAP_GENFS_SECLABEL_WILDCARD,
+ POLICYDB_CAP_FUNCTIONFS_SECLABEL,
__POLICYDB_CAP_MAX
};
#define POLICYDB_CAP_MAX (__POLICYDB_CAP_MAX - 1)
diff --git a/libsepol/src/polcaps.c b/libsepol/src/polcaps.c
index 7ac0ae7c..83eb6143 100644
--- a/libsepol/src/polcaps.c
+++ b/libsepol/src/polcaps.c
@@ -18,6 +18,7 @@ static const char * const polcap_names[POLICYDB_CAP_MAX + 1] = {
[POLICYDB_CAP_NETLINK_XPERM] = "netlink_xperm",
[POLICYDB_CAP_NETIF_WILDCARD] = "netif_wildcard",
[POLICYDB_CAP_GENFS_SECLABEL_WILDCARD] = "genfs_seclabel_wildcard",
+ [POLICYDB_CAP_FUNCTIONFS_SECLABEL] = "functionfs_seclabel",
};
int sepol_polcap_getnum(const char *name)
--
2.51.0.318.gd7df087d1a-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] selinux: enable per-file labeling for functionfs
2025-08-27 22:22 [PATCH v2 1/2] selinux: enable per-file labeling for functionfs Neill Kapron
2025-08-27 22:22 ` [PATCH v2 2/2] libsepol: Support functionfs_seclabel policycap Neill Kapron
@ 2025-08-28 13:08 ` Stephen Smalley
2025-08-28 15:13 ` Neill Kapron
1 sibling, 1 reply; 5+ messages in thread
From: Stephen Smalley @ 2025-08-28 13:08 UTC (permalink / raw)
To: Neill Kapron
Cc: Paul Moore, Ondrej Mosnacek, kernel-team, linux-kernel, selinux
On Wed, Aug 27, 2025 at 6:22 PM Neill Kapron <nkapron@google.com> wrote:
>
> This patch adds support for genfscon per-file labeling of functionfs
> files as well as support for userspace to apply labels after new
> functionfs endpoints are created.
>
> This allows for separate labels and therefore access control on a
> per-endpoint basis. An example use case would be for the default
> endpoint EP0 used as a restricted control endpoint, and additional
> usb endpoints to be used by other more permissive domains.
>
> It should be noted that if there are multiple functionfs mounts on a
> system, genfs file labels will apply to all mounts, and therefore will not
> likely be as useful as the userspace relabeling portion of this patch -
> the addition to selinux_is_genfs_special_handling().
>
> This patch introduces the functionfs_seclabel policycap to maintain
> existing functionfs genfscon behavior unless explicitly enabled.
>
> Signed-off-by: Neill Kapron <nkapron@google.com>
>
> Changes since v1:
> - Add functionfs_seclabel policycap
> - Move new functionality to the end of existing lists
This isn't actually a multi-patch series for the kernel, so don't use
the patch 1/2, patch 2/2 notation since that confuses b4 (it tries to
pull in the 2nd patch for libsepol and unsurprisingly that won't apply
to the kernel). Not sure that warrants re-posting (defer to Paul). The
patch itself looks fine to me but we now have 3 pending patches each
of which is trying to claim the next available policy capability bit,
so we'll ultimately need to de-conflict for upstream merge. Otherwise,
you can add my:
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
> ---
> security/selinux/hooks.c | 8 ++++++--
> security/selinux/include/policycap.h | 1 +
> security/selinux/include/policycap_names.h | 1 +
> security/selinux/include/security.h | 6 ++++++
> 4 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index e474cd7398ef..333bb6cba25e 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -476,7 +476,9 @@ static int selinux_is_genfs_special_handling(struct super_block *sb)
> !strcmp(sb->s_type->name, "rootfs") ||
> (selinux_policycap_cgroupseclabel() &&
> (!strcmp(sb->s_type->name, "cgroup") ||
> - !strcmp(sb->s_type->name, "cgroup2")));
> + !strcmp(sb->s_type->name, "cgroup2"))) ||
> + (selinux_policycap_functionfs_seclabel() &&
> + !strcmp(sb->s_type->name, "functionfs"));
> }
>
> static int selinux_is_sblabel_mnt(struct super_block *sb)
> @@ -741,7 +743,9 @@ static int selinux_set_mnt_opts(struct super_block *sb,
> !strcmp(sb->s_type->name, "binder") ||
> !strcmp(sb->s_type->name, "bpf") ||
> !strcmp(sb->s_type->name, "pstore") ||
> - !strcmp(sb->s_type->name, "securityfs"))
> + !strcmp(sb->s_type->name, "securityfs") ||
> + (selinux_policycap_functionfs_seclabel() &&
> + strcmp(sb->s_type->name, "functionfs")))
> sbsec->flags |= SE_SBGENFS;
>
> if (!strcmp(sb->s_type->name, "sysfs") ||
> diff --git a/security/selinux/include/policycap.h b/security/selinux/include/policycap.h
> index 7405154e6c42..135a969f873c 100644
> --- a/security/selinux/include/policycap.h
> +++ b/security/selinux/include/policycap.h
> @@ -17,6 +17,7 @@ enum {
> POLICYDB_CAP_NETLINK_XPERM,
> POLICYDB_CAP_NETIF_WILDCARD,
> POLICYDB_CAP_GENFS_SECLABEL_WILDCARD,
> + POLICYDB_CAP_FUNCTIONFS_SECLABEL,
> __POLICYDB_CAP_MAX
> };
> #define POLICYDB_CAP_MAX (__POLICYDB_CAP_MAX - 1)
> diff --git a/security/selinux/include/policycap_names.h b/security/selinux/include/policycap_names.h
> index d8962fcf2ff9..ff8882887651 100644
> --- a/security/selinux/include/policycap_names.h
> +++ b/security/selinux/include/policycap_names.h
> @@ -20,6 +20,7 @@ const char *const selinux_policycap_names[__POLICYDB_CAP_MAX] = {
> "netlink_xperm",
> "netif_wildcard",
> "genfs_seclabel_wildcard",
> + "functionfs_seclabel",
> };
> /* clang-format on */
>
> diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h
> index 7f19972f7922..0f954a40d3fc 100644
> --- a/security/selinux/include/security.h
> +++ b/security/selinux/include/security.h
> @@ -203,6 +203,12 @@ static inline bool selinux_policycap_netlink_xperm(void)
> selinux_state.policycap[POLICYDB_CAP_NETLINK_XPERM]);
> }
>
> +static inline bool selinux_policycap_functionfs_seclabel(void)
> +{
> + return READ_ONCE(
> + selinux_state.policycap[POLICYDB_CAP_FUNCTIONFS_SECLABEL]);
> +}
> +
> struct selinux_policy_convert_data;
>
> struct selinux_load_state {
> --
> 2.51.0.318.gd7df087d1a-goog
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] libsepol: Support functionfs_seclabel policycap
2025-08-27 22:22 ` [PATCH v2 2/2] libsepol: Support functionfs_seclabel policycap Neill Kapron
@ 2025-08-28 13:13 ` Stephen Smalley
0 siblings, 0 replies; 5+ messages in thread
From: Stephen Smalley @ 2025-08-28 13:13 UTC (permalink / raw)
To: Neill Kapron
Cc: Paul Moore, Ondrej Mosnacek, kernel-team, linux-kernel, selinux
On Wed, Aug 27, 2025 at 6:22 PM Neill Kapron <nkapron@google.com> wrote:
>
> This adds the necessary userspace pieces to support the
> functionfs_seclabel policycap which enables per-file labels in
> functionfs and the ability for userspace to apply the labels.
>
> With the policycap disabled, legacy behaviors are maintained and
> per-file labeling is disallowed.
>
> Signed-off-by: Neill Kapron <nkapron@google.com>
Just a note for other SELinux userspace maintainers: we need to
de-conflict the currently pending 3 kernel patches each trying to
claim the next available policy capability bit so don't merge any of
the libsepol patches until that gets resolved please.
> ---
> libsepol/include/sepol/policydb/polcaps.h | 1 +
> libsepol/src/polcaps.c | 1 +
> 2 files changed, 2 insertions(+)
>
> diff --git a/libsepol/include/sepol/policydb/polcaps.h b/libsepol/include/sepol/policydb/polcaps.h
> index 0835ea21..bbaebf1a 100644
> --- a/libsepol/include/sepol/policydb/polcaps.h
> +++ b/libsepol/include/sepol/policydb/polcaps.h
> @@ -19,6 +19,7 @@ enum {
> POLICYDB_CAP_NETLINK_XPERM,
> POLICYDB_CAP_NETIF_WILDCARD,
> POLICYDB_CAP_GENFS_SECLABEL_WILDCARD,
> + POLICYDB_CAP_FUNCTIONFS_SECLABEL,
> __POLICYDB_CAP_MAX
> };
> #define POLICYDB_CAP_MAX (__POLICYDB_CAP_MAX - 1)
> diff --git a/libsepol/src/polcaps.c b/libsepol/src/polcaps.c
> index 7ac0ae7c..83eb6143 100644
> --- a/libsepol/src/polcaps.c
> +++ b/libsepol/src/polcaps.c
> @@ -18,6 +18,7 @@ static const char * const polcap_names[POLICYDB_CAP_MAX + 1] = {
> [POLICYDB_CAP_NETLINK_XPERM] = "netlink_xperm",
> [POLICYDB_CAP_NETIF_WILDCARD] = "netif_wildcard",
> [POLICYDB_CAP_GENFS_SECLABEL_WILDCARD] = "genfs_seclabel_wildcard",
> + [POLICYDB_CAP_FUNCTIONFS_SECLABEL] = "functionfs_seclabel",
> };
>
> int sepol_polcap_getnum(const char *name)
> --
> 2.51.0.318.gd7df087d1a-goog
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] selinux: enable per-file labeling for functionfs
2025-08-28 13:08 ` [PATCH v2 1/2] selinux: enable per-file labeling for functionfs Stephen Smalley
@ 2025-08-28 15:13 ` Neill Kapron
0 siblings, 0 replies; 5+ messages in thread
From: Neill Kapron @ 2025-08-28 15:13 UTC (permalink / raw)
To: Stephen Smalley
Cc: Paul Moore, Ondrej Mosnacek, kernel-team, linux-kernel, selinux
On Thu, Aug 28, 2025 at 09:08:48AM -0400, Stephen Smalley wrote:
> This isn't actually a multi-patch series for the kernel, so don't use
> the patch 1/2, patch 2/2 notation since that confuses b4 (it tries to
> pull in the 2nd patch for libsepol and unsurprisingly that won't apply
> to the kernel). Not sure that warrants re-posting (defer to Paul).
Whoops, I will send separate patches as v3.
Thanks,
Neill
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-28 15:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27 22:22 [PATCH v2 1/2] selinux: enable per-file labeling for functionfs Neill Kapron
2025-08-27 22:22 ` [PATCH v2 2/2] libsepol: Support functionfs_seclabel policycap Neill Kapron
2025-08-28 13:13 ` Stephen Smalley
2025-08-28 13:08 ` [PATCH v2 1/2] selinux: enable per-file labeling for functionfs Stephen Smalley
2025-08-28 15:13 ` Neill Kapron
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).