From: sashiko-bot@kernel.org
To: "Ackerley Tng" <ackerleytng@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH RFC 01/17] mm: shmem: Implement guest_memfd provider operations for tmpfs
Date: Sat, 26 Sep 2026 01:08:27 +0000 [thread overview]
Message-ID: <20260926010828.699111F008A1@smtp.kernel.org> (raw)
In-Reply-To: <20260925-gmem-tmpfs-backend-v1-1-d36159822d18@google.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] mm: guest_memfd bypasses tmpfs disk quotas and overcommit limits
- [High] mm: guest_memfd zone contamination via GFP_HIGHUSER_MOVABLE
- [Medium] fs: missing mnt_want_write() causes TOCTOU race with read-only remounts
--
commit aa746f432476f1dcdc507ac315f4952fd2b53724
Author: Ackerley Tng <ackerleytng@google.com>
mm: shmem: Implement guest_memfd provider operations for tmpfs
Implement guest_memfd provider operations to declare that tmpfs supports
providing memory to guest_memfd.
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 897fa2b61346f..279f29a9861c1 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
[ ... ]
> @@ -5234,6 +5235,114 @@ static const struct inode_operations shmem_special_inode_operations = {
> #endif
> };
>
> +#ifdef CONFIG_KVM_GUEST_MEMFD
> +static void *shmem_gmem_attach(struct file *resource_file)
> +{
[ ... ]
> + if (__mnt_is_readonly(resource_file->f_path.mnt))
> + return ERR_PTR(-EROFS);
[Severity: Medium]
Does this check adequately protect against concurrent remounts?
shmem_gmem_attach() checks __mnt_is_readonly() without holding
mnt_want_write() or acquiring a VFS write reference. The mount could become
read-only immediately after this check, but guest_memfd would continue
allocating from it.
[ ... ]
> +static struct folio *shmem_gmem_alloc_folio(void *provider, pgoff_t index,
> + struct mempolicy *mpol)
> +{
> + struct mempolicy *sb_mpol = NULL;
> + struct vfsmount *mnt = provider;
> + struct shmem_sb_info *sbinfo;
> + struct folio *folio;
> +
> + sbinfo = SHMEM_SB(mnt->mnt_sb);
> + if (sbinfo->max_blocks &&
> + !percpu_counter_limited_add(&sbinfo->used_blocks,
> + sbinfo->max_blocks, 1))
> + return ERR_PTR(-ENOSPC);
[Severity: High]
Does this logic bypass tmpfs user/group disk quotas and VM overcommit limits?
While the global block limit is checked and charged here, it skips
both shmem_acct_blocks() (for VM overcommit) and dquot_alloc_block_nodirty()
(for inode disk quotas). Could an unprivileged user with write access to a
tmpfs mount evade limits and consume unbounded space?
> +
> + if (!mpol) {
> + sb_mpol = shmem_get_sbmpol(sbinfo);
> + mpol = sb_mpol;
> + }
> +
> + if (mpol)
> + folio = folio_alloc_mpol(GFP_HIGHUSER_MOVABLE, 0, mpol, index,
> + numa_node_id());
> + else
> + folio = folio_alloc(GFP_HIGHUSER_MOVABLE, 0);
[Severity: High]
Can placing unmovable guest_memfd pages into movable zones cause memory
fragmentation?
shmem_gmem_alloc_folio() allocates folios with the GFP_HIGHUSER_MOVABLE
flag. The __GFP_MOVABLE flag tells the allocator these pages can be migrated
or evicted, but guest_memfd pages are strictly unmovable. Does this break
memory management invariants and potentially cause large-order allocation or
memory hot-remove failures?
> +
> + mpol_cond_put(sb_mpol);
[Severity: Medium]
This is a pre-existing issue, but does mpol_cond_put() leak the policy
reference count here?
shmem_get_sbmpol() returns a policy with an incremented refcount. However,
mpol_cond_put() only drops the reference if the MPOL_F_SHARED flag is set.
Since the superblock policy does not have MPOL_F_SHARED set, this operation
is a no-op, which appears to leak the policy reference.
> +
> + if (!folio) {
> + if (sbinfo->max_blocks)
> + percpu_counter_sub(&sbinfo->used_blocks, 1);
> + return ERR_PTR(-ENOMEM);
> + }
> +
> + return folio;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260925-gmem-tmpfs-backend-v1-0-d36159822d18@google.com?part=1
next prev parent reply other threads:[~2026-09-26 1:08 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 0:50 [PATCH RFC 00/17] Allow guest_memfd to be created using a resource (pool) fd Ackerley Tng via B4 Relay
2026-09-26 0:50 ` [PATCH RFC 01/17] mm: shmem: Implement guest_memfd provider operations for tmpfs Ackerley Tng via B4 Relay
2026-09-26 1:08 ` sashiko-bot [this message]
2026-10-01 13:07 ` David Woodhouse
2026-10-01 14:17 ` Jason Gunthorpe
2026-10-01 15:47 ` David Woodhouse
2026-10-01 17:15 ` Jason Gunthorpe
2026-09-26 0:50 ` [PATCH RFC 02/17] KVM: guest_memfd: Support provider folio allocation Ackerley Tng via B4 Relay
2026-09-26 1:00 ` sashiko-bot
2026-09-26 0:50 ` [PATCH RFC 03/17] KVM: guest_memfd: Support provider folio invalidation Ackerley Tng via B4 Relay
2026-09-26 0:50 ` [PATCH RFC 04/17] KVM: guest_memfd: Add helper to attach resource provider file Ackerley Tng via B4 Relay
2026-09-26 1:13 ` sashiko-bot
2026-09-26 0:50 ` [PATCH RFC 05/17] KVM: selftests: Add helper to create guest_memfd with a resource file Ackerley Tng via B4 Relay
2026-09-26 1:00 ` sashiko-bot
2026-09-26 0:50 ` [PATCH RFC 06/17] KVM: selftests: Test negative validation of resource_fd argument Ackerley Tng via B4 Relay
2026-09-26 1:01 ` sashiko-bot
2026-09-26 0:50 ` [PATCH RFC 07/17] KVM: selftests: Test rejection of unsupported filesystem for resource_fd Ackerley Tng via B4 Relay
2026-09-26 0:56 ` sashiko-bot
2026-09-26 0:50 ` [PATCH RFC 08/17] KVM: selftests: Test rejection of tmpfs file " Ackerley Tng via B4 Relay
2026-09-26 0:50 ` [PATCH RFC 09/17] KVM: selftests: Test rejection of swap tmpfs mounts Ackerley Tng via B4 Relay
2026-09-26 0:57 ` sashiko-bot
2026-09-26 0:50 ` [PATCH RFC 10/17] KVM: selftests: Test rejection of hugepage " Ackerley Tng via B4 Relay
2026-09-26 0:58 ` sashiko-bot
2026-09-26 0:50 ` [PATCH RFC 11/17] KVM: selftests: Test guest_memfd with anonymous fsmount() tmpfs pool Ackerley Tng via B4 Relay
2026-09-26 1:02 ` sashiko-bot
2026-09-26 0:50 ` [PATCH RFC 12/17] KVM: selftests: Test guest_memfd with mounted tmpfs root directory Ackerley Tng via B4 Relay
2026-09-26 1:01 ` sashiko-bot
2026-09-26 0:51 ` [PATCH RFC 13/17] KVM: selftests: Test guest_memfd resource pool sharing across instances Ackerley Tng via B4 Relay
2026-09-26 0:51 ` [PATCH RFC 14/17] KVM: selftests: Test memory allocation against shared tmpfs resource pool Ackerley Tng via B4 Relay
2026-09-26 0:51 ` [PATCH RFC 15/17] KVM: selftests: Test that shared tmpfs resource pool size limit is respected Ackerley Tng via B4 Relay
2026-09-26 0:51 ` [PATCH RFC 16/17] KVM: selftests: Test guest execution with tmpfs-backed guest_memfd Ackerley Tng via B4 Relay
2026-09-26 1:07 ` sashiko-bot
2026-09-26 0:51 ` [PATCH RFC 17/17] KVM: selftests: Document testing TODOs Ackerley Tng via B4 Relay
2026-09-28 16:32 ` [PATCH RFC 00/17] Allow guest_memfd to be created using a resource (pool) fd David Woodhouse
2026-09-28 22:59 ` Ackerley Tng
2026-09-29 16:17 ` David Woodhouse
2026-09-29 23:41 ` Ackerley Tng
2026-09-30 0:08 ` David Woodhouse
2026-10-01 13:43 ` Gregory Price
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260926010828.699111F008A1@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ackerleytng@google.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).