Commit 1f8266ff authored by Jann Horn's avatar Jann Horn Committed by John Johansen

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: b2d09ae4 ("apparmor: move ptrace checks to using labels")
Signed-off-by: default avatarJann Horn <jannh@google.com>
Signed-off-by: default avatarJohn Johansen <john.johansen@canonical.com>
parent 5f997580
...@@ -151,6 +151,8 @@ static inline struct aa_label *begin_current_label_crit_section(void) ...@@ -151,6 +151,8 @@ static inline struct aa_label *begin_current_label_crit_section(void)
{ {
struct aa_label *label = aa_current_raw_label(); struct aa_label *label = aa_current_raw_label();
might_sleep();
if (label_is_stale(label)) { if (label_is_stale(label)) {
label = aa_get_newest_label(label); label = aa_get_newest_label(label);
if (aa_replace_current_label(label) == 0) if (aa_replace_current_label(label) == 0)
......
...@@ -114,13 +114,13 @@ static int apparmor_ptrace_access_check(struct task_struct *child, ...@@ -114,13 +114,13 @@ static int apparmor_ptrace_access_check(struct task_struct *child,
struct aa_label *tracer, *tracee; struct aa_label *tracer, *tracee;
int error; int error;
tracer = begin_current_label_crit_section(); tracer = __begin_current_label_crit_section();
tracee = aa_get_task_label(child); tracee = aa_get_task_label(child);
error = aa_may_ptrace(tracer, tracee, error = aa_may_ptrace(tracer, tracee,
(mode & PTRACE_MODE_READ) ? AA_PTRACE_READ (mode & PTRACE_MODE_READ) ? AA_PTRACE_READ
: AA_PTRACE_TRACE); : AA_PTRACE_TRACE);
aa_put_label(tracee); aa_put_label(tracee);
end_current_label_crit_section(tracer); __end_current_label_crit_section(tracer);
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment