Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp833916pxu; Mon, 23 Nov 2020 05:28:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxq4WX5VifzYWEJJXuYRffFihlIHUPMDxoM7Efg/pJl5kZVV8QOZxOp3//b1p7sz0SpcDi X-Received: by 2002:a17:906:4c85:: with SMTP id q5mr5902683eju.375.1606138102606; Mon, 23 Nov 2020 05:28:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606138102; cv=none; d=google.com; s=arc-20160816; b=vTtMGqXlvFZHsHfaU64Svc7A60CIGFc3/jXDYfX2j7WjPg+uwzoIjYlBqkdpfuSu7N Z4CbxpLKFkOe938BaBfxWOjcnBxpCAnauJjbJQMFn1GOOWe6xGfxQixIut3y3SyX5b4M CnAwwEh/h+YOmPjcO7mLBPm+QvrUTxRDDGQdJq0jqS0jwX3tQzpkzmPjcG3ucSF/J4R1 LuTZYqAQ7JieRsik7W/Hk/gyf0SrwJirySxk1K4cBlfQf4Ln+YCMCOHZE3ZBXD6QZRfV b0C76mcWLq6wbOhD9clYgWNoKSvTaAb0J/j+UQ4ZrlxbnAimXDoXoq/gDRx4ZdD0NOAk z2Jg== 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=VUlpoVfqA8BcKzWZ+jYKlfiLFOtO/XFl2Bu+efsg5/E=; b=FOZ27CGc40q049ymPOov1WgZfuxNl1ID0aHSVru+uiZWE888aEp+HRYQTNVPDzZgCN JzLFM4FydhQhwI+g5arR50gqeiC9d06JxEull4QXKDS4bP+OCHGOS97gXyEAwUGiskds MH8dGkJ3VtVc17u/kveXvRtIRen1czj5EExvdjWsrfEtFcjI4ORn2E9FY9U2IsLtkJ12 aWUrfXuIYHHwKXfPrq7sZHO0ixxNu+Ef58t3LgstPusOOoxGFNG9HB1jvl67zzMYsbmK uyPXyUkaKImWHu3hvM2ZKrtRksSgisjgoQlq89NNCzLIH+nLN4j1JwJJF0Bd4nrt+K94 FIQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ToC8Z5Au; 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 rl11si6234951ejb.348.2020.11.23.05.27.59; Mon, 23 Nov 2020 05:28:22 -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=ToC8Z5Au; 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 S1731900AbgKWNZO (ORCPT + 99 others); Mon, 23 Nov 2020 08:25:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:44838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731212AbgKWMd0 (ORCPT ); Mon, 23 Nov 2020 07:33:26 -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 796142065E; Mon, 23 Nov 2020 12:33:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606134805; bh=QMmUiflosflNQFXLXUur3KFYJHIusEcaRmsEfAOoN1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ToC8Z5AuSKXOdM54r71A2Q0zEMCQvuEdzjFxYaJiQddDMOES4R5TbULIZ5YzvHqOP w5dVW0T7Mgqrjnwl0vJxxf2qUt8Bq7LnDt6h95gIm8GQ7hf9lxxDMBMl7GltbTWVO1 aLRzu4de3fawo2pEFNqHBhG+NZnp79EXTKSACF3k= 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 4.19 88/91] ptrace: Set PF_SUPERPRIV when checking capability Date: Mon, 23 Nov 2020 13:22:48 +0100 Message-Id: <20201123121813.595323104@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121809.285416732@linuxfoundation.org> References: <20201123121809.285416732@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 @@ -258,17 +258,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. */ @@ -320,7 +314,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; @@ -339,7 +333,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);