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 <[email protected]>
---
 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


Reply via email to