From: sashiko-bot@kernel.org
To: "David Howells" <dhowells@redhat.com>
Cc: v9fs@lists.linux.dev, "Chuck Lever" <cel@kernel.org>,
"Jeff Layton" <jlayton@kernel.org>,
"Anna Schumaker" <anna@kernel.org>
Subject: Re: [PATCH v17 11/17] afs: Use a bvecq to hold dir content rather than folioq
Date: Thu, 12 Nov 2026 00:06:51 +0000 [thread overview]
Message-ID: <sashiko-outbox-209883@kernel.org> (raw)
In-Reply-To: <20261111203034.2126314-12-dhowells@redhat.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] afs: TOCTOU race checking AFS_VNODE_DIR_VALID in
afs_dir_writepages()
--
commit 6db299c57b12dc739490b1b98b5287a7b4f00825
Author: David Howells <dhowells@redhat.com>
afs: Use a bvecq to hold dir content rather than folioq
This commit replaces folio_queue buffers with bvecq buffers for AFS
directories and symlinks, and snapshots the directory size, inode size, and
bvecq buffer under cb_lock during directory writeback.
Link: https://sashiko.dev/#/patchset/20261107160823.1465553-1-dhowells%40redhat.com
> diff --git a/fs/afs/dir.c b/fs/afs/dir.c
> index 51c158d8f723f..9cefd90fd4f8b 100644
> --- a/fs/afs/dir.c
> +++ b/fs/afs/dir.c
[ ... ]
> @@ -2220,6 +2220,7 @@ static int afs_dir_writepages(struct address_space *mapping,
> struct writeback_control *wbc)
> {
> struct afs_vnode *dvnode = AFS_FS_I(mapping->host);
> + struct bvecq *directory = NULL;
> struct iov_iter iter;
> int ret = 0;
>
> @@ -2236,14 +2237,21 @@ static int afs_dir_writepages(struct address_space *mapping,
> }
>
> if (test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags)) {
> - iov_iter_folio_queue(&iter, ITER_SOURCE, dvnode->directory,
> - 0, 0, dvnode->directory_size);
> - ret = netfs_writeback_single(mapping, wbc, &iter,
> - i_size_read(&dvnode->netfs.inode));
> + size_t i_size, d_size;
> +
> + read_seqlock_excl(&dvnode->cb_lock);
> + i_size = i_size_read(&dvnode->netfs.inode);
> + d_size = dvnode->directory_size;
> + directory = bvecq_get(dvnode->directory);
> + read_sequnlock_excl(&dvnode->cb_lock);
> +
> + iov_iter_bvec_queue(&iter, ITER_SOURCE, directory, 0, 0, d_size);
> + ret = netfs_writeback_single(mapping, wbc, &iter, i_size);
> if (ret == 1)
> ret = 0; /* Skipped write due to lock conflict. */
> }
[Severity: Medium]
Can afs_dir_writepages() still read a new i_size paired with an old
directory_size if a third-party status update races between the
AFS_VNODE_DIR_VALID check and read_seqlock_excl(&dvnode->cb_lock)?
CPU0 CPU1
afs_dir_writepages()
down_read(&dvnode->validate_lock)
test_bit(AFS_VNODE_DIR_VALID, ...)
afs_vnode_commit_status()
write_seqlock(&dvnode->cb_lock)
afs_apply_status()
afs_invalidate_dir()
clear_bit(AFS_VNODE_DIR_VALID, ...)
netfs_write_sizes()
i_size_write(..., status->size)
write_sequnlock(&dvnode->cb_lock)
read_seqlock_excl(&dvnode->cb_lock)
i_size = i_size_read(...)
d_size = dvnode->directory_size
read_sequnlock_excl(&dvnode->cb_lock)
netfs_writeback_single(..., i_size)
WARN_ON_ONCE(iov_iter_count(iter) < len) <-- i_size > d_size
When afs_apply_status() processes a third-party directory change under
cb_lock without holding validate_lock, it clears AFS_VNODE_DIR_VALID and
updates inode->i_size to the new server size, while leaving
dvnode->directory_size and dvnode->directory unchanged until the directory
is later re-read. If the directory grew on the server beyond d_size,
netfs_writeback_single() hits WARN_ON_ONCE(iov_iter_count(iter) < len) and
fails with -EIO; otherwise it writes the invalidated buffer with the new
i_size to the cache.
Re-checking AFS_VNODE_DIR_VALID inside the cb_lock critical section would
ensure i_size and directory_size come from a valid, consistent state.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111203034.2126314-1-dhowells@redhat.com?part=11
next prev parent reply other threads:[~2026-11-12 0:06 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 20:30 [PATCH v17 00/17] netfs, iov_iter: Use a chain of bio_vec arrays instead of folio_queue David Howells
2026-11-11 20:30 ` [PATCH v17 01/17] iov_iter: Fix kunit test to remove __init and __refdata marks David Howells
2026-11-11 21:23 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 02/17] Add a function to kmap one page of a multipage bio_vec David Howells
2026-11-11 21:26 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 03/17] iov_iter: Add a segmented queue of bio_vec[] David Howells
2026-11-11 21:46 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 04/17] netfs: Add some tools for managing bvecq chains David Howells
2026-11-11 22:17 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 05/17] iov_iter: Add an API document for the bvecq structure David Howells
2026-11-11 22:22 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 06/17] iov_iter: Add a bvecq kunit test David Howells
2026-11-11 22:31 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 07/17] afs: Fix an inconsistency in the symlink code David Howells
2026-11-11 22:45 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 08/17] netfs: Explicitly pass tail padding to netfs_writeback_single() David Howells
2026-11-11 23:17 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 09/17] netfs: Change netfs_writeback_single() to not look inside the iterator David Howells
2026-11-11 23:36 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 10/17] netfs: Pass the write length to request creation where appropriate David Howells
2026-11-11 23:39 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 11/17] afs: Use a bvecq to hold dir content rather than folioq David Howells
2026-11-12 0:06 ` sashiko-bot [this message]
2026-11-11 20:30 ` [PATCH v17 12/17] cifs: Use a bvecq for buffering instead of a folioq David Howells
2026-11-12 0:20 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 13/17] smbdirect: Support ITER_BVECQ in smbdirect_map_sges_from_iter() David Howells
2026-11-12 0:27 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 14/17] netfs: Switch folioq to bvecq David Howells
2026-11-12 1:03 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 15/17] smbdirect: Remove support for ITER_FOLIOQ from smbdirect_map_sges_from_iter() David Howells
2026-11-12 1:06 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 16/17] iov_iter: Remove ITER_FOLIOQ David Howells
2026-11-12 1:11 ` sashiko-bot
2026-11-11 20:30 ` [PATCH v17 17/17] netfs: Remove folio_queue David Howells
2026-11-12 1:14 ` sashiko-bot
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=sashiko-outbox-209883@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=anna@kernel.org \
--cc=cel@kernel.org \
--cc=dhowells@redhat.com \
--cc=jlayton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=v9fs@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