From patchwork Thu Jul 13 14:09:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksa Sarai X-Patchwork-Id: 13312263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE7A2C001DD for ; Thu, 13 Jul 2023 14:10:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234344AbjGMOKm (ORCPT ); Thu, 13 Jul 2023 10:10:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232568AbjGMOKk (ORCPT ); Thu, 13 Jul 2023 10:10:40 -0400 X-Greylist: delayed 4442 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 13 Jul 2023 07:10:39 PDT Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B8B6212D; Thu, 13 Jul 2023 07:10:39 -0700 (PDT) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4R1xMw0SSlz9sRm; Thu, 13 Jul 2023 16:10:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cyphar.com; s=MBO0001; t=1689257436; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=DsJX/tFpbTwtQ2LSeMQrzi9/53b88Qdy1opjeZwYFME=; b=LgbtBXv50U/WMflAcuUJfocHrynxphke7hl5cwiqpeOPrJIN49aI0t3xCmzdx6NFv6CFIv b/P0NDXnaWETV00yq6QxV4DkZR+Yh1kZuLx4L8og/bxJ4S+mxJYAfpIB4SuvCAjKBWmNKf 87urlpwu7g3GpG8hDcrCtOD0BoAFBJ+ksUfUbINpqvtLX14kRqWnjkygwxup85wVgWpIS8 ft8FwM6lCVVF6gZfpjZeC6V4Mc19VCxvwSm1MvZ50K+XjAYx/El9FiT4M2Yc/SJDOp/SLe WUZZMu2YXRjZKZIXXG/NvEpcp55H23dT6b1xfW28rjq8poauQhKlXhoasgVhvg== From: Aleksa Sarai To: Christian Brauner , Andrew Morton , Dave Chinner , xu xin , Al Viro , "Liam R. Howlett" , Zhihao Cheng , Stefan Roesch , Janis Danisevskis , Kees Cook Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Aleksa Sarai , stable@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v2] procfs: block chmod on /proc/thread-self/comm Date: Fri, 14 Jul 2023 00:09:58 +1000 Message-ID: <20230713141001.27046-1-cyphar@cyphar.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4R1xMw0SSlz9sRm Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 --- v2: removed nolibc selftests as per review v1: --- fs/proc/base.c | 3 ++- 1 file changed, 2 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, }; /*