Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1077734rwp; Thu, 13 Jul 2023 05:59:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlH9+nIvFikC+b8cPISTgLX/G/881qk91rCbSSUVTseDE09y+/ijszNs6kpiqcX/frWeB2gt X-Received: by 2002:a05:6a00:14c6:b0:682:7d8a:f887 with SMTP id w6-20020a056a0014c600b006827d8af887mr1107441pfu.30.1689253192695; Thu, 13 Jul 2023 05:59:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689253192; cv=none; d=google.com; s=arc-20160816; b=k21n6Vo5qR8P2+x6vh9Z5xJejnCmYPieGNGdz9ES6LykoafneOncnZ7F8gAqWH2e2S WREBK0Wx0EAePIcfl91eEr4TWAekxtzsF0iZomOsTnT+VZOoZTilBs2Roh6giBcX01OB 9Y1Um8rrNyOGWmzLN31GsIhkL79xR7AbX/UrzkXmxITp0vaaARJWdR04+13OOYNYJmAU xk/fp/lQ4BanNG/abXrvPXmsOpBoLKHlWvAEaI0U6McS6OvgBCh+cufl47EPBMxHkn/N 0kD6Qf01CPd/XwLQ7dGeusPlNXU5VFaI5SGK2kMgfqIqAU69Ghad1BahrJYp7nXwobHv lzFA== 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; bh=1i1jODXg7cwBRUb7pj6BKnHX01zJkF8EktLR9n4noE0=; fh=uSQ0A2OdNuRGQPXvCPz4Sm5aYrzGbX0WDABFgLspW9I=; b=oDrKOkYNhgH8KjiPFV5HMLwkoljBWh9DAE9tMK+pM54m3a/wp4Z8vS9dYKUyTv9Z/D UOswWvKVZgRTpKkDYLHyDcrFJ1DFQLs9c52eW0FNWcuzWD7PVqbJYJMHF6gKvIpukx8+ LLsB9Yqvr1NGFRALplul0McDp0Oqbw9XkaUBWTt5FhUO7pgMYia2kPRqwxiVxik20v0e 3kKx2CuL0yI/Tb0aAH6jAtB2uoxf7PpImy0w0uNLbMoo9yiqIuKN9N21kVgPBON3rL/9 uVikafF1N8yha0Xc8bsYCkCyflgFmXUjz2KPdM73Zg3IPckEZh6/VB8EKHKyR5VOcCb0 /U9A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q22-20020a056a00151600b0068291627221si5285407pfu.15.2023.07.13.05.59.40; Thu, 13 Jul 2023 05:59:52 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234695AbjGMMiU (ORCPT + 99 others); Thu, 13 Jul 2023 08:38:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbjGMMiT (ORCPT ); Thu, 13 Jul 2023 08:38:19 -0400 X-Greylist: delayed 101 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 13 Jul 2023 05:38:17 PDT Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D1FC213C; Thu, 13 Jul 2023 05:38:17 -0700 (PDT) Received: (from willy@localhost) by mail.home.local (8.17.1/8.17.1/Submit) id 36DCZRRM027222; Thu, 13 Jul 2023 14:35:27 +0200 Date: Thu, 13 Jul 2023 14:35:27 +0200 From: Willy Tarreau To: Aleksa Sarai Cc: Shuah Khan , Andrew Morton , Christian Brauner , 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, Thomas =?iso-8859-1?Q?Wei=DFschuh?= Subject: Re: [PATCH] procfs: block chmod on /proc/thread-self/comm Message-ID: References: <20230713121907.9693-1-cyphar@cyphar.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230713121907.9693-1-cyphar@cyphar.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,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 +Cc Thomas Wei?schuh as this seems quite related to his finding about /proc/self/net: https://lore.kernel.org/lkml/20230624-proc-net-setattr-v1-0-73176812adee@weissschuh.net/#b On Thu, Jul 13, 2023 at 10:19:04PM +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, > }; > > /* > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c > index 486334981e60..08f0969208eb 100644 > --- a/tools/testing/selftests/nolibc/nolibc-test.c > +++ b/tools/testing/selftests/nolibc/nolibc-test.c > @@ -580,6 +580,10 @@ int run_syscall(int min, int max) > CASE_TEST(chmod_net); EXPECT_SYSZR(proc, chmod("/proc/self/net", 0555)); break; > CASE_TEST(chmod_self); EXPECT_SYSER(proc, chmod("/proc/self", 0555), -1, EPERM); break; > CASE_TEST(chown_self); EXPECT_SYSER(proc, chown("/proc/self", 0, 0), -1, EPERM); break; > + CASE_TEST(chmod_self_comm); EXPECT_SYSER(proc, chmod("/proc/self/comm", 0777), -1, EPERM); break; > + CASE_TEST(chmod_tid_comm); EXPECT_SYSER(proc, chmod("/proc/thread-self/comm", 0777), -1, EPERM); break; > + CASE_TEST(chmod_self_environ);EXPECT_SYSER(proc, chmod("/proc/self/environ", 0777), -1, EPERM); break; > + CASE_TEST(chmod_tid_environ); EXPECT_SYSER(proc, chmod("/proc/thread-self/environ", 0777), -1, EPERM); break; > CASE_TEST(chroot_root); EXPECT_SYSZR(euid0, chroot("/")); break; > CASE_TEST(chroot_blah); EXPECT_SYSER(1, chroot("/proc/self/blah"), -1, ENOENT); break; > CASE_TEST(chroot_exe); EXPECT_SYSER(proc, chroot("/proc/self/exe"), -1, ENOTDIR); break; > -- > 2.41.0