]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
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)
committerKhalid Elmously <khalid.elmously@canonical.com>
Fri, 14 Feb 2020 05:29:37 +0000 (00:29 -0500)
BugLink: https://bugs.launchpad.net/bugs/1863019
[ 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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
security/apparmor/include/context.h
security/apparmor/lsm.c

index 349ea30882677ddebc0b37289f35fe3a70aff687..4031bf0d67fa8c333ada7a9ffad8e3bb8abee42c 100644 (file)
@@ -210,6 +210,8 @@ static inline struct aa_label *begin_current_label_crit_section(void)
 {
        struct aa_label *label = aa_current_raw_label();
 
+       might_sleep();
+
        if (label_is_stale(label)) {
                label = aa_get_newest_label(label);
                if (aa_replace_current_label(label) == 0)
index 80da8e51c2fe6ebb0aaf3a1da54e5e5c72d2ea47..384da7789d94e3d16c98f651b9fa1a1f337a3710 100644 (file)
@@ -87,12 +87,12 @@ static int apparmor_ptrace_access_check(struct task_struct *child,
        struct aa_label *tracer, *tracee;
        int error;
 
-       tracer = begin_current_label_crit_section();
+       tracer = __begin_current_label_crit_section();
        tracee = aa_get_task_label(child);
        error = aa_may_ptrace(tracer, tracee,
                  mode == PTRACE_MODE_READ ? AA_PTRACE_READ : AA_PTRACE_TRACE);
        aa_put_label(tracee);
-       end_current_label_crit_section(tracer);
+       __end_current_label_crit_section(tracer);
 
        return error;
 }