Skip to content

Commit 30e3fb3

Browse files
gegarciatjaalton
authored andcommitted
UBUNTU: SAUCE: apparmor4.0.0 [68/91]: add io_uring mediation
BugLink: http://bugs.launchpad.net/bugs/2028253 For now, the io_uring mediation is limited to sqpoll and override_creds. Signed-off-by: Georgia Garcia <[email protected]> Signed-off-by: John Johansen <[email protected]> (cherry picked from https://gitlab.com/jjohansen/apparmor-kernel) Signed-off-by: Andrea Righi <[email protected]> Signed-off-by: Timo Aaltonen <[email protected]>
1 parent f7b8388 commit 30e3fb3

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

security/apparmor/apparmorfs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,6 +2588,8 @@ static struct aa_sfs_entry aa_sfs_entry_domain[] = {
25882588
static struct aa_sfs_entry aa_sfs_entry_unconfined[] = {
25892589
AA_SFS_FILE_BOOLEAN("change_profile", 1),
25902590
AA_SFS_FILE_INTPTR("userns", aa_unprivileged_userns_restricted),
2591+
AA_SFS_FILE_INTPTR("io_uring",
2592+
aa_unprivileged_uring_restricted),
25912593
{ }
25922594
};
25932595

security/apparmor/include/policy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern int aa_unprivileged_userns_restricted;
3838
extern int aa_unprivileged_userns_restricted_force;
3939
extern int aa_unprivileged_userns_restricted_complain;
4040
extern int aa_unprivileged_unconfined_restricted;
41+
extern int aa_unprivileged_uring_restricted;
4142

4243
extern const char *const aa_profile_mode_names[];
4344
#define APPARMOR_MODE_NAMES_MAX_INDEX 4

security/apparmor/lsm.c

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -805,13 +805,41 @@ static int profile_uring(struct aa_profile *profile, u32 request,
805805
{
806806
unsigned int state;
807807
struct aa_ruleset *rules;
808-
int error = 0;
809808

810809
AA_BUG(!profile);
811810

812811
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+
*/
813816
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 {
815843
struct aa_perms perms = { };
816844

817845
if (new) {
@@ -821,11 +849,11 @@ static int profile_uring(struct aa_profile *profile, u32 request,
821849
perms = *aa_lookup_perms(rules->policy, state);
822850
}
823851
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,
825853
audit_uring_cb);
826-
}
854+
} while (0);
827855

828-
return error;
856+
return 0;
829857
}
830858

831859
/**
@@ -2412,6 +2440,13 @@ static struct ctl_table apparmor_sysctl_table[] = {
24122440
.mode = 0600,
24132441
.proc_handler = apparmor_dointvec,
24142442
},
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+
},
24152450
};
24162451

24172452
static int __init apparmor_init_sysctl(void)

security/apparmor/policy.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ int aa_unprivileged_userns_restricted = IS_ENABLED(CONFIG_SECURITY_APPARMOR_REST
9292
int aa_unprivileged_userns_restricted_force;
9393
int aa_unprivileged_userns_restricted_complain;
9494
int aa_unprivileged_unconfined_restricted;
95+
int aa_unprivileged_uring_restricted;
9596

9697
const char *const aa_profile_mode_names[] = {
9798
"enforce",

0 commit comments

Comments
 (0)