xref: /linux/security/apparmor/Makefile (revision 651e28c5537abb39076d3949fb7618536f1d242e)
1016d825fSJohn Johansen# Makefile for AppArmor Linux Security Module
2016d825fSJohn Johansen#
3016d825fSJohn Johansenobj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o
4016d825fSJohn Johansen
5016d825fSJohn Johansenapparmor-y := apparmorfs.o audit.o capability.o context.o ipc.o lib.o match.o \
6016d825fSJohn Johansen              path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \
7*651e28c5SJohn Johansen              resource.o secid.o file.o policy_ns.o label.o mount.o net.o
8f8eb8a13SJohn Johansenapparmor-$(CONFIG_SECURITY_APPARMOR_HASH) += crypto.o
9016d825fSJohn Johansen
10*651e28c5SJohn Johansenclean-files := capability_names.h rlim_names.h net_names.h
11016d825fSJohn Johansen
12*651e28c5SJohn Johansen# Build a lower case string table of address family names
13*651e28c5SJohn Johansen# Transform lines from
14*651e28c5SJohn Johansen#    #define AF_LOCAL		1	/* POSIX name for AF_UNIX	*/
15*651e28c5SJohn Johansen#    #define AF_INET		2	/* Internet IP Protocol 	*/
16*651e28c5SJohn Johansen# to
17*651e28c5SJohn Johansen#    [1] = "local",
18*651e28c5SJohn Johansen#    [2] = "inet",
19*651e28c5SJohn Johansen#
20*651e28c5SJohn Johansen# and build the securityfs entries for the mapping.
21*651e28c5SJohn Johansen# Transforms lines from
22*651e28c5SJohn Johansen#    #define AF_INET		2	/* Internet IP Protocol 	*/
23*651e28c5SJohn Johansen# to
24*651e28c5SJohn Johansen#    #define AA_SFS_AF_MASK "local inet"
25*651e28c5SJohn Johansenquiet_cmd_make-af = GEN     $@
26*651e28c5SJohn Johansencmd_make-af = echo "static const char *address_family_names[] = {" > $@ ;\
27*651e28c5SJohn Johansen	sed $< >>$@ -r -n -e "/AF_MAX/d" -e "/AF_LOCAL/d" -e "/AF_ROUTE/d" -e \
28*651e28c5SJohn Johansen	 's/^\#define[ \t]+AF_([A-Z0-9_]+)[ \t]+([0-9]+)(.*)/[\2] = "\L\1",/p';\
29*651e28c5SJohn Johansen	echo "};" >> $@ ;\
30*651e28c5SJohn Johansen	printf '%s' '\#define AA_SFS_AF_MASK "' >> $@ ;\
31*651e28c5SJohn Johansen	sed -r -n -e "/AF_MAX/d" -e "/AF_LOCAL/d" -e "/AF_ROUTE/d" -e \
32*651e28c5SJohn Johansen	 's/^\#define[ \t]+AF_([A-Z0-9_]+)[ \t]+([0-9]+)(.*)/\L\1/p'\
33*651e28c5SJohn Johansen	 $< | tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
34*651e28c5SJohn Johansen
35*651e28c5SJohn Johansen# Build a lower case string table of sock type names
36*651e28c5SJohn Johansen# Transform lines from
37*651e28c5SJohn Johansen#    SOCK_STREAM	= 1,
38*651e28c5SJohn Johansen# to
39*651e28c5SJohn Johansen#    [1] = "stream",
40*651e28c5SJohn Johansenquiet_cmd_make-sock = GEN     $@
41*651e28c5SJohn Johansencmd_make-sock = echo "static const char *sock_type_names[] = {" >> $@ ;\
42*651e28c5SJohn Johansen	sed $^ >>$@ -r -n \
43*651e28c5SJohn Johansen	-e 's/^\tSOCK_([A-Z0-9_]+)[\t]+=[ \t]+([0-9]+)(.*)/[\2] = "\L\1",/p';\
44*651e28c5SJohn Johansen	echo "};" >> $@
454fdef218SJohn Johansen
464fdef218SJohn Johansen# Build a lower case string table of capability names
474fdef218SJohn Johansen# Transforms lines from
484fdef218SJohn Johansen#    #define CAP_DAC_OVERRIDE     1
494fdef218SJohn Johansen# to
504fdef218SJohn Johansen#    [1] = "dac_override",
51016d825fSJohn Johansenquiet_cmd_make-caps = GEN     $@
527e570145STetsuo Handacmd_make-caps = echo "static const char *const capability_names[] = {" > $@ ;\
534fdef218SJohn Johansen	sed $< >>$@ -r -n -e '/CAP_FS_MASK/d' \
544fdef218SJohn Johansen	-e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/[\2] = "\L\1",/p';\
5584f1f787SJohn Johansen	echo "};" >> $@ ;\
56c97204baSJohn Johansen	printf '%s' '\#define AA_SFS_CAPS_MASK "' >> $@ ;\
5784f1f787SJohn Johansen	sed $< -r -n -e '/CAP_FS_MASK/d' \
5884f1f787SJohn Johansen	    -e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/\L\1/p' | \
5984f1f787SJohn Johansen	     tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
60016d825fSJohn Johansen
614fdef218SJohn Johansen
624fdef218SJohn Johansen# Build a lower case string table of rlimit names.
634fdef218SJohn Johansen# Transforms lines from
644fdef218SJohn Johansen#    #define RLIMIT_STACK		3	/* max stack size */
654fdef218SJohn Johansen# to
664fdef218SJohn Johansen#    [RLIMIT_STACK] = "stack",
674fdef218SJohn Johansen#
684fdef218SJohn Johansen# and build a second integer table (with the second sed cmd), that maps
69d384b0a1SKees Cook# RLIMIT defines to the order defined in asm-generic/resource.h  This is
704fdef218SJohn Johansen# required by policy load to map policy ordering of RLIMITs to internal
714fdef218SJohn Johansen# ordering for architectures that redefine an RLIMIT.
724fdef218SJohn Johansen# Transforms lines from
734fdef218SJohn Johansen#    #define RLIMIT_STACK		3	/* max stack size */
744fdef218SJohn Johansen# to
754fdef218SJohn Johansen# RLIMIT_STACK,
76d384b0a1SKees Cook#
77d384b0a1SKees Cook# and build the securityfs entries for the mapping.
78d384b0a1SKees Cook# Transforms lines from
79d384b0a1SKees Cook#    #define RLIMIT_FSIZE        1   /* Maximum filesize */
80d384b0a1SKees Cook#    #define RLIMIT_STACK		3	/* max stack size */
81d384b0a1SKees Cook# to
82c97204baSJohn Johansen# #define AA_SFS_RLIMIT_MASK "fsize stack"
83016d825fSJohn Johansenquiet_cmd_make-rlim = GEN     $@
847e570145STetsuo Handacmd_make-rlim = echo "static const char *const rlim_names[RLIM_NLIMITS] = {" \
8533e521acSJohn Johansen	> $@ ;\
864fdef218SJohn Johansen	sed $< >> $@ -r -n \
874fdef218SJohn Johansen	    -e 's/^\# ?define[ \t]+(RLIMIT_([A-Z0-9_]+)).*/[\1] = "\L\2",/p';\
884fdef218SJohn Johansen	echo "};" >> $@ ;\
89d384b0a1SKees Cook	echo "static const int rlim_map[RLIM_NLIMITS] = {" >> $@ ;\
904fdef218SJohn Johansen	sed -r -n "s/^\# ?define[ \t]+(RLIMIT_[A-Z0-9_]+).*/\1,/p" $< >> $@ ;\
91d384b0a1SKees Cook	echo "};" >> $@ ; \
92c97204baSJohn Johansen	printf '%s' '\#define AA_SFS_RLIMIT_MASK "' >> $@ ;\
93d384b0a1SKees Cook	sed -r -n 's/^\# ?define[ \t]+RLIMIT_([A-Z0-9_]+).*/\L\1/p' $< | \
94d384b0a1SKees Cook	    tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
95016d825fSJohn Johansen
96016d825fSJohn Johansen$(obj)/capability.o : $(obj)/capability_names.h
97*651e28c5SJohn Johansen$(obj)/net.o : $(obj)/net_names.h
98016d825fSJohn Johansen$(obj)/resource.o : $(obj)/rlim_names.h
9943c422edSJohn Johansen$(obj)/capability_names.h : $(srctree)/include/uapi/linux/capability.h \
100d384b0a1SKees Cook			    $(src)/Makefile
101016d825fSJohn Johansen	$(call cmd,make-caps)
1028a1ab315SDavid Howells$(obj)/rlim_names.h : $(srctree)/include/uapi/asm-generic/resource.h \
103d384b0a1SKees Cook		      $(src)/Makefile
104016d825fSJohn Johansen	$(call cmd,make-rlim)
105*651e28c5SJohn Johansen$(obj)/net_names.h : $(srctree)/include/linux/socket.h \
106*651e28c5SJohn Johansen		     $(srctree)/include/linux/net.h \
107*651e28c5SJohn Johansen		     $(src)/Makefile
108*651e28c5SJohn Johansen	$(call cmd,make-af)
109*651e28c5SJohn Johansen	$(call cmd,make-sock)
110