Skip to content

Commit 1f8266f

Browse files
thejhjrjohansen
authored andcommitted
apparmor: don't try to replace stale label in ptrace access check
As a comment above begin_current_label_crit_section() explains, begin_current_label_crit_section() must run in sleepable context because when label_is_stale() is true, aa_replace_current_label() runs, which uses prepare_creds(), which can sleep. Until now, the ptrace access check (which runs with a task lock held) violated this rule. Also add a might_sleep() assertion to begin_current_label_crit_section(), because asserts are less likely to be ignored than comments. Fixes: b2d09ae ("apparmor: move ptrace checks to using labels") Signed-off-by: Jann Horn <[email protected]> Signed-off-by: John Johansen <[email protected]>
1 parent 5f99758 commit 1f8266f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

security/apparmor/include/cred.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ static inline struct aa_label *begin_current_label_crit_section(void)
151151
{
152152
struct aa_label *label = aa_current_raw_label();
153153

154+
might_sleep();
155+
154156
if (label_is_stale(label)) {
155157
label = aa_get_newest_label(label);
156158
if (aa_replace_current_label(label) == 0)

security/apparmor/lsm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ static int apparmor_ptrace_access_check(struct task_struct *child,
114114
struct aa_label *tracer, *tracee;
115115
int error;
116116

117-
tracer = begin_current_label_crit_section();
117+
tracer = __begin_current_label_crit_section();
118118
tracee = aa_get_task_label(child);
119119
error = aa_may_ptrace(tracer, tracee,
120120
(mode & PTRACE_MODE_READ) ? AA_PTRACE_READ
121121
: AA_PTRACE_TRACE);
122122
aa_put_label(tracee);
123-
end_current_label_crit_section(tracer);
123+
__end_current_label_crit_section(tracer);
124124

125125
return error;
126126
}

0 commit comments

Comments
 (0)