Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1240538pxu; Mon, 23 Nov 2020 15:40:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRIqoUPR3y7yAip3rHaxrAvgAMoGdw5J8IXFp+Tz+n2ClkbMoZxYehjAaJpQFQSKWvU2i6 X-Received: by 2002:a17:906:5793:: with SMTP id k19mr1911588ejq.410.1606174859663; Mon, 23 Nov 2020 15:40:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606174859; cv=none; d=google.com; s=arc-20160816; b=nWifNOGgcqVwDo9bEI3m/U8A3p/mPtINWAfD3+qcal94+eUSIOodhLdlAUVg9mlSXr AoZr0b6ujpCWnqo3sO+JmHst5EzLaj5+EbJac64e/uST/TH3Ps7qJq7+XNYKYQv4UU5D QKXv+PlHXvYY+YlQNG5EAeuisioQ2im36qqKOfGCCjC33ORGp64QY36mZpBUeVozjENu 04uvtDmoFZ1EOo0pU51B5TF0D8/jTFaawAavEojXUqUC8XcIYMvNvFdAyrIL4Xp0s7kv xY59gVPbigVygmQWAxjzmEZHlk9SB2z+vHquvajfxRfqK09/TrBC61jerkVLPtjdNZf6 RjrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4xt7DO6C+sczSeazETiloYEqdHnAizCyPu9nJEueRq4=; b=of1ncquie/En2MscrAOsMO1lWh9x4voqtoexe7Vkra9wqd/68mmgb3vFfV9I6T+68B vcglY328FhyefXmOZ4dSdsBmNf1rxB0h7HOA3ROhLMDHFmBRwctl6J4A4ZHZZIAynSUg toUNlcUQknXwBjB0x43HsqlLrA0mFt0Tb6/b7ZgZVxKkzW0mNI/50zTR1Wi8Iq+v5nVr tTytvsQ5R3v2zrfA7h5kFqUG/Js78SpHk2v2jiJZDHh1zy56q0z1PMGCv9rdKRLBrqLk lxPrCwBylXNXHnE3o/cDjvdEmUeHnnBK9Z/lDH3hbHvdUie96kbIJ+49X1bIHXQmPKfr 3IdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FPqoab8S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k22si7343805ejv.345.2020.11.23.15.40.37; Mon, 23 Nov 2020 15:40:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FPqoab8S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732957AbgKWMmp (ORCPT + 99 others); Mon, 23 Nov 2020 07:42:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:54148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732615AbgKWMlJ (ORCPT ); Mon, 23 Nov 2020 07:41:09 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C97602076E; Mon, 23 Nov 2020 12:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135268; bh=KO/oSIr7KiWkP34qfoKSWjtSV23+odo3BU+VctyKVZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FPqoab8SI/YyhJVCSCwtgwFFRyCjVtM+5JP8S5WmOf/cYyTtkq+Cpj6bpqwdnqBui UJvBUtsv5cGBZ6BqW7N8X2gi6ZkujVwGVXqpGPKVv46cIaDAkCyQM4ADCdBztw8Y4L mt1O5EU+1gMUqKoVdh+sCkDnmXh9Ff3NNVqa2lZk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christian Brauner , Eric Paris , Jann Horn , Kees Cook , Oleg Nesterov , "Serge E. Hallyn" , Tyler Hicks , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= Subject: [PATCH 5.4 152/158] ptrace: Set PF_SUPERPRIV when checking capability Date: Mon, 23 Nov 2020 13:23:00 +0100 Message-Id: <20201123121827.265275346@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mickaël Salaün commit cf23705244c947151179f929774fabf71e239eee upstream. Commit 69f594a38967 ("ptrace: do not audit capability check when outputing /proc/pid/stat") replaced the use of ns_capable() with has_ns_capability{,_noaudit}() which doesn't set PF_SUPERPRIV. Commit 6b3ad6649a4c ("ptrace: reintroduce usage of subjective credentials in ptrace_has_cap()") replaced has_ns_capability{,_noaudit}() with security_capable(), which doesn't set PF_SUPERPRIV neither. Since commit 98f368e9e263 ("kernel: Add noaudit variant of ns_capable()"), a new ns_capable_noaudit() helper is available. Let's use it! As a result, the signature of ptrace_has_cap() is restored to its original one. Cc: Christian Brauner Cc: Eric Paris Cc: Jann Horn Cc: Kees Cook Cc: Oleg Nesterov Cc: Serge E. Hallyn Cc: Tyler Hicks Cc: stable@vger.kernel.org Fixes: 6b3ad6649a4c ("ptrace: reintroduce usage of subjective credentials in ptrace_has_cap()") Fixes: 69f594a38967 ("ptrace: do not audit capability check when outputing /proc/pid/stat") Signed-off-by: Mickaël Salaün Reviewed-by: Jann Horn Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20201030123849.770769-2-mic@digikod.net Signed-off-by: Greg Kroah-Hartman --- kernel/ptrace.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -264,17 +264,11 @@ static int ptrace_check_attach(struct ta return ret; } -static bool ptrace_has_cap(const struct cred *cred, struct user_namespace *ns, - unsigned int mode) +static bool ptrace_has_cap(struct user_namespace *ns, unsigned int mode) { - int ret; - if (mode & PTRACE_MODE_NOAUDIT) - ret = security_capable(cred, ns, CAP_SYS_PTRACE, CAP_OPT_NOAUDIT); - else - ret = security_capable(cred, ns, CAP_SYS_PTRACE, CAP_OPT_NONE); - - return ret == 0; + return ns_capable_noaudit(ns, CAP_SYS_PTRACE); + return ns_capable(ns, CAP_SYS_PTRACE); } /* Returns 0 on success, -errno on denial. */ @@ -326,7 +320,7 @@ static int __ptrace_may_access(struct ta gid_eq(caller_gid, tcred->sgid) && gid_eq(caller_gid, tcred->gid)) goto ok; - if (ptrace_has_cap(cred, tcred->user_ns, mode)) + if (ptrace_has_cap(tcred->user_ns, mode)) goto ok; rcu_read_unlock(); return -EPERM; @@ -345,7 +339,7 @@ ok: mm = task->mm; if (mm && ((get_dumpable(mm) != SUID_DUMP_USER) && - !ptrace_has_cap(cred, mm->user_ns, mode))) + !ptrace_has_cap(mm->user_ns, mode))) return -EPERM; return security_ptrace_access_check(task, mode);