From 9b66f6a749da43e1af34a1e72c8b0513fb3d745b Mon Sep 17 00:00:00 2001 From: Georgia Garcia Date: Wed, 17 Jul 2024 11:02:56 -0300 Subject: [PATCH 1/3] parser: fix unix for all rule By specifying 0 in the unix type, all rules were allowing only the "none" type, when it wanted to allow all types, so replace it by 0xffffffff. Also, add this testcase to the unix regression tests. Fixes: https://gitlab.com/apparmor/apparmor/-/issues/410 Signed-off-by: Georgia Garcia --- parser/all_rule.cc | 2 +- tests/regression/apparmor/unix_socket.inc | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/parser/all_rule.cc b/parser/all_rule.cc index 34159349e..f0d07aee3 100644 --- a/parser/all_rule.cc +++ b/parser/all_rule.cc @@ -39,7 +39,7 @@ void all_rule::add_implied_rules(Profile &prof) prefix_rule_t *rule; const prefixes *prefix = this; - rule = new unix_rule(0, audit, rule_mode); + rule = new unix_rule(0xffffffff, audit, rule_mode); (void) rule->add_prefix(*prefix); prof.rule_ents.push_back(rule); diff --git a/tests/regression/apparmor/unix_socket.inc b/tests/regression/apparmor/unix_socket.inc index 905c99c6f..6d6c60fd4 100644 --- a/tests/regression/apparmor/unix_socket.inc +++ b/tests/regression/apparmor/unix_socket.inc @@ -71,6 +71,11 @@ do_test() desc+=" confined $test_prog" + if [ "$(parser_supports 'all,')" = "true" ]; then + $genprof "all" + runchecktest "$desc (allow all)" pass $args + fi + $genprof "unix:ALL" runchecktest "$desc (implicit perms)" pass $args From d3f53082655ec778bd18edd60496e558016f22e7 Mon Sep 17 00:00:00 2001 From: Georgia Garcia Date: Wed, 17 Jul 2024 14:50:39 -0300 Subject: [PATCH 2/3] parser: fix mount for all rule Without AA_MAY_MOUNT, mount was not allowed by the allow all rule. AA_DUMMY_REMOUNT does become AA_MAY_MOUNT, but it fixes the flags to remount only, so other options are not included. Also, add allow all rule testcases to the mount regression tests. Fixes: https://gitlab.com/apparmor/apparmor/-/issues/410 Signed-off-by: Georgia Garcia --- parser/all_rule.cc | 2 +- tests/regression/apparmor/mount.sh | 30 +++++++++++++++++++++++++ tests/regression/apparmor/pivot_root.sh | 5 +++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/parser/all_rule.cc b/parser/all_rule.cc index f0d07aee3..4ebc47a8a 100644 --- a/parser/all_rule.cc +++ b/parser/all_rule.cc @@ -67,7 +67,7 @@ void all_rule::add_implied_rules(Profile &prof) (void) rule->add_prefix(*prefix); prof.rule_ents.push_back(rule); - rule = new mnt_rule(NULL, NULL, NULL, NULL, 0); + rule = new mnt_rule(NULL, NULL, NULL, NULL, AA_MAY_MOUNT); (void) rule->add_prefix(*prefix); prof.rule_ents.push_back(rule); diff --git a/tests/regression/apparmor/mount.sh b/tests/regression/apparmor/mount.sh index 37c5f3193..0154d1ac1 100755 --- a/tests/regression/apparmor/mount.sh +++ b/tests/regression/apparmor/mount.sh @@ -424,6 +424,34 @@ fsmount_tests() { fsmount_test " fsmount deny att_dis" "qual=deny:" "flag:attach_disconnected" ${should_fail} } +all_rule() { + if [ "$(parser_supports 'all,')" != "true" ]; then + echo " not supported by parser - skipping allow all," + return + fi + + settest mount + genprofile "all" + + runchecktest "MOUNT (confined allow all)" pass mount ${loop_device} ${mount_point} + + runchecktest "UMOUNT (confined allow all)" pass umount ${loop_device} ${mount_point} + + runchecktest "MOUNT (confined allow all remount setup)" pass mount ${loop_device} ${mount_point} + runchecktest "MOUNT (confined allow all remount)" pass mount ${loop_device} ${mount_point} -o remount + remove_mnt + + settest move_mount + genprofile "all" + + runchecktest "MOVE_MOUNT (confined fsmount: allow all)" pass fsmount ${loop_device} ${mount_point} ${fstype} + remove_mnt + + mount ${loop_device} ${mnt_source} + runchecktest "MOVE_MOUNT (confined open_tree: allow all)" pass open_tree ${mount_point2} ${mount_point} ${fstype} + remove_mnt +} + # TEST 1. Make sure can mount and umount unconfined runchecktest "MOUNT (unconfined)" pass mount ${loop_device} ${mount_point} remove_mnt @@ -569,6 +597,8 @@ else fsmount_tests tmpfs ${mount_point} tmpfs fsmount_tests ${loop_device} ${mount_point} ${fstype} open_tree_tests ${mount_point2} ${mount_point} ${fstype} + + all_rule fi #need tests for chroot diff --git a/tests/regression/apparmor/pivot_root.sh b/tests/regression/apparmor/pivot_root.sh index dd7104edc..70abec5e7 100755 --- a/tests/regression/apparmor/pivot_root.sh +++ b/tests/regression/apparmor/pivot_root.sh @@ -120,6 +120,11 @@ if [ "$(kernel_features mount)" != "true" -o "$(parser_supports 'mount,')" != "t exit fi +if [ "$(parser_supports 'all,')" = "true" ]; then + genprofile "all" + do_test "allow all rule" pass "$put_old" "$new_root" "$test" +fi + # Ensure failure when no pivot_root perms are granted genprofile $cur $cap do_test "cap only" fail "$put_old" "$new_root" "$test" From bf36ace42174d81010a4f411c42b5e14307490fb Mon Sep 17 00:00:00 2001 From: Georgia Garcia Date: Wed, 17 Jul 2024 17:48:40 -0300 Subject: [PATCH 3/3] tests: add allow all rule test to the regression tests Signed-off-by: Georgia Garcia --- tests/regression/apparmor/aa_exec.sh | 13 +++++++++++ tests/regression/apparmor/access.sh | 9 +++++++- .../apparmor/attach_disconnected.sh | 9 ++++++++ tests/regression/apparmor/dbus_eavesdrop.sh | 5 ++++ tests/regression/apparmor/dbus_message.sh | 6 +++++ tests/regression/apparmor/dbus_service.sh | 8 +++++++ .../apparmor/dbus_unrequested_reply.sh | 8 +++++++ tests/regression/apparmor/io_uring.sh | 5 ++++ tests/regression/apparmor/net_inet.sh | 23 +++++++++++++++---- tests/regression/apparmor/net_raw.sh | 4 ++++ tests/regression/apparmor/posix_mq.sh | 4 ++++ tests/regression/apparmor/ptrace_v6.inc | 9 ++++++++ tests/regression/apparmor/tcp.sh | 6 +++++ tests/regression/apparmor/userns.sh | 5 ++++ 14 files changed, 109 insertions(+), 5 deletions(-) diff --git a/tests/regression/apparmor/aa_exec.sh b/tests/regression/apparmor/aa_exec.sh index daaefee9b..9ef1f5355 100755 --- a/tests/regression/apparmor/aa_exec.sh +++ b/tests/regression/apparmor/aa_exec.sh @@ -79,3 +79,16 @@ runchecktest "complain (--namespace=${ns})" pass "$aa_exec -n $ns -p $test" "$te genprofile_aa_exec "$test" 0 runchecktest "negative test: bad ns (--namespace=${ns}XXX)" fail "$aa_exec -n ${ns}XXX -p $test" "$test (enforce)" + +if [ "$(parser_supports 'all,')" = "true" ]; then + genprofile --stdin <