Skip to contentSkip to conversation

shmem: consume the reserved xattr space despite remount

PATCH Applied Andrew Morton 3 participants 3 messages Nov 18 – Nov 19

Subsystems (3)
lore
Share & tools
lore

Andrew Morton

author maintainer
#0 lore raw

PATCH 1/1 shmem: consume the reserved xattr space despite remount

From: Andrew Morton <[email protected]>
Subject: shmem: consume the reserved xattr space despite remount
Date: Thu, 05 Nov 2026 08:08:06 -0800

Creating a tmpfs inode can trigger WARN_ON(ispace) in shmem_initxattrs() when a concurrent remount sets nr_inodes=0. With panic_on_warn enabled, this warning can panic the machine.

shmem_initxattrs() reserves space for the security xattrs while inode limits are enabled. It later tests max_inodes again before consuming that reservation for each installed xattr. If remount disables the limit between those steps, successfully installed xattrs leave a nonzero reservation behind.

Use the remaining reservation, rather than the current mount policy, to decide whether to subtract the installed xattr's space. This also leaves the failure path with only the unconsumed reservation to refund.

An initially unlimited filesystem cannot acquire an inode limit through
remount: shmem_reconfigure() rejects that transition.

Fixes 076e5cef28e2 ("simple_xattr: change interface to pass struct simple_xattrs")
Cc Hugh Dickins <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Miklos Szeredi <[email protected]>
Cc Christian Brauner <[email protected]>

---
Reproduced the warning before the fix and verified its absence afterward in a Debian 13 guest with SELinux enabled (permissive).

A temporary hook paused file creation after reserving security-xattr space. Another process completed a real nr_inodes=0 remount before creation resumed. The unpatched kernel left 94 bytes unconsumed and triggered WARN_ON(ispace); the patched kernel consumed the reservation completely. File contents and the security xattr were verified.

Ordinary creation on limited and unlimited tmpfs mounts also passed on both kernels. No additional KASAN or lockdep reports occurred.

Tested Linux 7.4.0-rc1 with GCC 13.3, KASAN and lockdep, using KVM:
8 GiB RAM, four vCPUs and one virtual NUMA node, backed by a Threadripper PRO 3995WX. Both kernels had the same diagnostic hook; the ordering was forced rather than left to random stress.

 mm/shmem.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/shmem.c renamed from mm/shmem.c~shmem-consume-the-reserved-xattr-space-despite-remount +1 -1
@@ -4491,7 +4491,7 @@ static int shmem_initxattrs(struct inode
 		if (simple_xattr_add(&sbinfo->xa_cache, &info->xattrs, new_xattr))
 			break;
 
-		if (sbinfo->max_inodes)
+		if (ispace)
 			ispace -= simple_xattr_space(new_xattr->name, new_xattr->size);
 		retain_and_null_ptr(new_xattr);
 	}

_

maintainer Applied
#1 lore raw
Quoted 11 lines · Andrew Morton

Creating a tmpfs inode can trigger WARN_ON(ispace) in shmem_initxattrs() when a concurrent remount sets nr_inodes=0. With panic_on_warn enabled, this warning can panic the machine.

shmem_initxattrs() reserves space for the security xattrs while inode limits are enabled. It later tests max_inodes again before consuming that reservation for each installed xattr. If remount disables the limit between those steps, successfully installed xattrs leave a nonzero reservation behind.

[...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] shmem: consume the reserved xattr space despite remount

      https://git.kernel.org/vfs/vfs/c/274ae8ab278e
#2 lore raw
In reply to Andrew Morton
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] shmem: Fixes trailer subject omits trailing pointer asterisks --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] shmem: Fixes trailer subject omits trailing pointer asterisks --

commit 2c1ee388f6f3d6454e93c257214769e6a996663f
Author: Andrew Morton <[email protected]>

Quoted 19 lines

shmem: consume the reserved xattr space despite remount

Creating a tmpfs inode can trigger WARN_ON(ispace) in shmem_initxattrs() when a concurrent remount sets nr_inodes=0. With panic_on_warn enabled, this warning can panic the machine.

shmem_initxattrs() reserves space for the security xattrs while inode limits are enabled. It later tests max_inodes again before consuming that reservation for each installed xattr. If remount disables the limit between those steps, successfully installed xattrs leave a nonzero reservation behind.

Use the remaining reservation, rather than the current mount policy, to decide whether to subtract the installed xattr's space. This also leaves the failure path with only the unconsumed reservation to refund.

An initially unlimited filesystem cannot acquire an inode limit through
remount: shmem_reconfigure() rejects that transition.

Quoted 10 lines
Fixes 076e5cef28e2 ("simple_xattr: change interface to pass struct simple_xattrs")
Cc Hugh Dickins <[email protected]>
Cc Baolin Wang <[email protected]>
Cc Miklos Szeredi <[email protected]>
Cc Christian Brauner <[email protected]>

[Severity: Low]
The subject in the Fixes: tag is missing the trailing " **" from commit 076e5cef28e2 ("simple_xattr: change interface to pass struct simple_xattrs **"). Should this be:

Fixes 076e5cef28e2 ("simple_xattr: change interface to pass struct simple_xattrs **")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1