[PATCH 4/4] kbuild: install the AppArmor feature set with the modules

Maxime Bélair maxime.belair at canonical.com
Tue Nov 17 13:50:10 UTC 2026


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 at 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




More information about the Linux-security-module-archive mailing list