From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F51CC33CB6 for ; Thu, 16 Jan 2020 17:22:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D669C20684 for ; Thu, 16 Jan 2020 17:22:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579195322; bh=sUEmpbvttt0S4MWyiKJbNj8b+VkU2b5Kh+cieFdT378=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=dU3I/dLDp/exUAIW4hg6vq/Uqin5wRjbhdTbsYDJb/J8NOFa2NAXZvpQK9yy4UXha z+RBfELNOSqdkIBs2O84Z67qtKqrQFUkkkjwUumn19mLSvBT71eHrNtdwl21vMwOUX QtR0UmWsd97jRkkOkT3ITTsE0UYvHY6bdJbktOYc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391501AbgAPRVw (ORCPT ); Thu, 16 Jan 2020 12:21:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:42472 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391200AbgAPRR0 (ORCPT ); Thu, 16 Jan 2020 12:17:26 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6C71E21582; Thu, 16 Jan 2020 17:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579195045; bh=sUEmpbvttt0S4MWyiKJbNj8b+VkU2b5Kh+cieFdT378=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z30zkRLj1VVOTkOOT8Lko9JuuA+kD9FEAMZlLISnv6iGM+jd5OXVqvLPHe8+dbjRA iqINVjF/+xa9AUkJwlu7zlipNfXuYnhi5DfRF2Xh68hjopnzTU1J7NJ/nnI1LS5eAs DYRs8pq67j7olWgtMthvvD7HTHf4x0u/aTKBdJq0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jann Horn , John Johansen , Sasha Levin , linux-security-module@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 004/371] apparmor: don't try to replace stale label in ptrace access check Date: Thu, 16 Jan 2020 12:11:12 -0500 Message-Id: <20200116171719.16965-4-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200116171719.16965-1-sashal@kernel.org> References: <20200116171719.16965-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: From: Jann Horn [ 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 Signed-off-by: John Johansen Signed-off-by: Sasha Levin --- security/apparmor/include/context.h | 2 ++ security/apparmor/lsm.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/security/apparmor/include/context.h b/security/apparmor/include/context.h index 6ae07e9aaa17..812cdec9dd3b 100644 --- a/security/apparmor/include/context.h +++ b/security/apparmor/include/context.h @@ -191,6 +191,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) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 1346ee5be04f..4f08023101f3 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -108,12 +108,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; } -- 2.20.1