From: sashiko-bot@kernel.org
To: "Krzysztof Wilczyński" <kwilczynski@kernel.org>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v2 2/3] kernfs: Unmap mmaps of removed files via file->f_mapping
Date: Sat, 25 Jul 2026 21:22:51 +0000 [thread overview]
Message-ID: <20260725212251.A4A291F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260725210549.3716546-3-kwilczynski@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] A TOCTOU race condition between mmap() and kernfs_drain_open_files() allows a newly created VMA to escape being zapped, leaving stale physical mappings accessible to user space after device removal.
--
--- Patch [2]: [PATCH v2 2/3] kernfs: Unmap mmaps of removed files via file->f_mapping ---
commit cbf76235c8b2fab1c84f41b35091ff343e6741ef
Author: Krzysztof Wilczyński <kwilczynski@kernel.org>
kernfs: Unmap mmaps of removed files via file->f_mapping
This commit replaces unmap_mapping_range() with unmap_mapping_file()
in kernfs_drain_open_files(). This ensures that only VMAs of the
removed node are zapped, preserving unrelated mappings for PCI resource
and legacy sysfs files that swap their f_mapping.
> diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
> index 8e0e90c933720..eb04439e9c3ec 100644
> --- a/fs/kernfs/file.c
> +++ b/fs/kernfs/file.c
> @@ -815,10 +815,8 @@ void kernfs_drain_open_files(struct kernfs_node *kn)
> }
>
> list_for_each_entry(of, &on->files, list) {
> - struct inode *inode = file_inode(of->file);
> -
> if (of->mmapped) {
> - unmap_mapping_range(inode->i_mapping, 0, 0, 1);
> + unmap_mapping_file(of->file);
[Severity: High]
This isn't a bug introduced by this patch, but can this race with the VMA
being linked into the interval tree?
If kernfs_fop_mmap() sets of->mmapped = true and drops the active reference,
it can wake up a concurrent kernfs_remove() thread waiting for active
references to drain.
If that thread calls kernfs_drain_open_files() and sees of->mmapped == true,
it will call unmap_mapping_file() here.
However, since kernfs_fop_mmap() hasn't yet returned to the core mm code
where vma_link_file() is called (like in __mmap_new_vma()), the VMA
might not be in the interval tree yet. Consequently, unmap_mapping_file()
could find nothing to zap, and the mmap syscall subsequently inserts the VMA,
leaving userspace with an active physical mapping to a removed device.
Could the synchronization between the mmap path and kernfs_drain_open_files()
be missing a mechanism to wait for the VMA to be fully linked?
> of->mmapped = false;
> on->nr_mmapped--;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260725210549.3716546-1-kwilczynski@kernel.org?part=2
next prev parent reply other threads:[~2026-07-25 21:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-25 21:05 [PATCH v2 0/3] mm,kernfs,proc: Unmap mmaps of removed files via file->f_mapping Krzysztof Wilczyński
2026-07-25 21:05 ` [PATCH v2 1/3] mm: Add unmap_mapping_file() helper Krzysztof Wilczyński
2026-07-25 21:35 ` sashiko-bot
2026-07-25 21:05 ` [PATCH v2 2/3] kernfs: Unmap mmaps of removed files via file->f_mapping Krzysztof Wilczyński
2026-07-25 21:22 ` sashiko-bot [this message]
2026-07-25 21:05 ` [PATCH v2 3/3] proc: " Krzysztof Wilczyński
2026-07-25 21:19 ` sashiko-bot
2026-07-25 21:37 ` [PATCH v2 0/3] mm,kernfs,proc: " Andrew Morton
2026-07-26 1:22 ` Krzysztof Wilczyński
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=20260725212251.A4A291F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=linux-pci@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.