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 v18 11/17] afs: Use a bvecq to hold dir content rather than folioq
Date: Tue, 17 Nov 2026 18:05:13 +0000 [thread overview]
Message-ID: <sashiko-outbox-219308@kernel.org> (raw)
In-Reply-To: <20261117171958.2982801-12-dhowells@redhat.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] afs: inconsistent i_size and uninitialized buffer in
afs_symlink_writepages()
- [Medium] afs: inconsistent directory state and size in
afs_dir_writepages()
--
commit 1f753ccfe6b6a6145c885c24eef1abe752152c76
Author: David Howells <dhowells@redhat.com>
afs: Use a bvecq to hold dir content rather than folioq
This commit replaces folio_queue buffers with refcounted bvecq buffers for
AFS directory and symlink contents, and snapshots the buffer and sizes
under cb_lock during 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..cc0449b9a6866 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;
>
> @@ -2235,15 +2236,23 @@ static int afs_dir_writepages(struct address_space *mapping,
> down_read(&dvnode->validate_lock);
> }
>
> + read_seqlock_excl(&dvnode->cb_lock);
> 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 = i_size_read(&dvnode->netfs.inode);
> + size_t 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. */
> + } else {
> + read_sequnlock_excl(&dvnode->cb_lock);
> }
>
> up_read(&dvnode->validate_lock);
> + bvecq_put(directory);
> return ret;
> }
[Severity: Medium]
Can afs_dir_writepages() still observe an inconsistent i_size and d_size or
write unvalidated directory data to fscache when checking only
AFS_VNODE_DIR_VALID under cb_lock?
In afs_read_dir(), set_bit(AFS_VNODE_DIR_VALID, &dvnode->flags) runs
outside cb_lock after afs_read_single() has released io_lock and marked the
inode dirty. A concurrent RPC that updates status without holding
validate_lock, such as FS.InlineBulkStatus in afs_do_lookup(), can update
inode->i_size and clear AFS_VNODE_DIR_VALID in between:
CPU0 CPU1
afs_read_dir()
afs_read_single()
... (allocates d_size, dirties inode)
afs_do_lookup()
...
afs_vnode_commit_status()
write_seqlock(&dvnode->cb_lock)
afs_apply_status()
afs_invalidate_dir()
i_size_write(inode, new_size)
write_sequnlock(&dvnode->cb_lock)
set_bit(AFS_VNODE_DIR_VALID, ...)
downgrade_write(&dvnode->validate_lock)
afs_dir_writepages()
... (d_size < i_size)
netfs_writeback_single(..., i_size)
WARN_ON_ONCE(iov_iter_count(iter) < len)
Also, afs_inode_init_from_status() sets AFS_VNODE_DIR_VALID on new directory
vnodes before the directory is read. During the first afs_read_dir(),
netfs_read_single() marks the inode dirty before afs_do_read_single() runs
afs_dir_check(); if afs_dir_check() fails, afs_read_dir() jumps to
error_unlock with AFS_VNODE_DIR_VALID still set and AFS_VNODE_DIR_READ
clear, so afs_dir_writepages() will write the corrupted buffer into fscache.
[ ... ]
> diff --git a/fs/afs/symlink.c b/fs/afs/symlink.c
> index c18e4f8064234..b65f6c3c011ac 100644
> --- a/fs/afs/symlink.c
> +++ b/fs/afs/symlink.c
> @@ -56,7 +56,7 @@ void afs_evict_symlink(struct afs_vnode *vnode)
> void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)
> {
> struct afs_symlink *symlink = op->create.symlink;
> - size_t dsize = 0;
> + unsigned int alloc_flags = 0;
> size_t size = strlen(symlink->content) + 1;
> char *p;
>
> @@ -66,12 +66,15 @@ void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)
> if (!fscache_cookie_enabled(netfs_i_cookie(&vnode->netfs)))
> return;
>
> - if (netfs_alloc_folioq_buffer(NULL, &vnode->directory, &dsize, size,
> - mapping_gfp_mask(vnode->netfs.inode.i_mapping)) < 0)
> + vnode->directory =
> + bvecq_alloc_buffer(PAGE_SIZE,
> + mapping_gfp_mask(vnode->netfs.inode.i_mapping),
> + &alloc_flags);
> + if (!vnode->directory)
> return;
>
> - vnode->directory_size = dsize;
> - p = kmap_local_folio(folioq_folio(vnode->directory, 0), 0);
> + vnode->directory_size = PAGE_SIZE;
> + p = bvec_kmap_partial(&vnode->directory->bv[0], 0);
> memcpy(p, symlink->content, size);
> kunmap_local(p);
> netfs_single_mark_inode_dirty(&vnode->netfs.inode);
> @@ -84,6 +87,7 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)
> {
> struct afs_symlink *symlink;
> struct iov_iter iter;
> + unsigned int alloc_flags = 0;
> ssize_t ret;
> loff_t i_size;
>
> @@ -94,17 +98,15 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)
> }
>
> if (!vnode->directory) {
> - size_t cur_size = 0;
> -
> - ret = netfs_alloc_folioq_buffer(NULL,
> - &vnode->directory, &cur_size, PAGE_SIZE,
> - mapping_gfp_mask(vnode->netfs.inode.i_mapping));
> + vnode->directory = bvecq_alloc_buffer(
> + PAGE_SIZE, mapping_gfp_mask(vnode->netfs.inode.i_mapping),
> + &alloc_flags);
> + if (!vnode->directory)
> + return -ENOMEM;
> vnode->directory_size = PAGE_SIZE;
> - if (ret < 0)
> - return ret;
> }
[ ... ]
> @@ -249,24 +251,31 @@ int afs_symlink_writepages(struct address_space *mapping,
> down_read(&vnode->validate_lock);
> }
>
> + read_seqlock_excl(&vnode->cb_lock);
> if (vnode->directory &&
> atomic64_read(&vnode->cb_expires_at) != AFS_NO_CB_PROMISE) {
> + struct bvecq *bq = bvecq_get(vnode->directory);
> size_t i_size = i_size_read(&vnode->netfs.inode);
> + size_t d_size = vnode->directory_size;
> +
> + read_sequnlock_excl(&vnode->cb_lock);
>
> - if (i_size < vnode->directory_size) {
> - iov_iter_folio_queue(&iter, ITER_DEST, vnode->directory, 0, 0,
> - vnode->directory_size);
> + if (i_size < d_size) {
> + iov_iter_bvec_queue(&iter, ITER_DEST, bq, 0, 0, d_size);
> iov_iter_advance(&iter, i_size);
> - iov_iter_zero(vnode->directory_size - i_size, &iter);
> + iov_iter_zero(d_size - i_size, &iter);
> }
> - iov_iter_folio_queue(&iter, ITER_SOURCE, vnode->directory, 0, 0,
> - vnode->directory_size);
> +
> + iov_iter_bvec_queue(&iter, ITER_SOURCE, bq, 0, 0, d_size);
> ret = netfs_writeback_single(mapping, wbc, &iter, i_size);
> + bvecq_put(bq);
> + } else {
> + read_sequnlock_excl(&vnode->cb_lock);
> }
[Severity: High]
Can afs_symlink_writepages() write uninitialized kernel memory to fscache
or pass i_size > d_size to netfs_writeback_single()?
Both afs_init_new_symlink() and afs_do_read_symlink() allocate
vnode->directory via bvecq_alloc_buffer() without __GFP_ZERO and populate
only the symlink length. When a status update modifies a symlink,
afs_vnode_commit_status() updates inode->i_size and sets a valid
cb_expires_at while setting AFS_VNODE_ZAP_DATA rather than clearing
vnode->directory:
fs/afs/inode.c:afs_apply_status() {
...
if (vnode->status.type == AFS_FTYPE_DIR)
afs_invalidate_dir(vnode, afs_dir_invalid_dv_mismatch);
else
set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags);
change_size = true;
...
}
Because afs_symlink_writepages() only checks vnode->directory and
cb_expires_at != AFS_NO_CB_PROMISE, a larger updated i_size <= PAGE_SIZE
causes it to zero only [i_size, d_size) and write stale symlink bytes plus
uninitialized page memory in [old_size, i_size) into fscache. If the server
reports i_size > PAGE_SIZE (including when afs_do_read_symlink() returns
-EFBIG after netfs_read_single() has already updated i_size and dirtied the
inode), afs_symlink_writepages() passes i_size > d_size to
netfs_writeback_single(), triggering WARN_ON_ONCE(iov_iter_count(iter) < len).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117171958.2982801-1-dhowells@redhat.com?part=11
next prev parent reply other threads:[~2026-11-17 18:05 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 17:18 [PATCH v18 00/17] netfs, iov_iter: Use a chain of bio_vec arrays instead of folio_queue David Howells
2026-11-17 17:18 ` [PATCH v18 01/17] iov_iter: Fix kunit test to remove __init and __refdata marks David Howells
2026-11-17 17:34 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 02/17] Add a function to kmap one page of a multipage bio_vec David Howells
2026-11-17 17:28 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 03/17] iov_iter: Add a segmented queue of bio_vec[] David Howells
2026-11-17 17:56 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 04/17] netfs: Add some tools for managing bvecq chains David Howells
2026-11-17 17:51 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 05/17] iov_iter: Add an API document for the bvecq structure David Howells
2026-11-17 17:32 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 06/17] iov_iter: Add a bvecq kunit test David Howells
2026-11-17 17:30 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 07/17] afs: Fix an inconsistency in the symlink code David Howells
2026-11-17 17:38 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 08/17] netfs: Explicitly pass tail padding to netfs_writeback_single() David Howells
2026-11-17 17:58 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 09/17] netfs: Change netfs_writeback_single() to not look inside the iterator David Howells
2026-11-17 17:53 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 10/17] netfs: Pass the write length to request creation where appropriate David Howells
2026-11-17 17:28 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 11/17] afs: Use a bvecq to hold dir content rather than folioq David Howells
2026-11-17 18:05 ` sashiko-bot [this message]
2026-11-17 17:19 ` [PATCH v18 12/17] cifs: Use a bvecq for buffering instead of a folioq David Howells
2026-11-17 17:45 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 13/17] smbdirect: Support ITER_BVECQ in smbdirect_map_sges_from_iter() David Howells
2026-11-17 17:36 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 14/17] netfs: Switch folioq to bvecq David Howells
2026-11-17 18:19 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 15/17] smbdirect: Remove support for ITER_FOLIOQ from smbdirect_map_sges_from_iter() David Howells
2026-11-17 17:35 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 16/17] iov_iter: Remove ITER_FOLIOQ David Howells
2026-11-17 17:41 ` sashiko-bot
2026-11-17 17:19 ` [PATCH v18 17/17] netfs: Remove folio_queue David Howells
2026-11-17 17:37 ` 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-219308@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