xref: /openbmc/linux/security/apparmor/Makefile (revision b11e51dd)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2016d825fSJohn Johansen# Makefile for AppArmor Linux Security Module
3016d825fSJohn Johansen#
4016d825fSJohn Johansenobj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o
5016d825fSJohn Johansen
6de62de59SJohn Johansenapparmor-y := apparmorfs.o audit.o capability.o task.o ipc.o lib.o match.o \
7016d825fSJohn Johansen              path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \
856974a6fSJohn Johansen              resource.o secid.o file.o policy_ns.o label.o mount.o net.o \
9f8eb8a13SJohn Johansen              policy_compat.o
10016d825fSJohn Johansenapparmor-$(CONFIG_SECURITY_APPARMOR_HASH) += crypto.o
11*b11e51ddSRae Moar
12*b11e51ddSRae Moarobj-$(CONFIG_SECURITY_APPARMOR_KUNIT_TEST) += apparmor_policy_unpack_test.o
13*b11e51ddSRae Moarapparmor_policy_unpack_test-objs += policy_unpack_test.o
1456974a6fSJohn Johansen
15016d825fSJohn Johansenclean-files := capability_names.h rlim_names.h net_names.h
1656974a6fSJohn Johansen
1756974a6fSJohn Johansen# Build a lower case string table of address family names
1856974a6fSJohn Johansen# Transform lines from
1956974a6fSJohn Johansen#    #define AF_LOCAL		1	/* POSIX name for AF_UNIX	*/
2056974a6fSJohn Johansen#    #define AF_INET		2	/* Internet IP Protocol 	*/
2156974a6fSJohn Johansen# to
2256974a6fSJohn Johansen#    [1] = "local",
2356974a6fSJohn Johansen#    [2] = "inet",
2456974a6fSJohn Johansen#
2556974a6fSJohn Johansen# and build the securityfs entries for the mapping.
2656974a6fSJohn Johansen# Transforms lines from
2756974a6fSJohn Johansen#    #define AF_INET		2	/* Internet IP Protocol 	*/
2856974a6fSJohn Johansen# to
2956974a6fSJohn Johansen#    #define AA_SFS_AF_MASK "local inet"
3056974a6fSJohn Johansenquiet_cmd_make-af = GEN     $@
3156974a6fSJohn Johansencmd_make-af = echo "static const char *address_family_names[] = {" > $@ ;\
3256974a6fSJohn Johansen	sed $< >>$@ -r -n -e "/AF_MAX/d" -e "/AF_LOCAL/d" -e "/AF_ROUTE/d" -e \
3356974a6fSJohn Johansen	 's/^\#define[ \t]+AF_([A-Z0-9_]+)[ \t]+([0-9]+)(.*)/[\2] = "\L\1",/p';\
3456974a6fSJohn Johansen	echo "};" >> $@ ;\
3556974a6fSJohn Johansen	printf '%s' '\#define AA_SFS_AF_MASK "' >> $@ ;\
3656974a6fSJohn Johansen	sed -r -n -e "/AF_MAX/d" -e "/AF_LOCAL/d" -e "/AF_ROUTE/d" -e \
3756974a6fSJohn Johansen	 's/^\#define[ \t]+AF_([A-Z0-9_]+)[ \t]+([0-9]+)(.*)/\L\1/p'\
3856974a6fSJohn Johansen	 $< | tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
3956974a6fSJohn Johansen
4056974a6fSJohn Johansen# Build a lower case string table of sock type names
4156974a6fSJohn Johansen# Transform lines from
4256974a6fSJohn Johansen#    SOCK_STREAM	= 1,
4356974a6fSJohn Johansen# to
4456974a6fSJohn Johansen#    [1] = "stream",
4556974a6fSJohn Johansenquiet_cmd_make-sock = GEN     $@
4656974a6fSJohn Johansencmd_make-sock = echo "static const char *sock_type_names[] = {" >> $@ ;\
4756974a6fSJohn Johansen	sed $^ >>$@ -r -n \
4856974a6fSJohn Johansen	-e 's/^\tSOCK_([A-Z0-9_]+)[\t]+=[ \t]+([0-9]+)(.*)/[\2] = "\L\1",/p';\
494fdef218SJohn Johansen	echo "};" >> $@
504fdef218SJohn Johansen
514fdef218SJohn Johansen# Build a lower case string table of capability names
524fdef218SJohn Johansen# Transforms lines from
534fdef218SJohn Johansen#    #define CAP_DAC_OVERRIDE     1
544fdef218SJohn Johansen# to
55016d825fSJohn Johansen#    [1] = "dac_override",
567e570145STetsuo Handaquiet_cmd_make-caps = GEN     $@
574fdef218SJohn Johansencmd_make-caps = echo "static const char *const capability_names[] = {" > $@ ;\
584fdef218SJohn Johansen	sed $< >>$@ -r -n -e '/CAP_FS_MASK/d' \
5984f1f787SJohn Johansen	-e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/[\2] = "\L\1",/p';\
60c97204baSJohn Johansen	echo "};" >> $@ ;\
6184f1f787SJohn Johansen	printf '%s' '\#define AA_SFS_CAPS_MASK "' >> $@ ;\
6284f1f787SJohn Johansen	sed $< -r -n -e '/CAP_FS_MASK/d' \
6384f1f787SJohn Johansen	    -e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/\L\1/p' | \
64016d825fSJohn Johansen	     tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
654fdef218SJohn Johansen
664fdef218SJohn Johansen
674fdef218SJohn Johansen# Build a lower case string table of rlimit names.
684fdef218SJohn Johansen# Transforms lines from
694fdef218SJohn Johansen#    #define RLIMIT_STACK		3	/* max stack size */
704fdef218SJohn Johansen# to
714fdef218SJohn Johansen#    [RLIMIT_STACK] = "stack",
724fdef218SJohn Johansen#
73d384b0a1SKees Cook# and build a second integer table (with the second sed cmd), that maps
744fdef218SJohn Johansen# RLIMIT defines to the order defined in asm-generic/resource.h  This is
754fdef218SJohn Johansen# required by policy load to map policy ordering of RLIMITs to internal
764fdef218SJohn Johansen# ordering for architectures that redefine an RLIMIT.
774fdef218SJohn Johansen# Transforms lines from
784fdef218SJohn Johansen#    #define RLIMIT_STACK		3	/* max stack size */
794fdef218SJohn Johansen# to
80d384b0a1SKees Cook# RLIMIT_STACK,
81d384b0a1SKees Cook#
82d384b0a1SKees Cook# and build the securityfs entries for the mapping.
83d384b0a1SKees Cook# Transforms lines from
84d384b0a1SKees Cook#    #define RLIMIT_FSIZE        1   /* Maximum filesize */
85d384b0a1SKees Cook#    #define RLIMIT_STACK		3	/* max stack size */
86c97204baSJohn Johansen# to
87016d825fSJohn Johansen# #define AA_SFS_RLIMIT_MASK "fsize stack"
887e570145STetsuo Handaquiet_cmd_make-rlim = GEN     $@
8933e521acSJohn Johansencmd_make-rlim = echo "static const char *const rlim_names[RLIM_NLIMITS] = {" \
904fdef218SJohn Johansen	> $@ ;\
914fdef218SJohn Johansen	sed $< >> $@ -r -n \
924fdef218SJohn Johansen	    -e 's/^\# ?define[ \t]+(RLIMIT_([A-Z0-9_]+)).*/[\1] = "\L\2",/p';\
93d384b0a1SKees Cook	echo "};" >> $@ ;\
944fdef218SJohn Johansen	echo "static const int rlim_map[RLIM_NLIMITS] = {" >> $@ ;\
95d384b0a1SKees Cook	sed -r -n "s/^\# ?define[ \t]+(RLIMIT_[A-Z0-9_]+).*/\1,/p" $< >> $@ ;\
96c97204baSJohn Johansen	echo "};" >> $@ ; \
97d384b0a1SKees Cook	printf '%s' '\#define AA_SFS_RLIMIT_MASK "' >> $@ ;\
98d384b0a1SKees Cook	sed -r -n 's/^\# ?define[ \t]+RLIMIT_([A-Z0-9_]+).*/\L\1/p' $< | \
99016d825fSJohn Johansen	    tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
100016d825fSJohn Johansen
10156974a6fSJohn Johansen$(obj)/capability.o : $(obj)/capability_names.h
102016d825fSJohn Johansen$(obj)/net.o : $(obj)/net_names.h
10343c422edSJohn Johansen$(obj)/resource.o : $(obj)/rlim_names.h
104d384b0a1SKees Cook$(obj)/capability_names.h : $(srctree)/include/uapi/linux/capability.h \
105016d825fSJohn Johansen			    $(src)/Makefile
1068a1ab315SDavid Howells	$(call cmd,make-caps)
107d384b0a1SKees Cook$(obj)/rlim_names.h : $(srctree)/include/uapi/asm-generic/resource.h \
108016d825fSJohn Johansen		      $(src)/Makefile
10956974a6fSJohn Johansen	$(call cmd,make-rlim)
11056974a6fSJohn Johansen$(obj)/net_names.h : $(srctree)/include/linux/socket.h \
11156974a6fSJohn Johansen		     $(srctree)/include/linux/net.h \
11256974a6fSJohn Johansen		     $(src)/Makefile
11356974a6fSJohn Johansen	$(call cmd,make-af)
114	$(call cmd,make-sock)
115