From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D06936070F19 for ; Wed, 4 Nov 2026 19:25:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=3jNjgl5M; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AOGtv8Mf DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=x8nH5QJkKiZNUTowDxB/hMOFyVkHqFnuwosL7qreMAM=; b=3jNjgl5MDscVp/ CrgtaMJBaOZwupPiJbVGt/UNSh6dwCmK3xXAYSslxUPG4c0Beuv8ap03NScc8zZp6FIP5AzhYoPBD x/nbvhNHOiPjbXFiP7ZFPJfve3C/P5hyKJ7sU0NjLIAc3GcSaS8IBhlNwyijx0KUF60ZAcr+m0+Ci frSHJ549YIfGlh2clIPHFfbJ1rRhjx9In8QVUgDK7pqk8GgULhpaNqbqOt72fhUX/ZGr3YSjyOciS SIu8nWNE80Lgi7lGqDNygITMzA/ib+9lHShmjgQlQGSch2skNMqF2u59CAGzBZ26JMLHqg9a94Djc h2ssytpU22eg/3ENUl1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xOgbY-00000006b0g-2Lki; Wed, 04 Nov 2026 19:25:04 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xOgbW-00000006b0G-2aUs; Wed, 04 Nov 2026 19:25:02 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 5F12341256; Wed, 4 Nov 2026 19:25:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A96E1F0093A; Wed, 4 Nov 2026 19:24:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793820302; bh=x8nH5QJkKiZNUTowDxB/hMOFyVkHqFnuwosL7qreMAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AOGtv8MfSvpV7/N3SPQdxO34HN0jitae0lUNpVEJDAU9XLw0mdF8nEKatSbYah4D4 pJnFyEpZO1zbMa9uji/9OWzr8wEr6lfii12mf0iU2Lh2VjsLavJMVeCqDZp/52sjZ8 3Go4KV6nkkS39oFoJGSvgQnMVnncUKXYL8Mx162m4aQQqRHIlpeUtyYZQRcyHTHG+m F6SJS7Gx3owS0zf+1GA3KxpXJd3wQWd0E3FPh1GuNLid6UQ0pR28EaGxERe/wN3pMg +vSX7Zm5D1718tOrlyhaV4OrQ07V2BymOcNC4cPME/yryrTT1k2SVGUu6wuwzfR22j +9kSochp+NapA== From: Christian Brauner To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Jann Horn , Josef Bacik , Chris Mason , Jeff Layton , NeilBrown , Eric Dumazet , Thomas Gleixner , Al Viro , Jonathan Corbet , Christoph Hellwig , Greg Kroah-Hartman , Joel Granados , Kees Cook , Jan Kara , Jan Kara , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-um@lists.infradead.org, linux-wireless@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org, ntfs3@lists.linux.dev, platform-driver-x86@vger.kernel.org, coreteam@netfilter.org, kexec@lists.infradead.org, linux-pci@vger.kernel.org, linux-sound@vger.kernel.org, netfilter-devel@vger.kernel.org, dri-devel@lists.freedesktop.org, ibm-acpi-devel@lists.sourceforge.net, jfs-discussion@lists.sourceforge.net, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-cifs@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-mm@kvack.org, linux-sh@vger.kernel.org, linux-usb@vger.kernel.org, samba-technical@lists.samba.org, sparclinux@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-doc@vger.kernel.org, linux-serial@vger.kernel.org, linux-atm-general@lists.sourceforge.net, Takashi Iwai , linux-input@vger.kernel.org, linux-raid@vger.kernel.org, linux-ext4@vger.kernel.org, linux-modules@vger.kernel.org, linux-debuggers@vger.kernel.org, "Christian Brauner (Amutable)" , Chuck Lever , stable@vger.kernel.org Subject: [PATCH RESEND v2 36/51] proc: don't let NOMMU map procfs files Date: Wed, 4 Nov 2026 20:24:48 +0100 Message-ID: <20261104-work-procfs-bugfixes-v2-36-021c84d852e0@kernel.org> In-Reply-To: <20261104-work-procfs-bugfixes-v2-0-021c84d852e0@kernel.org> References: <20261104-work-procfs-bugfixes-v2-0-021c84d852e0@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3847; i=brauner@kernel.org; h=from:subject:message-id; bh=JTUUxaAv8g+OiylD/jB4kSfUdacg86Bjtrwx1fOwQ90=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWS9bvzxcvsOxp23JLZfCWya6MPaPHGnRYPLhkVvf4fHB W9U5hb431HKwiDGxSArpsji0G4SLrecp2KzUaYGzBxWJpAhDFycAjCRyk+MDK+PBU/le8dv0ftD 839XV15oaNPWrTw8hs1fHTLi/wid+Mbwv6CPOeDfzSePDj+a/VD2SORxlTWdy84uUOARvTIlTdD JgRcA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Content-Transfer-Encoding: 8bit X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Every procfs file has a ->mmap since commit 786d7e1612f0 ("Fix rmmod/read/write races in /proc entries"), whether the entry has a ->proc_mmap or not. On NOMMU validate_mmap_request() takes that to mean the file can be mapped. procfs has no ->mmap_capabilities so a regular file gets NOMMU_MAP_COPY, and a private mapping never calls ->mmap at all. Instead do_mmap() takes nommu_region_sem for writing and do_mmap_private() reads the file into the copy with kernel_read(). Reading /proc/maps takes nommu_region_sem as well: mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, open("/proc/maps", O_RDONLY), 0) do_mmap() // down_write(&nommu_region_sem) -> do_mmap_private() -> kernel_read() -> seq_read_iter() -> nommu_region_list_start() // down_read() The task hangs for good, holding nommu_region_sem and its own mmap_lock, and every mmap(), munmap() and exit after that hangs behind it. /proc/maps is 0444 so any user can do that. Give the procfs files a ->mmap_capabilities on NOMMU that allows nothing. That covers every entry and not just /proc/maps, procfs can't know which entry's read takes nommu_region_sem. Mapping a procfs file then fails with -ENODEV, like mapping a file without ->mmap did before 786d7e1612f0. NOMMU never called ->proc_mmap() for a regular file anyway, procfs never offered NOMMU_MAP_DIRECT. Reported-by: Chris Mason Fixes: 786d7e1612f0 ("Fix rmmod/read/write races in /proc entries") Cc: stable@vger.kernel.org Signed-off-by: Christian Brauner (Amutable) --- fs/proc/inode.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/fs/proc/inode.c b/fs/proc/inode.c index b7634f975d98..9933f03ab9fb 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -466,6 +466,18 @@ proc_reg_get_unmapped_area(struct file *file, unsigned long orig_addr, return rv; } +#ifndef CONFIG_MMU +/* + * NOMMU never calls ->proc_mmap() for a regular file. It reads the file into + * a private copy instead, with nommu_region_sem held for writing, which + * reading /proc/maps takes as well. Don't map procfs files at all. + */ +static unsigned int proc_reg_mmap_capabilities(struct file *file) +{ + return 0; +} +#endif + static int proc_reg_open(struct inode *inode, struct file *file) { struct proc_dir_entry *pde = PDE(inode); @@ -559,6 +571,9 @@ static const struct file_operations proc_reg_file_ops = { .unlocked_ioctl = proc_reg_unlocked_ioctl, .mmap = proc_reg_mmap, .get_unmapped_area = proc_reg_get_unmapped_area, +#ifndef CONFIG_MMU + .mmap_capabilities = proc_reg_mmap_capabilities, +#endif .open = proc_reg_open, .release = proc_reg_release, }; @@ -572,6 +587,9 @@ static const struct file_operations proc_iter_file_ops = { .unlocked_ioctl = proc_reg_unlocked_ioctl, .mmap = proc_reg_mmap, .get_unmapped_area = proc_reg_get_unmapped_area, +#ifndef CONFIG_MMU + .mmap_capabilities = proc_reg_mmap_capabilities, +#endif .open = proc_reg_open, .release = proc_reg_release, }; @@ -586,6 +604,9 @@ static const struct file_operations proc_reg_file_ops_compat = { .compat_ioctl = proc_reg_compat_ioctl, .mmap = proc_reg_mmap, .get_unmapped_area = proc_reg_get_unmapped_area, +#ifndef CONFIG_MMU + .mmap_capabilities = proc_reg_mmap_capabilities, +#endif .open = proc_reg_open, .release = proc_reg_release, }; @@ -600,6 +621,9 @@ static const struct file_operations proc_iter_file_ops_compat = { .compat_ioctl = proc_reg_compat_ioctl, .mmap = proc_reg_mmap, .get_unmapped_area = proc_reg_get_unmapped_area, +#ifndef CONFIG_MMU + .mmap_capabilities = proc_reg_mmap_capabilities, +#endif .open = proc_reg_open, .release = proc_reg_release, }; -- 2.53.0