Skip to content

Commit 4d944bc

Browse files
mssalvatoreshuahkh
authored andcommitted
apparmor: add AppArmor KUnit tests for policy unpack
Add KUnit tests to test AppArmor unpacking of userspace policies. AppArmor uses a serialized binary format for loading policies. To find policy format documentation see Documentation/admin-guide/LSM/apparmor.rst. In order to write the tests against the policy unpacking code, some static functions needed to be exposed for testing purposes. One of the goals of this patch is to establish a pattern for which testing these kinds of functions should be done in the future. Signed-off-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Mike Salvatore <mike.salvatore@canonical.com> Acked-by: John Johansen <john.johansen@canonical.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent c79f46a commit 4d944bc

File tree

3 files changed

+627
-0
lines changed

3 files changed

+627
-0
lines changed

security/apparmor/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,19 @@ config SECURITY_APPARMOR_DEBUG_MESSAGES
6868
Set the default value of the apparmor.debug kernel parameter.
6969
When enabled, various debug messages will be logged to
7070
the kernel message buffer.
71+
72+
config SECURITY_APPARMOR_KUNIT_TEST
73+
bool "Build KUnit tests for policy_unpack.c"
74+
depends on KUNIT && SECURITY_APPARMOR
75+
help
76+
This builds the AppArmor KUnit tests.
77+
78+
KUnit tests run during boot and output the results to the debug log
79+
in TAP format (http://testanything.org/). Only useful for kernel devs
80+
running KUnit test harness and are not for inclusion into a
81+
production build.
82+
83+
For more information on KUnit and unit tests in general please refer
84+
to the KUnit documentation in Documentation/dev-tools/kunit/.
85+
86+
If unsure, say N.

security/apparmor/policy_unpack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,3 +1228,7 @@ int aa_unpack(struct aa_loaddata *udata, struct list_head *lh,
12281228

12291229
return error;
12301230
}
1231+
1232+
#ifdef CONFIG_SECURITY_APPARMOR_KUNIT_TEST
1233+
#include "policy_unpack_test.c"
1234+
#endif /* CONFIG_SECURITY_APPARMOR_KUNIT_TEST */

0 commit comments

Comments
 (0)