1 # SPDX-License-Identifier: GPL-2.0
2 # Makefile for AppArmor Linux Security Module
4 obj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o
6 apparmor-y := apparmorfs.o audit.o capability.o task.o ipc.o lib.o match.o \
7 path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \
8 resource.o secid.o file.o policy_ns.o label.o mount.o net.o
9 apparmor-$(CONFIG_SECURITY_APPARMOR_HASH) += crypto.o
11 obj-$(CONFIG_SECURITY_APPARMOR_KUNIT_TEST) += apparmor_policy_unpack_test.o
12 apparmor_policy_unpack_test-objs += policy_unpack_test.o
14 clean-files := capability_names.h rlim_names.h net_names.h
16 # Build a lower case string table of address family names
17 # Transform lines from
18 # #define AF_LOCAL 1 /* POSIX name for AF_UNIX */
19 # #define AF_INET 2 /* Internet IP Protocol */
24 # and build the securityfs entries for the mapping.
25 # Transforms lines from
26 # #define AF_INET 2 /* Internet IP Protocol */
28 # #define AA_SFS_AF_MASK "local inet"
29 quiet_cmd_make-af = GEN $@
30 cmd_make-af = echo "static const char *address_family_names[] = {" > $@ ;\
31 sed $< >>$@ -r -n -e "/AF_MAX/d" -e "/AF_LOCAL/d" -e "/AF_ROUTE/d" -e \
32 's/^\#define[ \t]+AF_([A-Z0-9_]+)[ \t]+([0-9]+)(.*)/[\2] = "\L\1",/p';\
34 printf '%s' '\#define AA_SFS_AF_MASK "' >> $@ ;\
35 sed -r -n -e "/AF_MAX/d" -e "/AF_LOCAL/d" -e "/AF_ROUTE/d" -e \
36 's/^\#define[ \t]+AF_([A-Z0-9_]+)[ \t]+([0-9]+)(.*)/\L\1/p'\
37 $< | tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
39 # Build a lower case string table of sock type names
40 # Transform lines from
44 quiet_cmd_make-sock = GEN $@
45 cmd_make-sock = echo "static const char *sock_type_names[] = {" >> $@ ;\
47 -e 's/^\tSOCK_([A-Z0-9_]+)[\t]+=[ \t]+([0-9]+)(.*)/[\2] = "\L\1",/p';\
50 # Build a lower case string table of capability names
51 # Transforms lines from
52 # #define CAP_DAC_OVERRIDE 1
54 # [1] = "dac_override",
55 quiet_cmd_make-caps = GEN $@
56 cmd_make-caps = echo "static const char *const capability_names[] = {" > $@ ;\
57 sed $< >>$@ -r -n -e '/CAP_FS_MASK/d' \
58 -e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/[\2] = "\L\1",/p';\
60 printf '%s' '\#define AA_SFS_CAPS_MASK "' >> $@ ;\
61 sed $< -r -n -e '/CAP_FS_MASK/d' \
62 -e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/\L\1/p' | \
63 tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
66 # Build a lower case string table of rlimit names.
67 # Transforms lines from
68 # #define RLIMIT_STACK 3 /* max stack size */
70 # [RLIMIT_STACK] = "stack",
72 # and build a second integer table (with the second sed cmd), that maps
73 # RLIMIT defines to the order defined in asm-generic/resource.h This is
74 # required by policy load to map policy ordering of RLIMITs to internal
75 # ordering for architectures that redefine an RLIMIT.
76 # Transforms lines from
77 # #define RLIMIT_STACK 3 /* max stack size */
81 # and build the securityfs entries for the mapping.
82 # Transforms lines from
83 # #define RLIMIT_FSIZE 1 /* Maximum filesize */
84 # #define RLIMIT_STACK 3 /* max stack size */
86 # #define AA_SFS_RLIMIT_MASK "fsize stack"
87 quiet_cmd_make-rlim = GEN $@
88 cmd_make-rlim = echo "static const char *const rlim_names[RLIM_NLIMITS] = {" \
91 -e 's/^\# ?define[ \t]+(RLIMIT_([A-Z0-9_]+)).*/[\1] = "\L\2",/p';\
93 echo "static const int rlim_map[RLIM_NLIMITS] = {" >> $@ ;\
94 sed -r -n "s/^\# ?define[ \t]+(RLIMIT_[A-Z0-9_]+).*/\1,/p" $< >> $@ ;\
96 printf '%s' '\#define AA_SFS_RLIMIT_MASK "' >> $@ ;\
97 sed -r -n 's/^\# ?define[ \t]+RLIMIT_([A-Z0-9_]+).*/\L\1/p' $< | \
98 tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
100 $(obj)/capability.o : $(obj)/capability_names.h
101 $(obj)/net.o : $(obj)/net_names.h
102 $(obj)/resource.o : $(obj)/rlim_names.h
103 $(obj)/capability_names.h : $(srctree)/include/uapi/linux/capability.h \
105 $(call cmd,make-caps)
106 $(obj)/rlim_names.h : $(srctree)/include/uapi/asm-generic/resource.h \
108 $(call cmd,make-rlim)
109 $(obj)/net_names.h : $(srctree)/include/linux/socket.h \
110 $(srctree)/include/linux/net.h \
113 $(call cmd,make-sock)