* [PATCH 0/4] apparmor: provide the kernel feature set at build time
@ 2026-11-17 13:50 Maxime Bélair
2026-11-17 13:50 ` [PATCH 1/4] apparmor: move the feature tables to a header Maxime Bélair
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Maxime Bélair @ 2026-11-17 13:50 UTC (permalink / raw)
To: John Johansen, Georgia Garcia
Cc: apparmor, linux-security-module, Maxime Bélair
AppArmor policy is compiled in user space for the feature set of the
kernel, and the cache of compiled policy is keyed on that set. The set
can only be read from /sys/kernel/security/apparmor/features once the
kernel runs, so the first boot into a kernel with a new feature set
compiles all of the policy.
Every entry of the feature set is a build-time constant. This series
writes the set to a file when the kernel is built and installs it as
/lib/modules/<release>/apparmor/features
so that user space can compile the policy when the kernel is installed,
and the first boot takes it from the cache.
Patches 1 and 2 prepare the feature tables to be built into a host
program, patch 3 writes the file with that program, and patch 4
installs it with the modules.
The file is identical to the output of "aa-features-abi -x" on the
booted kernel.
Maxime Bélair (4):
apparmor: move the feature tables to a header
apparmor: make the feature tables build without kernel headers
apparmor: write the feature set to a file at build time
kbuild: install the AppArmor feature set with the modules
Documentation/admin-guide/LSM/apparmor.rst | 15 ++
scripts/Makefile.modinst | 6 +
security/apparmor/.gitignore | 3 +
security/apparmor/Makefile | 25 ++-
security/apparmor/apparmorfs.c | 127 +--------------
security/apparmor/capability.c | 6 -
security/apparmor/gen_features.c | 100 ++++++++++++
security/apparmor/include/capability.h | 2 -
security/apparmor/include/features.h | 173 +++++++++++++++++++++
security/apparmor/include/net.h | 3 -
security/apparmor/include/resource.h | 2 -
security/apparmor/include/task.h | 4 -
security/apparmor/net.c | 15 --
security/apparmor/resource.c | 5 -
14 files changed, 328 insertions(+), 158 deletions(-)
create mode 100644 security/apparmor/gen_features.c
create mode 100644 security/apparmor/include/features.h
--
2.51.0
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 1/4] apparmor: move the feature tables to a header 2026-11-17 13:50 [PATCH 0/4] apparmor: provide the kernel feature set at build time Maxime Bélair @ 2026-11-17 13:50 ` Maxime Bélair 2026-11-17 13:55 ` sashiko-bot 2026-11-17 13:50 ` [PATCH 2/4] apparmor: make the feature tables build without kernel headers Maxime Bélair ` (2 subsequent siblings) 3 siblings, 1 reply; 9+ messages in thread From: Maxime Bélair @ 2026-11-17 13:50 UTC (permalink / raw) To: John Johansen, Georgia Garcia Cc: apparmor, linux-security-module, Maxime Bélair The tables that describe the securityfs features directory are spread over apparmorfs.c, capability.c, net.c and resource.c. Move them to include/features.h, so that a later patch can also build them into a host program, which writes the feature set to a file when the kernel is built. Three of the tables use a generated mask. Collect the masks in feature_masks.h, apart from the name tables they are generated with. The entries are moved as they are, and the content of the features directory does not change. Signed-off-by: Maxime Bélair <maxime.belair@canonical.com> --- security/apparmor/.gitignore | 1 + security/apparmor/Makefile | 10 +- security/apparmor/apparmorfs.c | 124 +------------------ security/apparmor/capability.c | 6 - security/apparmor/include/capability.h | 2 - security/apparmor/include/features.h | 165 +++++++++++++++++++++++++ security/apparmor/include/net.h | 3 - security/apparmor/include/resource.h | 2 - security/apparmor/net.c | 15 --- security/apparmor/resource.c | 5 - 10 files changed, 178 insertions(+), 155 deletions(-) create mode 100644 security/apparmor/include/features.h diff --git a/security/apparmor/.gitignore b/security/apparmor/.gitignore index 6d1eb1c15c18..921cc7c3e835 100644 --- a/security/apparmor/.gitignore +++ b/security/apparmor/.gitignore @@ -2,3 +2,4 @@ net_names.h capability_names.h rlim_names.h +feature_masks.h diff --git a/security/apparmor/Makefile b/security/apparmor/Makefile index 8aed0d7ed6f5..7d20a09cb116 100644 --- a/security/apparmor/Makefile +++ b/security/apparmor/Makefile @@ -12,7 +12,7 @@ apparmor-$(CONFIG_SECURITY_APPARMOR_HASH) += crypto.o obj-$(CONFIG_SECURITY_APPARMOR_KUNIT_TEST) += apparmor_policy_unpack_test.o apparmor_policy_unpack_test-objs += policy_unpack_test.o -clean-files := capability_names.h rlim_names.h net_names.h +clean-files := capability_names.h rlim_names.h net_names.h feature_masks.h # Build a lower case string table of address family names # Transform lines from @@ -98,6 +98,11 @@ cmd_make-rlim = echo "static const char *const rlim_names[RLIM_NLIMITS] = {" \ sed -r -n 's/^\# ?define[ \t]+RLIMIT_([A-Z0-9_]+).*/\L\1/p' $< | \ tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@ +# Collect the feature masks, without the name tables they are generated with +quiet_cmd_make-masks = GEN $@ +cmd_make-masks = grep -h '^\#define AA_SFS_' $(filter %.h,$^) > $@ + +$(obj)/apparmorfs.o : $(obj)/feature_masks.h $(obj)/capability.o : $(obj)/capability_names.h $(obj)/net.o : $(obj)/net_names.h $(obj)/resource.o : $(obj)/rlim_names.h @@ -112,3 +117,6 @@ $(obj)/net_names.h : $(srctree)/include/linux/socket.h \ $(src)/Makefile $(call cmd,make-af) $(call cmd,make-sock) +$(obj)/feature_masks.h : $(obj)/capability_names.h $(obj)/net_names.h \ + $(obj)/rlim_names.h $(src)/Makefile + $(call cmd,make-masks) diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index a99366467217..9fbe72c4bee7 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -2577,128 +2577,10 @@ static const struct file_operations aa_sfs_profiles_fops = { /** Base file system setup **/ -static struct aa_sfs_entry aa_sfs_entry_file[] = { - AA_SFS_FILE_STRING("mask", - "create read write exec append mmap_exec link lock"), - { } -}; - -static struct aa_sfs_entry aa_sfs_entry_ptrace[] = { - AA_SFS_FILE_STRING("mask", "read trace"), - { } -}; - -static struct aa_sfs_entry aa_sfs_entry_signal[] = { - AA_SFS_FILE_STRING("mask", AA_SFS_SIG_MASK), - { } -}; - -static struct aa_sfs_entry aa_sfs_entry_attach[] = { - AA_SFS_FILE_BOOLEAN("xattr", 1), - { } -}; -static struct aa_sfs_entry aa_sfs_entry_domain[] = { - AA_SFS_FILE_BOOLEAN("change_hat", 1), - AA_SFS_FILE_BOOLEAN("change_hatv", 1), - AA_SFS_FILE_BOOLEAN("unconfined_allowed_children", 1), - AA_SFS_FILE_BOOLEAN("change_onexec", 1), - AA_SFS_FILE_BOOLEAN("change_profile", 1), - AA_SFS_FILE_BOOLEAN("stack", 1), - AA_SFS_FILE_BOOLEAN("fix_binfmt_elf_mmap", 1), - AA_SFS_FILE_BOOLEAN("post_nnp_subset", 1), - AA_SFS_FILE_BOOLEAN("computed_longest_left", 1), - AA_SFS_DIR("attach_conditions", aa_sfs_entry_attach), - AA_SFS_FILE_BOOLEAN("disconnected.path", 1), - AA_SFS_FILE_BOOLEAN("kill.signal", 1), - AA_SFS_FILE_STRING("version", "1.2"), - { } -}; - -static struct aa_sfs_entry aa_sfs_entry_unconfined[] = { - AA_SFS_FILE_BOOLEAN("change_profile", 1), - { } -}; - -static struct aa_sfs_entry aa_sfs_entry_versions[] = { - AA_SFS_FILE_BOOLEAN("v5", 1), - AA_SFS_FILE_BOOLEAN("v6", 1), - AA_SFS_FILE_BOOLEAN("v7", 1), - AA_SFS_FILE_BOOLEAN("v8", 1), - AA_SFS_FILE_BOOLEAN("v9", 1), - { } -}; - -#define PERMS32STR "allow deny subtree cond kill complain prompt audit quiet hide xindex tag label" -static struct aa_sfs_entry aa_sfs_entry_policy[] = { - AA_SFS_DIR("versions", aa_sfs_entry_versions), - AA_SFS_FILE_BOOLEAN("set_load", 1), - AA_SFS_FILE_BOOLEAN("diff-encode", 1), - /* number of out of band transitions supported */ - AA_SFS_FILE_U64("outofband", MAX_OOB_SUPPORTED), - AA_SFS_FILE_U64("permstable32_version", 3), - AA_SFS_FILE_STRING("permstable32", PERMS32STR), - AA_SFS_FILE_U64("state32", 1), - AA_SFS_DIR("unconfined_restrictions", aa_sfs_entry_unconfined), -#ifdef CONFIG_SECURITY_APPARMOR_COMPRESSED_POLICY - AA_SFS_FILE_BOOLEAN("compressed_load", 1), - AA_SFS_FILE_BOOLEAN("extended_policy_header", 1), -#endif - { } -}; - -static struct aa_sfs_entry aa_sfs_entry_mount[] = { - AA_SFS_FILE_STRING("mask", "mount umount pivot_root"), - AA_SFS_FILE_STRING("move_mount", "detached"), - { } -}; - -static struct aa_sfs_entry aa_sfs_entry_ns[] = { - AA_SFS_FILE_BOOLEAN("profile", 1), - AA_SFS_FILE_BOOLEAN("pivot_root", 0), - AA_SFS_FILE_STRING("mask", "userns_create"), - { } -}; - -static struct aa_sfs_entry aa_sfs_entry_dbus[] = { - AA_SFS_FILE_STRING("mask", "acquire send receive"), - { } -}; -static struct aa_sfs_entry aa_sfs_entry_query_label[] = { - AA_SFS_FILE_STRING("perms", "allow deny audit quiet"), - AA_SFS_FILE_BOOLEAN("data", 1), - AA_SFS_FILE_BOOLEAN("multi_transaction", 1), - { } -}; - -static struct aa_sfs_entry aa_sfs_entry_query[] = { - AA_SFS_DIR("label", aa_sfs_entry_query_label), - { } -}; - -static struct aa_sfs_entry aa_sfs_entry_io_uring[] = { - AA_SFS_FILE_STRING("mask", "sqpoll override_creds"), - { } -}; - -static struct aa_sfs_entry aa_sfs_entry_features[] = { - AA_SFS_DIR("policy", aa_sfs_entry_policy), - AA_SFS_DIR("domain", aa_sfs_entry_domain), - AA_SFS_DIR("file", aa_sfs_entry_file), - AA_SFS_DIR("network_v8", aa_sfs_entry_network), - AA_SFS_DIR("network_v9", aa_sfs_entry_networkv9), - AA_SFS_DIR("mount", aa_sfs_entry_mount), - AA_SFS_DIR("namespaces", aa_sfs_entry_ns), - AA_SFS_FILE_U64("capability", VFS_CAP_FLAGS_MASK), - AA_SFS_DIR("rlimit", aa_sfs_entry_rlimit), - AA_SFS_DIR("caps", aa_sfs_entry_caps), - AA_SFS_DIR("ptrace", aa_sfs_entry_ptrace), - AA_SFS_DIR("signal", aa_sfs_entry_signal), - AA_SFS_DIR("dbus", aa_sfs_entry_dbus), - AA_SFS_DIR("query", aa_sfs_entry_query), - AA_SFS_DIR("io_uring", aa_sfs_entry_io_uring), - { } -}; +/* the tables of the features directory */ +#include "feature_masks.h" +#include "include/features.h" static struct aa_sfs_entry aa_sfs_entry_apparmor[] = { AA_SFS_FILE_FOPS(".access", 0666, &aa_sfs_access), diff --git a/security/apparmor/capability.c b/security/apparmor/capability.c index 2f3c6c84358d..7e238043c12a 100644 --- a/security/apparmor/capability.c +++ b/security/apparmor/capability.c @@ -25,12 +25,6 @@ */ #include "capability_names.h" -struct aa_sfs_entry aa_sfs_entry_caps[] = { - AA_SFS_FILE_STRING("mask", AA_SFS_CAPS_MASK), - AA_SFS_FILE_BOOLEAN("extended", 1), - { } -}; - struct audit_cache { const struct cred *ad_subj_cred; /* Capabilities go from 0 to CAP_LAST_CAP */ diff --git a/security/apparmor/include/capability.h b/security/apparmor/include/capability.h index 89a9c75d8f44..e0956eab6c6e 100644 --- a/security/apparmor/include/capability.h +++ b/security/apparmor/include/capability.h @@ -35,8 +35,6 @@ struct aa_caps { kernel_cap_t extended; }; -extern struct aa_sfs_entry aa_sfs_entry_caps[]; - kernel_cap_t aa_profile_capget(const struct aa_profile *profile); int aa_capable(const struct cred *subj_cred, struct aa_label *label, int cap, unsigned int opts); diff --git a/security/apparmor/include/features.h b/security/apparmor/include/features.h new file mode 100644 index 000000000000..97fb3c6acbd4 --- /dev/null +++ b/security/apparmor/include/features.h @@ -0,0 +1,165 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * AppArmor security module + * + * This file contains the tables behind the securityfs features directory, + * /sys/kernel/security/apparmor/features. It defines them, so it is for + * apparmorfs.c alone. + * + * Copyright (C) 1998-2008 Novell/SUSE + * Copyright 2009-2026 Canonical Ltd. + */ + +#ifndef __AA_FEATURES_H +#define __AA_FEATURES_H + +static struct aa_sfs_entry aa_sfs_entry_file[] = { + AA_SFS_FILE_STRING("mask", + "create read write exec append mmap_exec link lock"), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_ptrace[] = { + AA_SFS_FILE_STRING("mask", "read trace"), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_signal[] = { + AA_SFS_FILE_STRING("mask", AA_SFS_SIG_MASK), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_attach[] = { + AA_SFS_FILE_BOOLEAN("xattr", 1), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_domain[] = { + AA_SFS_FILE_BOOLEAN("change_hat", 1), + AA_SFS_FILE_BOOLEAN("change_hatv", 1), + AA_SFS_FILE_BOOLEAN("unconfined_allowed_children", 1), + AA_SFS_FILE_BOOLEAN("change_onexec", 1), + AA_SFS_FILE_BOOLEAN("change_profile", 1), + AA_SFS_FILE_BOOLEAN("stack", 1), + AA_SFS_FILE_BOOLEAN("fix_binfmt_elf_mmap", 1), + AA_SFS_FILE_BOOLEAN("post_nnp_subset", 1), + AA_SFS_FILE_BOOLEAN("computed_longest_left", 1), + AA_SFS_DIR("attach_conditions", aa_sfs_entry_attach), + AA_SFS_FILE_BOOLEAN("disconnected.path", 1), + AA_SFS_FILE_BOOLEAN("kill.signal", 1), + AA_SFS_FILE_STRING("version", "1.2"), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_unconfined[] = { + AA_SFS_FILE_BOOLEAN("change_profile", 1), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_versions[] = { + AA_SFS_FILE_BOOLEAN("v5", 1), + AA_SFS_FILE_BOOLEAN("v6", 1), + AA_SFS_FILE_BOOLEAN("v7", 1), + AA_SFS_FILE_BOOLEAN("v8", 1), + AA_SFS_FILE_BOOLEAN("v9", 1), + { } +}; + +#define PERMS32STR "allow deny subtree cond kill complain prompt audit quiet hide xindex tag label" +static struct aa_sfs_entry aa_sfs_entry_policy[] = { + AA_SFS_DIR("versions", aa_sfs_entry_versions), + AA_SFS_FILE_BOOLEAN("set_load", 1), + AA_SFS_FILE_BOOLEAN("diff-encode", 1), + /* number of out of band transitions supported */ + AA_SFS_FILE_U64("outofband", MAX_OOB_SUPPORTED), + AA_SFS_FILE_U64("permstable32_version", 3), + AA_SFS_FILE_STRING("permstable32", PERMS32STR), + AA_SFS_FILE_U64("state32", 1), + AA_SFS_DIR("unconfined_restrictions", aa_sfs_entry_unconfined), +#ifdef CONFIG_SECURITY_APPARMOR_COMPRESSED_POLICY + AA_SFS_FILE_BOOLEAN("compressed_load", 1), + AA_SFS_FILE_BOOLEAN("extended_policy_header", 1), +#endif + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_mount[] = { + AA_SFS_FILE_STRING("mask", "mount umount pivot_root"), + AA_SFS_FILE_STRING("move_mount", "detached"), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_ns[] = { + AA_SFS_FILE_BOOLEAN("profile", 1), + AA_SFS_FILE_BOOLEAN("pivot_root", 0), + AA_SFS_FILE_STRING("mask", "userns_create"), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_dbus[] = { + AA_SFS_FILE_STRING("mask", "acquire send receive"), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_query_label[] = { + AA_SFS_FILE_STRING("perms", "allow deny audit quiet"), + AA_SFS_FILE_BOOLEAN("data", 1), + AA_SFS_FILE_BOOLEAN("multi_transaction", 1), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_query[] = { + AA_SFS_DIR("label", aa_sfs_entry_query_label), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_io_uring[] = { + AA_SFS_FILE_STRING("mask", "sqpoll override_creds"), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_caps[] = { + AA_SFS_FILE_STRING("mask", AA_SFS_CAPS_MASK), + AA_SFS_FILE_BOOLEAN("extended", 1), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_network[] = { + AA_SFS_FILE_STRING("af_mask", AA_SFS_AF_MASK), + AA_SFS_FILE_BOOLEAN("tcp-fast-open", 1), + AA_SFS_FILE_BOOLEAN("sctp", 1), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_networkv9[] = { + AA_SFS_FILE_STRING("af_mask", AA_SFS_AF_MASK), + AA_SFS_FILE_BOOLEAN("af_unix", 1), + AA_SFS_FILE_BOOLEAN("tcp-fast-open", 1), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_rlimit[] = { + AA_SFS_FILE_STRING("mask", AA_SFS_RLIMIT_MASK), + { } +}; + +static struct aa_sfs_entry aa_sfs_entry_features[] = { + AA_SFS_DIR("policy", aa_sfs_entry_policy), + AA_SFS_DIR("domain", aa_sfs_entry_domain), + AA_SFS_DIR("file", aa_sfs_entry_file), + AA_SFS_DIR("network_v8", aa_sfs_entry_network), + AA_SFS_DIR("network_v9", aa_sfs_entry_networkv9), + AA_SFS_DIR("mount", aa_sfs_entry_mount), + AA_SFS_DIR("namespaces", aa_sfs_entry_ns), + AA_SFS_FILE_U64("capability", VFS_CAP_FLAGS_MASK), + AA_SFS_DIR("rlimit", aa_sfs_entry_rlimit), + AA_SFS_DIR("caps", aa_sfs_entry_caps), + AA_SFS_DIR("ptrace", aa_sfs_entry_ptrace), + AA_SFS_DIR("signal", aa_sfs_entry_signal), + AA_SFS_DIR("dbus", aa_sfs_entry_dbus), + AA_SFS_DIR("query", aa_sfs_entry_query), + AA_SFS_DIR("io_uring", aa_sfs_entry_io_uring), + { } +}; + +#endif /* __AA_FEATURES_H */ diff --git a/security/apparmor/include/net.h b/security/apparmor/include/net.h index 375341929cb6..1e958721e98c 100644 --- a/security/apparmor/include/net.h +++ b/security/apparmor/include/net.h @@ -82,9 +82,6 @@ struct aa_secmark { char *label; }; -extern struct aa_sfs_entry aa_sfs_entry_network[]; -extern struct aa_sfs_entry aa_sfs_entry_networkv9[]; - int aa_do_perms(struct aa_profile *profile, struct aa_policydb *policy, aa_state_t state, u32 request, const struct aa_perms *p, struct apparmor_audit_data *ad); diff --git a/security/apparmor/include/resource.h b/security/apparmor/include/resource.h index ad2c0da8e64f..ac9d8917b15e 100644 --- a/security/apparmor/include/resource.h +++ b/security/apparmor/include/resource.h @@ -30,8 +30,6 @@ struct aa_rlimit { struct rlimit limits[RLIM_NLIMITS]; }; -extern struct aa_sfs_entry aa_sfs_entry_rlimit[]; - int aa_map_resource(int resource); int aa_task_setrlimit(const struct cred *subj_cred, struct aa_label *label, struct task_struct *task, diff --git a/security/apparmor/net.c b/security/apparmor/net.c index 136d14226b97..dd5186b976a6 100644 --- a/security/apparmor/net.c +++ b/security/apparmor/net.c @@ -20,21 +20,6 @@ #include "net_names.h" - -struct aa_sfs_entry aa_sfs_entry_network[] = { - AA_SFS_FILE_STRING("af_mask", AA_SFS_AF_MASK), - AA_SFS_FILE_BOOLEAN("tcp-fast-open", 1), - AA_SFS_FILE_BOOLEAN("sctp", 1), - { } -}; - -struct aa_sfs_entry aa_sfs_entry_networkv9[] = { - AA_SFS_FILE_STRING("af_mask", AA_SFS_AF_MASK), - AA_SFS_FILE_BOOLEAN("af_unix", 1), - AA_SFS_FILE_BOOLEAN("tcp-fast-open", 1), - { } -}; - static const char * const net_mask_names[] = { "unknown", "send", diff --git a/security/apparmor/resource.c b/security/apparmor/resource.c index 64212b39ba4b..700833199b09 100644 --- a/security/apparmor/resource.c +++ b/security/apparmor/resource.c @@ -21,11 +21,6 @@ */ #include "rlim_names.h" -struct aa_sfs_entry aa_sfs_entry_rlimit[] = { - AA_SFS_FILE_STRING("mask", AA_SFS_RLIMIT_MASK), - { } -}; - /* audit callback for resource specific fields */ static void audit_cb(struct audit_buffer *ab, void *va) { -- 2.51.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/4] apparmor: move the feature tables to a header 2026-11-17 13:50 ` [PATCH 1/4] apparmor: move the feature tables to a header Maxime Bélair @ 2026-11-17 13:55 ` sashiko-bot 0 siblings, 0 replies; 9+ messages in thread From: sashiko-bot @ 2026-11-17 13:55 UTC (permalink / raw) Cc: linux-security-module > The tables that describe the securityfs features directory are spread > over apparmorfs.c, capability.c, net.c and resource.c. Move them to > include/features.h, so that a later patch can also build them into a > host program, which writes the feature set to a file when the kernel > is built. > > Three of the tables use a generated mask. Collect the masks in > feature_masks.h, apart from the name tables they are generated with. > > The entries are moved as they are, and the content of the features > directory does not change. > > Signed-off-by: Maxime Bélair <maxime.belair@canonical.com> Sashiko has reviewed this patch and found no issues. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261117135042.78238-1-maxime.belair@canonical.com?part=1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/4] apparmor: make the feature tables build without kernel headers 2026-11-17 13:50 [PATCH 0/4] apparmor: provide the kernel feature set at build time Maxime Bélair 2026-11-17 13:50 ` [PATCH 1/4] apparmor: move the feature tables to a header Maxime Bélair @ 2026-11-17 13:50 ` Maxime Bélair 2026-11-17 13:55 ` sashiko-bot 2026-11-17 13:50 ` [PATCH 3/4] apparmor: write the feature set to a file at build time Maxime Bélair 2026-11-17 13:50 ` [PATCH 4/4] kbuild: install the AppArmor feature set with the modules Maxime Bélair 3 siblings, 1 reply; 9+ messages in thread From: Maxime Bélair @ 2026-11-17 13:50 UTC (permalink / raw) To: John Johansen, Georgia Garcia Cc: apparmor, linux-security-module, Maxime Bélair The feature tables are about to be built into a host program, and a host program cannot include kernel headers, see commit 541b57e31368 ("selinux: do not include <linux/*.h> headers from host programs"). Move AA_SFS_SIG_MASK next to the signal table, and give the tables copies of MAX_OOB_SUPPORTED and VFS_CAP_FLAGS_MASK, which apparmorfs.c checks against the originals with static_assert(). The content of the features directory does not change. Signed-off-by: Maxime Bélair <maxime.belair@canonical.com> --- security/apparmor/apparmorfs.c | 4 ++++ security/apparmor/include/features.h | 11 +++++++++-- security/apparmor/include/task.h | 4 ---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index 9fbe72c4bee7..4ca449b108df 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -2582,6 +2582,10 @@ static const struct file_operations aa_sfs_profiles_fops = { #include "feature_masks.h" #include "include/features.h" +/* features.h cannot include the headers that define these */ +static_assert(AA_SFS_MAX_OOB_SUPPORTED == MAX_OOB_SUPPORTED); +static_assert(AA_SFS_VFS_CAP_FLAGS_MASK == VFS_CAP_FLAGS_MASK); + static struct aa_sfs_entry aa_sfs_entry_apparmor[] = { AA_SFS_FILE_FOPS(".access", 0666, &aa_sfs_access), AA_SFS_FILE_FOPS(".stacked", 0444, &seq_ns_stacked_fops), diff --git a/security/apparmor/include/features.h b/security/apparmor/include/features.h index 97fb3c6acbd4..dc38f54abec6 100644 --- a/security/apparmor/include/features.h +++ b/security/apparmor/include/features.h @@ -13,6 +13,10 @@ #ifndef __AA_FEATURES_H #define __AA_FEATURES_H +/* Copies of kernel header values, apparmorfs.c checks that they match */ +#define AA_SFS_MAX_OOB_SUPPORTED 1 +#define AA_SFS_VFS_CAP_FLAGS_MASK 0x00ffffff + static struct aa_sfs_entry aa_sfs_entry_file[] = { AA_SFS_FILE_STRING("mask", "create read write exec append mmap_exec link lock"), @@ -24,6 +28,9 @@ static struct aa_sfs_entry aa_sfs_entry_ptrace[] = { { } }; +#define AA_SFS_SIG_MASK "hup int quit ill trap abrt bus fpe kill usr1 " \ + "segv usr2 pipe alrm term stkflt chld cont stop stp ttin ttou urg " \ + "xcpu xfsz vtalrm prof winch io pwr sys emt lost" static struct aa_sfs_entry aa_sfs_entry_signal[] = { AA_SFS_FILE_STRING("mask", AA_SFS_SIG_MASK), { } @@ -71,7 +78,7 @@ static struct aa_sfs_entry aa_sfs_entry_policy[] = { AA_SFS_FILE_BOOLEAN("set_load", 1), AA_SFS_FILE_BOOLEAN("diff-encode", 1), /* number of out of band transitions supported */ - AA_SFS_FILE_U64("outofband", MAX_OOB_SUPPORTED), + AA_SFS_FILE_U64("outofband", AA_SFS_MAX_OOB_SUPPORTED), AA_SFS_FILE_U64("permstable32_version", 3), AA_SFS_FILE_STRING("permstable32", PERMS32STR), AA_SFS_FILE_U64("state32", 1), @@ -151,7 +158,7 @@ static struct aa_sfs_entry aa_sfs_entry_features[] = { AA_SFS_DIR("network_v9", aa_sfs_entry_networkv9), AA_SFS_DIR("mount", aa_sfs_entry_mount), AA_SFS_DIR("namespaces", aa_sfs_entry_ns), - AA_SFS_FILE_U64("capability", VFS_CAP_FLAGS_MASK), + AA_SFS_FILE_U64("capability", AA_SFS_VFS_CAP_FLAGS_MASK), AA_SFS_DIR("rlimit", aa_sfs_entry_rlimit), AA_SFS_DIR("caps", aa_sfs_entry_caps), AA_SFS_DIR("ptrace", aa_sfs_entry_ptrace), diff --git a/security/apparmor/include/task.h b/security/apparmor/include/task.h index a8030ed78ff2..0d984724383b 100644 --- a/security/apparmor/include/task.h +++ b/security/apparmor/include/task.h @@ -99,10 +99,6 @@ static inline void aa_clear_task_ctx_trans(struct aa_task_ctx *ctx) AA_MAY_BE_READ | AA_MAY_BE_TRACED) #define AA_SIGNAL_PERM_MASK (MAY_READ | MAY_WRITE) -#define AA_SFS_SIG_MASK "hup int quit ill trap abrt bus fpe kill usr1 " \ - "segv usr2 pipe alrm term stkflt chld cont stop stp ttin ttou urg " \ - "xcpu xfsz vtalrm prof winch io pwr sys emt lost" - int aa_may_ptrace(const struct cred *tracer_cred, struct aa_label *tracer, const struct cred *tracee_cred, struct aa_label *tracee, u32 request); -- 2.51.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/4] apparmor: make the feature tables build without kernel headers 2026-11-17 13:50 ` [PATCH 2/4] apparmor: make the feature tables build without kernel headers Maxime Bélair @ 2026-11-17 13:55 ` sashiko-bot 0 siblings, 0 replies; 9+ messages in thread From: sashiko-bot @ 2026-11-17 13:55 UTC (permalink / raw) Cc: linux-security-module > The feature tables are about to be built into a host program, and a > host program cannot include kernel headers, see commit 541b57e31368 > ("selinux: do not include <linux/*.h> headers from host programs"). > > Move AA_SFS_SIG_MASK next to the signal table, and give the tables > copies of MAX_OOB_SUPPORTED and VFS_CAP_FLAGS_MASK, which apparmorfs.c > checks against the originals with static_assert(). > > The content of the features directory does not change. > > Signed-off-by: Maxime Bélair <maxime.belair@canonical.com> Sashiko has reviewed this patch and found no issues. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261117135042.78238-1-maxime.belair@canonical.com?part=2 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/4] apparmor: write the feature set to a file at build time 2026-11-17 13:50 [PATCH 0/4] apparmor: provide the kernel feature set at build time Maxime Bélair 2026-11-17 13:50 ` [PATCH 1/4] apparmor: move the feature tables to a header Maxime Bélair 2026-11-17 13:50 ` [PATCH 2/4] apparmor: make the feature tables build without kernel headers Maxime Bélair @ 2026-11-17 13:50 ` Maxime Bélair 2026-11-17 14:00 ` sashiko-bot 2026-11-17 13:50 ` [PATCH 4/4] kbuild: install the AppArmor feature set with the modules Maxime Bélair 3 siblings, 1 reply; 9+ messages in thread From: Maxime Bélair @ 2026-11-17 13:50 UTC (permalink / raw) To: John Johansen, Georgia Garcia Cc: apparmor, linux-security-module, Maxime Bélair apparmor_parser compiles policy for the feature set of the kernel, which libapparmor reads from /sys/kernel/security/apparmor/features, and the policy cache is keyed on that set. The cache for a kernel can therefore only be filled once that kernel runs, and the first boot into a kernel with a new feature set compiles all of the policy. Every entry of the features directory comes from a static table of constants. So write the set to security/apparmor/features when the kernel is built, in the format that libapparmor flattens the directory to. Policy can then be compiled when a kernel is installed: apparmor_parser --kernel-features=<file> ... Signed-off-by: Maxime Bélair <maxime.belair@canonical.com> --- security/apparmor/.gitignore | 2 + security/apparmor/Makefile | 15 ++++ security/apparmor/apparmorfs.c | 1 + security/apparmor/gen_features.c | 100 +++++++++++++++++++++++++++ security/apparmor/include/features.h | 5 +- 5 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 security/apparmor/gen_features.c diff --git a/security/apparmor/.gitignore b/security/apparmor/.gitignore index 921cc7c3e835..ff816ca0f22b 100644 --- a/security/apparmor/.gitignore +++ b/security/apparmor/.gitignore @@ -3,3 +3,5 @@ net_names.h capability_names.h rlim_names.h feature_masks.h +/features +/gen_features diff --git a/security/apparmor/Makefile b/security/apparmor/Makefile index 7d20a09cb116..400655ec78a3 100644 --- a/security/apparmor/Makefile +++ b/security/apparmor/Makefile @@ -102,6 +102,21 @@ cmd_make-rlim = echo "static const char *const rlim_names[RLIM_NLIMITS] = {" \ quiet_cmd_make-masks = GEN $@ cmd_make-masks = grep -h '^\#define AA_SFS_' $(filter %.h,$^) > $@ +# Write the feature set to a file, with a host program that is built from the +# feature tables. It needs the kernel configuration, and -idirafter keeps the +# other kernel headers behind the ones of the host. +hostprogs := gen_features +HOSTCFLAGS_gen_features.o := -include $(srctree)/include/linux/kconfig.h \ + -idirafter $(objtree)/include +always-y += features + +quiet_cmd_gen_features = GEN $@ + cmd_gen_features = $< > $@ + +$(obj)/features: $(obj)/gen_features FORCE + $(call if_changed,gen_features) + +$(obj)/gen_features : $(obj)/feature_masks.h $(obj)/apparmorfs.o : $(obj)/feature_masks.h $(obj)/capability.o : $(obj)/capability_names.h $(obj)/net.o : $(obj)/net_names.h diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index 4ca449b108df..b897d2840d77 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -1255,6 +1255,7 @@ static const struct file_operations aa_sfs_access = { .llseek = generic_file_llseek, }; +/* gen_features.c prints the same values at build time, keep them in sync */ static int aa_sfs_seq_show(struct seq_file *seq, void *v) { struct aa_sfs_entry *fs_file = seq->private; diff --git a/security/apparmor/gen_features.c b/security/apparmor/gen_features.c new file mode 100644 index 000000000000..978a1b06ab4b --- /dev/null +++ b/security/apparmor/gen_features.c @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * AppArmor security module + * + * This program writes the feature set of the kernel that is being built, the + * way libapparmor flattens /sys/kernel/security/apparmor/features on the + * running kernel. The policy cache is keyed on it, so the output has to be + * the same byte for byte: the entries of a directory in the strcmp() order of + * their names, each as + * + * <name> {<entries of the directory>}\n + * <name> {<content of the file>}\n + * + * Copyright 2026 Canonical Ltd. + */ + +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +enum aa_sfs_type { + AA_SFS_TYPE_BOOLEAN, + AA_SFS_TYPE_STRING, + AA_SFS_TYPE_U64, + AA_SFS_TYPE_DIR, +}; + +/* The members of the kernel's struct aa_sfs_entry that the tables set */ +struct aa_sfs_entry { + const char *name; + enum aa_sfs_type v_type; + union { + bool boolean; + const char *string; + unsigned long u64; + struct aa_sfs_entry *files; + } v; +}; + +#define AA_SFS_FILE_BOOLEAN(_name, _value) \ + { .name = (_name), .v_type = AA_SFS_TYPE_BOOLEAN, .v.boolean = (_value) } +#define AA_SFS_FILE_STRING(_name, _value) \ + { .name = (_name), .v_type = AA_SFS_TYPE_STRING, .v.string = (_value) } +#define AA_SFS_FILE_U64(_name, _value) \ + { .name = (_name), .v_type = AA_SFS_TYPE_U64, .v.u64 = (_value) } +#define AA_SFS_DIR(_name, _value) \ + { .name = (_name), .v_type = AA_SFS_TYPE_DIR, .v.files = (_value) } + +#include "feature_masks.h" +#include "include/features.h" + +static int cmp_entries(const void *a, const void *b) +{ + const struct aa_sfs_entry *x = a, *y = b; + + return strcmp(x->name, y->name); +} + +static void print_dir(struct aa_sfs_entry *dir) +{ + struct aa_sfs_entry *entry; + size_t count = 0; + + while (dir[count].name) + count++; + + qsort(dir, count, sizeof(*dir), cmp_entries); + + for (entry = dir; entry->name; entry++) { + /* libapparmor skips these */ + if (entry->name[0] == '.') + continue; + + printf("%s {", entry->name); + switch (entry->v_type) { + case AA_SFS_TYPE_BOOLEAN: + printf("%s\n", entry->v.boolean ? "yes" : "no"); + break; + case AA_SFS_TYPE_STRING: + printf("%s\n", entry->v.string); + break; + case AA_SFS_TYPE_U64: + /* "%#08lx" in the kernel, which prints 0x for 0 too */ + printf("0x%06lx\n", entry->v.u64); + break; + case AA_SFS_TYPE_DIR: + print_dir(entry->v.files); + break; + } + printf("}\n"); + } +} + +int main(void) +{ + print_dir(aa_sfs_entry_features); + + return fflush(stdout) || ferror(stdout); +} diff --git a/security/apparmor/include/features.h b/security/apparmor/include/features.h index dc38f54abec6..aadd8391ae9a 100644 --- a/security/apparmor/include/features.h +++ b/security/apparmor/include/features.h @@ -3,8 +3,9 @@ * AppArmor security module * * This file contains the tables behind the securityfs features directory, - * /sys/kernel/security/apparmor/features. It defines them, so it is for - * apparmorfs.c alone. + * /sys/kernel/security/apparmor/features. It defines them, for apparmorfs.c + * and for the host program gen_features.c, so it cannot depend on kernel + * headers. * * Copyright (C) 1998-2008 Novell/SUSE * Copyright 2009-2026 Canonical Ltd. -- 2.51.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] apparmor: write the feature set to a file at build time 2026-11-17 13:50 ` [PATCH 3/4] apparmor: write the feature set to a file at build time Maxime Bélair @ 2026-11-17 14:00 ` sashiko-bot 0 siblings, 0 replies; 9+ messages in thread From: sashiko-bot @ 2026-11-17 14:00 UTC (permalink / raw) Cc: linux-security-module > apparmor_parser compiles policy for the feature set of the kernel, > which libapparmor reads from /sys/kernel/security/apparmor/features, > and the policy cache is keyed on that set. The cache for a kernel can > therefore only be filled once that kernel runs, and the first boot > into a kernel with a new feature set compiles all of the policy. > > Every entry of the features directory comes from a static table of > constants. So write the set to security/apparmor/features when the > kernel is built, in the format that libapparmor flattens the directory > to. Policy can then be compiled when a kernel is installed: > > apparmor_parser --kernel-features=<file> ... > > Signed-off-by: Maxime Bélair <maxime.belair@canonical.com> Sashiko has reviewed this patch and found no issues. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261117135042.78238-1-maxime.belair@canonical.com?part=3 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 4/4] kbuild: install the AppArmor feature set with the modules 2026-11-17 13:50 [PATCH 0/4] apparmor: provide the kernel feature set at build time Maxime Bélair ` (2 preceding siblings ...) 2026-11-17 13:50 ` [PATCH 3/4] apparmor: write the feature set to a file at build time Maxime Bélair @ 2026-11-17 13:50 ` Maxime Bélair 2026-11-17 13:58 ` sashiko-bot 3 siblings, 1 reply; 9+ messages in thread From: Maxime Bélair @ 2026-11-17 13:50 UTC (permalink / raw) To: John Johansen, Georgia Garcia Cc: apparmor, linux-security-module, Maxime Bélair A package hook that compiles the policy for a kernel when it is installed only knows the release of that kernel, so the feature set has to be in a place that is derived from the release. Install it as $(MODLIB)/apparmor/features with modules_install aa-precompile, which is proposed for the apparmor user space tools, reads the file from /lib/modules/<release>/apparmor/features if it exists. Signed-off-by: Maxime Bélair <maxime.belair@canonical.com> --- Documentation/admin-guide/LSM/apparmor.rst | 15 +++++++++++++++ scripts/Makefile.modinst | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/Documentation/admin-guide/LSM/apparmor.rst b/Documentation/admin-guide/LSM/apparmor.rst index 47939ee89d74..90e216556198 100644 --- a/Documentation/admin-guide/LSM/apparmor.rst +++ b/Documentation/admin-guide/LSM/apparmor.rst @@ -37,6 +37,21 @@ For AppArmor to enforce any restrictions beyond standard Linux DAC permissions policy must be loaded into the kernel from user space (see the Documentation and tools links). +Feature set +=========== + +The kernel lists what it supports in the securityfs directory +``/sys/kernel/security/apparmor/features``. The user space tools read it when +they compile policy, and keep the compiled policy of each feature set apart. + +The same feature set is written to ``security/apparmor/features`` when the +kernel is built, in the form that the user space tools flatten the directory +to, and ``make modules_install`` installs it as +``/lib/modules/$(KERNELRELEASE)/apparmor/features``. With that file the policy +can be compiled for a kernel that is not running, e.g. when it is installed:: + + apparmor_parser --kernel-features=<file> ... + Documentation ============= diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 9ba45e5b32b1..9df8e5ae014c 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -38,6 +38,12 @@ install-$(CONFIG_BUILTIN_MODULE_RANGES) += $(MODLIB)/modules.builtin.ranges $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo modules.builtin.ranges): $(MODLIB)/%: % FORCE $(call cmd,install) +# AppArmor feature set, to compile the policy for this kernel before it boots +install-$(CONFIG_SECURITY_APPARMOR) += $(MODLIB)/apparmor/features + +$(MODLIB)/apparmor/features: security/apparmor/features FORCE + $(call cmd,install) + endif modules := $(call read-file, modules.order) -- 2.51.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 4/4] kbuild: install the AppArmor feature set with the modules 2026-11-17 13:50 ` [PATCH 4/4] kbuild: install the AppArmor feature set with the modules Maxime Bélair @ 2026-11-17 13:58 ` sashiko-bot 0 siblings, 0 replies; 9+ messages in thread From: sashiko-bot @ 2026-11-17 13:58 UTC (permalink / raw) Cc: linux-security-module > A package hook that compiles the policy for a kernel when it is > installed only knows the release of that kernel, so the feature set > has to be in a place that is derived from the release. > > Install it as $(MODLIB)/apparmor/features with modules_install > > aa-precompile, which is proposed for the apparmor user space tools, > reads the file from /lib/modules/<release>/apparmor/features if it > exists. > > Signed-off-by: Maxime Bélair <maxime.belair@canonical.com> Sashiko has reviewed this patch and found no issues. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261117135042.78238-1-maxime.belair@canonical.com?part=4 ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-17 14:00 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-17 13:50 [PATCH 0/4] apparmor: provide the kernel feature set at build time Maxime Bélair 2026-11-17 13:50 ` [PATCH 1/4] apparmor: move the feature tables to a header Maxime Bélair 2026-11-17 13:55 ` sashiko-bot 2026-11-17 13:50 ` [PATCH 2/4] apparmor: make the feature tables build without kernel headers Maxime Bélair 2026-11-17 13:55 ` sashiko-bot 2026-11-17 13:50 ` [PATCH 3/4] apparmor: write the feature set to a file at build time Maxime Bélair 2026-11-17 14:00 ` sashiko-bot 2026-11-17 13:50 ` [PATCH 4/4] kbuild: install the AppArmor feature set with the modules Maxime Bélair 2026-11-17 13:58 ` sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox