18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci# Makefile for AppArmor Linux Security Module
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ciobj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciapparmor-y := apparmorfs.o audit.o capability.o task.o ipc.o lib.o match.o \
78c2ecf20Sopenharmony_ci              path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \
88c2ecf20Sopenharmony_ci              resource.o secid.o file.o policy_ns.o label.o mount.o net.o
98c2ecf20Sopenharmony_ciapparmor-$(CONFIG_SECURITY_APPARMOR_HASH) += crypto.o
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ciclean-files := capability_names.h rlim_names.h net_names.h
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci# Build a lower case string table of address family names
148c2ecf20Sopenharmony_ci# Transform lines from
158c2ecf20Sopenharmony_ci#    #define AF_LOCAL		1	/* POSIX name for AF_UNIX	*/
168c2ecf20Sopenharmony_ci#    #define AF_INET		2	/* Internet IP Protocol 	*/
178c2ecf20Sopenharmony_ci# to
188c2ecf20Sopenharmony_ci#    [1] = "local",
198c2ecf20Sopenharmony_ci#    [2] = "inet",
208c2ecf20Sopenharmony_ci#
218c2ecf20Sopenharmony_ci# and build the securityfs entries for the mapping.
228c2ecf20Sopenharmony_ci# Transforms lines from
238c2ecf20Sopenharmony_ci#    #define AF_INET		2	/* Internet IP Protocol 	*/
248c2ecf20Sopenharmony_ci# to
258c2ecf20Sopenharmony_ci#    #define AA_SFS_AF_MASK "local inet"
268c2ecf20Sopenharmony_ciquiet_cmd_make-af = GEN     $@
278c2ecf20Sopenharmony_cicmd_make-af = echo "static const char *address_family_names[] = {" > $@ ;\
288c2ecf20Sopenharmony_ci	sed $< >>$@ -r -n -e "/AF_MAX/d" -e "/AF_LOCAL/d" -e "/AF_ROUTE/d" -e \
298c2ecf20Sopenharmony_ci	 's/^\#define[ \t]+AF_([A-Z0-9_]+)[ \t]+([0-9]+)(.*)/[\2] = "\L\1",/p';\
308c2ecf20Sopenharmony_ci	echo "};" >> $@ ;\
318c2ecf20Sopenharmony_ci	printf '%s' '\#define AA_SFS_AF_MASK "' >> $@ ;\
328c2ecf20Sopenharmony_ci	sed -r -n -e "/AF_MAX/d" -e "/AF_LOCAL/d" -e "/AF_ROUTE/d" -e \
338c2ecf20Sopenharmony_ci	 's/^\#define[ \t]+AF_([A-Z0-9_]+)[ \t]+([0-9]+)(.*)/\L\1/p'\
348c2ecf20Sopenharmony_ci	 $< | tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci# Build a lower case string table of sock type names
378c2ecf20Sopenharmony_ci# Transform lines from
388c2ecf20Sopenharmony_ci#    SOCK_STREAM	= 1,
398c2ecf20Sopenharmony_ci# to
408c2ecf20Sopenharmony_ci#    [1] = "stream",
418c2ecf20Sopenharmony_ciquiet_cmd_make-sock = GEN     $@
428c2ecf20Sopenharmony_cicmd_make-sock = echo "static const char *sock_type_names[] = {" >> $@ ;\
438c2ecf20Sopenharmony_ci	sed $^ >>$@ -r -n \
448c2ecf20Sopenharmony_ci	-e 's/^\tSOCK_([A-Z0-9_]+)[\t]+=[ \t]+([0-9]+)(.*)/[\2] = "\L\1",/p';\
458c2ecf20Sopenharmony_ci	echo "};" >> $@
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci# Build a lower case string table of capability names
488c2ecf20Sopenharmony_ci# Transforms lines from
498c2ecf20Sopenharmony_ci#    #define CAP_DAC_OVERRIDE     1
508c2ecf20Sopenharmony_ci# to
518c2ecf20Sopenharmony_ci#    [1] = "dac_override",
528c2ecf20Sopenharmony_ciquiet_cmd_make-caps = GEN     $@
538c2ecf20Sopenharmony_cicmd_make-caps = echo "static const char *const capability_names[] = {" > $@ ;\
548c2ecf20Sopenharmony_ci	sed $< >>$@ -r -n -e '/CAP_FS_MASK/d' \
558c2ecf20Sopenharmony_ci	-e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/[\2] = "\L\1",/p';\
568c2ecf20Sopenharmony_ci	echo "};" >> $@ ;\
578c2ecf20Sopenharmony_ci	printf '%s' '\#define AA_SFS_CAPS_MASK "' >> $@ ;\
588c2ecf20Sopenharmony_ci	sed $< -r -n -e '/CAP_FS_MASK/d' \
598c2ecf20Sopenharmony_ci	    -e 's/^\#define[ \t]+CAP_([A-Z0-9_]+)[ \t]+([0-9]+)/\L\1/p' | \
608c2ecf20Sopenharmony_ci	     tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci# Build a lower case string table of rlimit names.
648c2ecf20Sopenharmony_ci# Transforms lines from
658c2ecf20Sopenharmony_ci#    #define RLIMIT_STACK		3	/* max stack size */
668c2ecf20Sopenharmony_ci# to
678c2ecf20Sopenharmony_ci#    [RLIMIT_STACK] = "stack",
688c2ecf20Sopenharmony_ci#
698c2ecf20Sopenharmony_ci# and build a second integer table (with the second sed cmd), that maps
708c2ecf20Sopenharmony_ci# RLIMIT defines to the order defined in asm-generic/resource.h  This is
718c2ecf20Sopenharmony_ci# required by policy load to map policy ordering of RLIMITs to internal
728c2ecf20Sopenharmony_ci# ordering for architectures that redefine an RLIMIT.
738c2ecf20Sopenharmony_ci# Transforms lines from
748c2ecf20Sopenharmony_ci#    #define RLIMIT_STACK		3	/* max stack size */
758c2ecf20Sopenharmony_ci# to
768c2ecf20Sopenharmony_ci# RLIMIT_STACK, 
778c2ecf20Sopenharmony_ci#
788c2ecf20Sopenharmony_ci# and build the securityfs entries for the mapping.
798c2ecf20Sopenharmony_ci# Transforms lines from
808c2ecf20Sopenharmony_ci#    #define RLIMIT_FSIZE        1   /* Maximum filesize */
818c2ecf20Sopenharmony_ci#    #define RLIMIT_STACK		3	/* max stack size */
828c2ecf20Sopenharmony_ci# to
838c2ecf20Sopenharmony_ci# #define AA_SFS_RLIMIT_MASK "fsize stack"
848c2ecf20Sopenharmony_ciquiet_cmd_make-rlim = GEN     $@
858c2ecf20Sopenharmony_cicmd_make-rlim = echo "static const char *const rlim_names[RLIM_NLIMITS] = {" \
868c2ecf20Sopenharmony_ci	> $@ ;\
878c2ecf20Sopenharmony_ci	sed $< >> $@ -r -n \
888c2ecf20Sopenharmony_ci	    -e 's/^\# ?define[ \t]+(RLIMIT_([A-Z0-9_]+)).*/[\1] = "\L\2",/p';\
898c2ecf20Sopenharmony_ci	echo "};" >> $@ ;\
908c2ecf20Sopenharmony_ci	echo "static const int rlim_map[RLIM_NLIMITS] = {" >> $@ ;\
918c2ecf20Sopenharmony_ci	sed -r -n "s/^\# ?define[ \t]+(RLIMIT_[A-Z0-9_]+).*/\1,/p" $< >> $@ ;\
928c2ecf20Sopenharmony_ci	echo "};" >> $@ ; \
938c2ecf20Sopenharmony_ci	printf '%s' '\#define AA_SFS_RLIMIT_MASK "' >> $@ ;\
948c2ecf20Sopenharmony_ci	sed -r -n 's/^\# ?define[ \t]+RLIMIT_([A-Z0-9_]+).*/\L\1/p' $< | \
958c2ecf20Sopenharmony_ci	    tr '\n' ' ' | sed -e 's/ $$/"\n/' >> $@
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci$(obj)/capability.o : $(obj)/capability_names.h
988c2ecf20Sopenharmony_ci$(obj)/net.o : $(obj)/net_names.h
998c2ecf20Sopenharmony_ci$(obj)/resource.o : $(obj)/rlim_names.h
1008c2ecf20Sopenharmony_ci$(obj)/capability_names.h : $(srctree)/include/uapi/linux/capability.h \
1018c2ecf20Sopenharmony_ci			    $(src)/Makefile
1028c2ecf20Sopenharmony_ci	$(call cmd,make-caps)
1038c2ecf20Sopenharmony_ci$(obj)/rlim_names.h : $(srctree)/include/uapi/asm-generic/resource.h \
1048c2ecf20Sopenharmony_ci		      $(src)/Makefile
1058c2ecf20Sopenharmony_ci	$(call cmd,make-rlim)
1068c2ecf20Sopenharmony_ci$(obj)/net_names.h : $(srctree)/include/linux/socket.h \
1078c2ecf20Sopenharmony_ci		     $(srctree)/include/linux/net.h \
1088c2ecf20Sopenharmony_ci		     $(src)/Makefile
1098c2ecf20Sopenharmony_ci	$(call cmd,make-af)
1108c2ecf20Sopenharmony_ci	$(call cmd,make-sock)
111