xref: /linux/security/apparmor/Makefile (revision 121d4a91e3c12ddfb167edafb9aa64cc5cc3a406)
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*121d4a91SJohn Johansen              resource.o secid.o file.o policy_ns.o
8f8eb8a13SJohn Johansenapparmor-$(CONFIG_SECURITY_APPARMOR_HASH) += crypto.o
9016d825fSJohn Johansen
100f825026SMichal Hockoclean-files := capability_names.h rlim_names.h
11016d825fSJohn Johansen
124fdef218SJohn Johansen
134fdef218SJohn Johansen# Build a lower case string table of capability names
144fdef218SJohn Johansen# Transforms lines from
154fdef218SJohn Johansen#    #define CAP_DAC_OVERRIDE     1
164fdef218SJohn Johansen# to
174fdef218SJohn Johansen#    [1] = "dac_override",
18016d825fSJohn Johansenquiet_cmd_make-caps = GEN     $@
197e570145STetsuo Handacmd_make-caps = echo "static const char *const capability_names[] = {" > $@ ;\
204fdef218SJohn Johansen	sed $< >>$@ -r -n -e '/CAP_FS_MASK/d' \
214fdef218SJohn Johansen	-e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/[\2] = "\L\1",/p';\
2284f1f787SJohn Johansen	echo "};" >> $@ ;\
2384f1f787SJohn Johansen	echo -n '\#define AA_FS_CAPS_MASK "' >> $@ ;\
2484f1f787SJohn Johansen	sed $< -r -n -e '/CAP_FS_MASK/d' \
2584f1f787SJohn Johansen	    -e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/\L\1/p' | \
2684f1f787SJohn Johansen	     tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
27016d825fSJohn Johansen
284fdef218SJohn Johansen
294fdef218SJohn Johansen# Build a lower case string table of rlimit names.
304fdef218SJohn Johansen# Transforms lines from
314fdef218SJohn Johansen#    #define RLIMIT_STACK		3	/* max stack size */
324fdef218SJohn Johansen# to
334fdef218SJohn Johansen#    [RLIMIT_STACK] = "stack",
344fdef218SJohn Johansen#
354fdef218SJohn Johansen# and build a second integer table (with the second sed cmd), that maps
36d384b0a1SKees Cook# RLIMIT defines to the order defined in asm-generic/resource.h  This is
374fdef218SJohn Johansen# required by policy load to map policy ordering of RLIMITs to internal
384fdef218SJohn Johansen# ordering for architectures that redefine an RLIMIT.
394fdef218SJohn Johansen# Transforms lines from
404fdef218SJohn Johansen#    #define RLIMIT_STACK		3	/* max stack size */
414fdef218SJohn Johansen# to
424fdef218SJohn Johansen# RLIMIT_STACK,
43d384b0a1SKees Cook#
44d384b0a1SKees Cook# and build the securityfs entries for the mapping.
45d384b0a1SKees Cook# Transforms lines from
46d384b0a1SKees Cook#    #define RLIMIT_FSIZE        1   /* Maximum filesize */
47d384b0a1SKees Cook#    #define RLIMIT_STACK		3	/* max stack size */
48d384b0a1SKees Cook# to
49d384b0a1SKees Cook# #define AA_FS_RLIMIT_MASK "fsize stack"
50016d825fSJohn Johansenquiet_cmd_make-rlim = GEN     $@
517e570145STetsuo Handacmd_make-rlim = echo "static const char *const rlim_names[RLIM_NLIMITS] = {" \
5233e521acSJohn Johansen	> $@ ;\
534fdef218SJohn Johansen	sed $< >> $@ -r -n \
544fdef218SJohn Johansen	    -e 's/^\# ?define[ \t]+(RLIMIT_([A-Z0-9_]+)).*/[\1] = "\L\2",/p';\
554fdef218SJohn Johansen	echo "};" >> $@ ;\
56d384b0a1SKees Cook	echo "static const int rlim_map[RLIM_NLIMITS] = {" >> $@ ;\
574fdef218SJohn Johansen	sed -r -n "s/^\# ?define[ \t]+(RLIMIT_[A-Z0-9_]+).*/\1,/p" $< >> $@ ;\
58d384b0a1SKees Cook	echo "};" >> $@ ; \
59d384b0a1SKees Cook	echo -n '\#define AA_FS_RLIMIT_MASK "' >> $@ ;\
60d384b0a1SKees Cook	sed -r -n 's/^\# ?define[ \t]+RLIMIT_([A-Z0-9_]+).*/\L\1/p' $< | \
61d384b0a1SKees Cook	    tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
62016d825fSJohn Johansen
63016d825fSJohn Johansen$(obj)/capability.o : $(obj)/capability_names.h
64016d825fSJohn Johansen$(obj)/resource.o : $(obj)/rlim_names.h
6543c422edSJohn Johansen$(obj)/capability_names.h : $(srctree)/include/uapi/linux/capability.h \
66d384b0a1SKees Cook			    $(src)/Makefile
67016d825fSJohn Johansen	$(call cmd,make-caps)
688a1ab315SDavid Howells$(obj)/rlim_names.h : $(srctree)/include/uapi/asm-generic/resource.h \
69d384b0a1SKees Cook		      $(src)/Makefile
70016d825fSJohn Johansen	$(call cmd,make-rlim)
71