Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1112479rwp; Thu, 13 Jul 2023 06:23:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlHWwdljmEQBU6cHt7k9EA3j4szBL/BceiDlB1/k8F1f+PQFbufqfekE0KFjSmjYvUfCNQRN X-Received: by 2002:a17:907:c82:b0:991:b834:af83 with SMTP id gi2-20020a1709070c8200b00991b834af83mr1432555ejc.59.1689254611650; Thu, 13 Jul 2023 06:23:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689254611; cv=none; d=google.com; s=arc-20160816; b=usfXn4KFTike7Th7d0MNDojgHyO2i15bYywSigWHGAvo6WQmoSIsOZOuTFacqdpKvX MqycySmGaljNwnYxaCB6JpbjOYbgGzy24LopjAqLeFOMMXr4mPOWMlzkQs3Vkf7H5ltI P6Mfysxkq1w3HbFy7c+OjSwxeNl8Ve376nvn6t11aESsLka1AuX+qkTiOOjxxwJfsXTl ws0RqqeMbRnOAg4Dbcc4gPLC1E/SCtAgIhXl6+ogHcuMkP7QvzX4RJMozDzCSf4sglA0 mtjRKNy3nstcBwBZV/JeeZWtDfrKFgabG4s1ZfAXCg5kyo7UdfBZOcfXTbiLfaoEvZ1F FZ0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ug93bWe0zcbhACqTIsMdZiTop0+FC4D83XQxBvP1Tfc=; fh=+DQ6MuoaNGppMWvYCb7M3YLYBcyEEic4lWka+NVkUrQ=; b=rCfQRRO6TexKCqhC5FiLyJkOkrtSZZsI2NafBGxBqPvD1CdRAhNRU4Syl1m97MnLM0 mAXoEvliHVWzVV7viNggR7VnmtFcZrge74+iilYwDIyZ3YV4J058tdgCfQOrYtVxb3XV aXEKWBi/Iyl90D1SOENTRC4esOCMlJhTdcrAbxHxnPGG19s5ezemGxfTiuU3Dm+DxJLg f8QsIfpF6b2w+D+1q7/A3kh+QeMKn5NsCZQZ5MT4MqmEaxldz1Pmja11qgPtXHLaVPUP DgEJuz+jEVVxayPtchnYhqQVw54siQkv32jcnc4DCaaZFhSO/vYKkGNRud9v6ozpXPsY gEAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IyX8o5M4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n21-20020a170906b31500b009926703c4b9si6673421ejz.413.2023.07.13.06.23.07; Thu, 13 Jul 2023 06:23:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IyX8o5M4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233441AbjGMNVJ (ORCPT + 99 others); Thu, 13 Jul 2023 09:21:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234481AbjGMNUl (ORCPT ); Thu, 13 Jul 2023 09:20:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61830270A; Thu, 13 Jul 2023 06:20:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F2C7461077; Thu, 13 Jul 2023 13:20:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA113C433C8; Thu, 13 Jul 2023 13:20:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689254431; bh=/HyMH976r1TkXdXXLMFe5egKFttnbGRT4cnSU1IDGSE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IyX8o5M49S3zdzIxtruMjTRp3CoLKS1Rhzh8MHa3gYd3oaysfgiI9455gtBEoX6/h VbqM0gkLxd4eQvSWW7TISIVbalZNozQIlll8xozP/Mpus0rGu4PKXHlVyyOaDlD8Nm MLz+0GsLu/xdnFlvqHh5WF5qicq294o0Dn9/hQp3R3SN5d/FjQLuMIOEbYVwPvBGkV 3pZL3qgJ3VM0f7sHcfQmUY8ueP8p88W4jCtOqXictAbtRiKpiIxS6sBpv5C7XYkSe3 I03sippl4hiN2aJerdZ/8LQgvMnUA8TpzL9Fg6A61oDg35Njc6Ts11QAdJ1MBAVhhm G+bK9ll/f7X2A== Date: Thu, 13 Jul 2023 15:20:20 +0200 From: Christian Brauner To: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= Cc: Aleksa Sarai , Willy Tarreau , Shuah Khan , Andrew Morton , Dave Chinner , xu xin , Al Viro , Stefan Roesch , Zhihao Cheng , "Liam R. Howlett" , Janis Danisevskis , Kees Cook , stable@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH] procfs: block chmod on /proc/thread-self/comm Message-ID: <20230713-shrimps-sachkenntnis-0343cc776cc2@brauner> References: <20230713121907.9693-1-cyphar@cyphar.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 13, 2023 at 03:01:24PM +0200, Thomas Weißschuh wrote: > On 2023-07-13 22:19:04+1000, Aleksa Sarai wrote: > > Due to an oversight in commit 1b3044e39a89 ("procfs: fix pthread > > cross-thread naming if !PR_DUMPABLE") in switching from REG to NOD, > > chmod operations on /proc/thread-self/comm were no longer blocked as > > they are on almost all other procfs files. > > > > A very similar situation with /proc/self/environ was used to as a root > > exploit a long time ago, but procfs has SB_I_NOEXEC so this is simply a > > correctness issue. > > > > Ref: https://lwn.net/Articles/191954/ > > Ref: 6d76fa58b050 ("Don't allow chmod() on the /proc// files") > > Fixes: 1b3044e39a89 ("procfs: fix pthread cross-thread naming if !PR_DUMPABLE") > > Cc: stable@vger.kernel.org # v4.7+ > > Signed-off-by: Aleksa Sarai > > --- > > fs/proc/base.c | 3 ++- > > tools/testing/selftests/nolibc/nolibc-test.c | 4 ++++ > > 2 files changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/fs/proc/base.c b/fs/proc/base.c > > index 05452c3b9872..7394229816f3 100644 > > --- a/fs/proc/base.c > > +++ b/fs/proc/base.c > > @@ -3583,7 +3583,8 @@ static int proc_tid_comm_permission(struct mnt_idmap *idmap, > > } > > > > static const struct inode_operations proc_tid_comm_inode_operations = { > > - .permission = proc_tid_comm_permission, > > + .setattr = proc_setattr, > > + .permission = proc_tid_comm_permission, > > }; > > Given that this seems to be a recurring theme a more systematic > aproach would help. > > Something like the following (untested) patch: > > diff --git a/fs/proc/base.c b/fs/proc/base.c > index 05452c3b9872..b90f2e9cda66 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -2649,6 +2649,7 @@ static struct dentry *proc_pident_instantiate(struct dentry *dentry, > set_nlink(inode, 2); /* Use getattr to fix if necessary */ > if (p->iop) > inode->i_op = p->iop; > + WARN_ON(!inode->i_op->setattr); Hm, no. This is hacky. To fix this properly we will need to wean off notify_change() from falling back to simple_setattr() when no i_op->setattr() method is defined. To do that we will have to go through every filesystem and port all that rely on this fallback to set simple_setattr() explicitly as their i_op->setattr() method. Christoph and I just discussed this in relation to another patch. This is a bugfix so it should be as minimal as possible for easy backport.