apparmor: don't try to replace stale label in ptrace access check
authorJann Horn <jannh@google.com>
Thu, 13 Sep 2018 16:12:09 +0000 (18:12 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 27 Jan 2020 13:46:04 +0000 (14:46 +0100)
commit49f3e22df7169a098a13384b51a2caabbd77604c
tree935f1ae1793ffebf316bea3ac5ddeabd3316817f
parent961e9f394d4ce5ec9518bd2c04469da5d2d9d3b3
apparmor: don't try to replace stale label in ptrace access check

[ Upstream commit 1f8266ff58840d698a1e96d2274189de1bdf7969 ]

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: b2d09ae449ced ("apparmor: move ptrace checks to using labels")
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
security/apparmor/include/context.h
security/apparmor/lsm.c