Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1484833pxx; Fri, 30 Oct 2020 11:02:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYwTx7x0cZYoydZous8FPksO10zFRQ8f6V9DeZhxKZ+cKTpM9m38U+DbdLF58Z8MmQiOKf X-Received: by 2002:aa7:cf99:: with SMTP id z25mr3786359edx.139.1604080960407; Fri, 30 Oct 2020 11:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604080960; cv=none; d=google.com; s=arc-20160816; b=svw8Dw2RtXK4SwG6mikC++CWlENCOG3icGZzSRBwRWKCmZ1xZr89NWGyXvYR2KzU0w 3FMS0nvDfGWxD+AAZRiBLGdoBlHMWwKBOe6q4fq5PdDwMgvJuKHgflxI7VOAir+YXm3v G4WnaMO5OT8c+9ytiWQtBwhOc9OBiHjTdfP+VtLaABEzh26XWjl+M/XeVfsQP6KPuc7V vzVG8S7xPjS15jngxXOKEe0DBFH106AX17Ct4ac1CdRDpUt5clcrW1x1yUZwseM8QvEu vhPiTqC7lAO07XeZha3jBdpHL7AsMms3680amp0+LjHkSfqUX2kVbr8dYY3rQf03wMlU y3iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=jymM9yh2NwbUECBOMcs6up1bGqTHgPh+0sCknIZeqEc=; b=K0NTGVAAUUG3/MtwfAe3/9cA68BB+jIMELJ/QGCKMJCJQLQ8wcYo9CfsJyqo1lPO95 Y+GdxtabceFPoeHaqV3eJBfKaQJ1Ze9aLbq/FNxBfAC4f5AeL40Cmh5eOpUpiHHjphao 68Jn8NkijMP/WoVeXApNEvBEpPPPHp3FdN9ekXbVw5M0xtzlZh3/D/1kXxKDxZRq1xNf 1kDN7yr81svAZ1Iib9/MRvgXpzo34AV4EiZOYKc0bwe7UMMfRraLMHI4hinrSjXlSYlI 6+oZpUsYhTQbO3vB4fY42uwZtLAyxFt/AWrxrrBLB5L5AXOd8kd+SG4id9JsY/Xus7jH p9xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JcxskUBF; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u10si5432013edp.411.2020.10.30.11.02.15; Fri, 30 Oct 2020 11:02:40 -0700 (PDT) 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=@google.com header.s=20161025 header.b=JcxskUBF; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726430AbgJ3SAp (ORCPT + 99 others); Fri, 30 Oct 2020 14:00:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726178AbgJ3SAp (ORCPT ); Fri, 30 Oct 2020 14:00:45 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6B6DC0613CF for ; Fri, 30 Oct 2020 11:00:44 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id d24so7806507ljg.10 for ; Fri, 30 Oct 2020 11:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=jymM9yh2NwbUECBOMcs6up1bGqTHgPh+0sCknIZeqEc=; b=JcxskUBFZ/WcAF1g8J83ug0UWLLYvJoewVsMjFCWA8cwPUfGhS7/J93HXK8mFDwlrV h9rQHlxFzTLpABQ5cB+StsbCXXifmaImuVXpq9dx/FmxvwQrVsijAxJrAoBrcgRzMTBL 6l/eWt39O8yFF1NSGtmhYU5qnZC8f0fcusPPA02hObCiD1dqhSomQDGFLbBUlGYj2nrx e9IpbQdBJyNWB/NAqYflN/yDgYNTuAW3e4rqAXLyYe84y8SslHPW/Gbvp7dmX5lQz6uO LHIPKP488T/78jBD7iKflU7E9MRGFKkTYXFo9RHsmBjiyoLG6iaRLjlxbUEZGNTh4MQa BjiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=jymM9yh2NwbUECBOMcs6up1bGqTHgPh+0sCknIZeqEc=; b=XmEKOEQNTmEv08Ija5usfkNw3aXClszOq3fCTf1/yNs1UynM9Mm9PRekqzLAH7D9F6 V3BYFzHJaU5m+NqXCgV4puX9TOJoCYVZyyyP4xGqXJBNuxTjOKyHbjJWYgyXjipaMCdU zSXDbDNjGCTddCJirtJL5z0YvdHsUYYrKWCDMCMUuRRoDjKvjax6KVZyKZFMfhqX03xk EkxejJLMBV4z4Csif4d6Al+2hHC1a/tGXcE3N0RlLPVDcG+TF3m/VpBgk+bpXc7n4bHp IQjTrU2Aj7lhZ3OVbJwjQ0rkCVkPmDVTWst1vTNvGQi6vwXr8lacbV0QTc9ZGQu8rrYb xMIQ== X-Gm-Message-State: AOAM533kXNeQgxYVDW09nKe4dfKUnX6NXZu1RW4B/ch2eGrFZR9gYmyA XTPbymo/UOz1TW+3iUrCTY5dg083ZqpMekiMlbh7ew== X-Received: by 2002:a2e:8816:: with SMTP id x22mr1518588ljh.377.1604080843021; Fri, 30 Oct 2020 11:00:43 -0700 (PDT) MIME-Version: 1.0 References: <20201030123849.770769-1-mic@digikod.net> <20201030123849.770769-2-mic@digikod.net> <94a86084-5aab-4a2c-e654-f55130190c1a@digikod.net> In-Reply-To: <94a86084-5aab-4a2c-e654-f55130190c1a@digikod.net> From: Jann Horn Date: Fri, 30 Oct 2020 19:00:16 +0100 Message-ID: Subject: Re: [PATCH v1 1/2] ptrace: Set PF_SUPERPRIV when checking capability To: =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= Cc: Christian Brauner , Kees Cook , Oleg Nesterov , Eric Paris , James Morris , "Serge E . Hallyn" , Tyler Hicks , Will Drewry , kernel list , stable , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 30, 2020 at 5:06 PM Micka=C3=ABl Sala=C3=BCn = wrote: > On 30/10/2020 16:47, Jann Horn wrote: > > On Fri, Oct 30, 2020 at 1:39 PM Micka=C3=ABl Sala=C3=BCn wrote: > >> Commit 69f594a38967 ("ptrace: do not audit capability check when outpu= ting > >> /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 credenti= als 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 orig= inal 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 credenti= als in ptrace_has_cap()") > >> Fixes: 69f594a38967 ("ptrace: do not audit capability check when outpu= ting /proc/pid/stat") > >> Signed-off-by: Micka=C3=ABl Sala=C3=BCn > > > > Yeah... I guess this makes sense. (We'd have to undo or change it if > > we ever end up needing to use a different set of credentials, e.g. > > from ->f_cred, but I guess that's really something we should avoid > > anyway.) > > > > Reviewed-by: Jann Horn > > > > with one nit: > > > > > > [...] > >> /* Returns 0 on success, -errno on denial. */ > >> static int __ptrace_may_access(struct task_struct *task, unsigned int= mode) > >> { > >> - const struct cred *cred =3D current_cred(), *tcred; > >> + const struct cred *const cred =3D current_cred(), *tcred; > > > > This is an unrelated change, and almost no kernel code marks local > > pointer variables as "const". I would drop this change from the patch. > > This give guarantee that the cred variable will not be used for > something else than current_cred(), which kinda prove that this patch > doesn't change the behavior of __ptrace_may_access() by not using cred > in ptrace_has_cap(). It doesn't hurt and I think it could be useful to > spot issues when backporting. And it might require an extra fixup while backporting because the next line is different and that might cause the patch to not apply.