@@ -805,13 +805,41 @@ static int profile_uring(struct aa_profile *profile, u32 request,
805
805
{
806
806
unsigned int state ;
807
807
struct aa_ruleset * rules ;
808
- int error = 0 ;
809
808
810
809
AA_BUG (!profile );
811
810
812
811
rules = list_first_entry (& profile -> rules , typeof (* rules ), list );
812
+
813
+ /* TODO: rework unconfined profile/dfa to mediate user ns, then
814
+ * we can drop the unconfined test
815
+ */
813
816
state = RULE_MEDIATES (rules , AA_CLASS_IO_URING );
814
- if (state ) {
817
+ if (!state ) {
818
+ /* TODO: this gets replaced when the default unconfined
819
+ * profile dfa gets updated to handle this
820
+ */
821
+ if (profile_unconfined (profile ) &&
822
+ profile == profiles_ns (profile )-> unconfined ) {
823
+ if (!aa_unprivileged_uring_restricted ||
824
+ ns_capable_noaudit (current_user_ns (), cap ))
825
+ /* unconfined early bail out */
826
+ return 0 ;
827
+ /* unconfined unprivileged user */
828
+ /* don't just return: allow complain mode to override */
829
+ } else {
830
+ /* Fallback to capability check if profile doesn't
831
+ * support io_uring rules. Note: special unconfined
832
+ * profiles as well.
833
+ */
834
+ return aa_capable (current_cred (), & profile -> label ,
835
+ cap , CAP_OPT_NONE );
836
+ }
837
+ /* continue to mediation - !state means non-accepting
838
+ * but can be overidden by complain
839
+ */
840
+ }
841
+ /* block so perms is not initialized unless mediating */
842
+ do {
815
843
struct aa_perms perms = { };
816
844
817
845
if (new ) {
@@ -821,11 +849,11 @@ static int profile_uring(struct aa_profile *profile, u32 request,
821
849
perms = * aa_lookup_perms (rules -> policy , state );
822
850
}
823
851
aa_apply_modes_to_perms (profile , & perms );
824
- error = aa_check_perms (profile , & perms , request , ad ,
852
+ return aa_check_perms (profile , & perms , request , ad ,
825
853
audit_uring_cb );
826
- }
854
+ } while ( 0 );
827
855
828
- return error ;
856
+ return 0 ;
829
857
}
830
858
831
859
/**
@@ -2412,6 +2440,13 @@ static struct ctl_table apparmor_sysctl_table[] = {
2412
2440
.mode = 0600 ,
2413
2441
.proc_handler = apparmor_dointvec ,
2414
2442
},
2443
+ {
2444
+ .procname = "apparmor_restrict_unprivileged_io_uring" ,
2445
+ .data = & aa_unprivileged_uring_restricted ,
2446
+ .maxlen = sizeof (int ),
2447
+ .mode = 0600 ,
2448
+ .proc_handler = apparmor_dointvec ,
2449
+ },
2415
2450
};
2416
2451
2417
2452
static int __init apparmor_init_sysctl (void )
0 commit comments