1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/fs/netfs
David Howells 5de0219a9b
netfs: Fix setting NETFS_RREQ_ALL_QUEUED to be after all subreqs queued
Due to the code that queues a subreq on the active subrequest list getting
moved to netfs_issue_read(), the NETFS_RREQ_ALL_QUEUED flag may now get set
before the list-add actually happens.  This is not a problem if the
collection worker happens after the list-add, but it's a race - and, for
9P, where the read from the server is synchronous and done in the
submitting thread, this is a lot more likely.

The result is that, if the timing is wrong, a ref gets leaked because the
collector thinks that all the subreqs have completed (because it can't see
the last one yet) and clears NETFS_RREQ_IN_PROGRESS - at which point, the
collection worker no longer goes into the collector.

This can be provoked with AFS by injecting an msleep() right before the
final subreq is queued.

Fix this by splitting the queuing part out of netfs_issue_read() into a new
function, netfs_queue_read(), and calling it separately.  The setting of
NETFS_RREQ_ALL_QUEUED is then done by netfs_queue_read() whilst it is
holding the spinlock (that's probably unnecessary, but shouldn't hurt).

It might be better to set a flag on the final subreq, but this could be a
problem if an error occurs and we can't queue it.

Fixes: e2d46f2ec3 ("netfs: Change the read result collector to only use one work item")
Reported-by: Ihor Solodrai <ihor.solodrai@pm.me>
Closes: https://lore.kernel.org/r/a7x33d4dnMdGTtRivptq6S1i8btK70SNBP2XyX_xwDAhLvgQoPox6FVBOkifq4eBinfFfbZlIkMZBe3QarlWTxoEtHZwJCZbNKtaqrR7PvI=@pm.me/
Signed-off-by: David Howells <dhowells@redhat.com>
Link: https://lore.kernel.org/r/20250212222402.3618494-4-dhowells@redhat.com
Tested-by: Ihor Solodrai <ihor.solodrai@linux.dev>
cc: Eric Van Hensbergen <ericvh@kernel.org>
cc: Latchesar Ionkov <lucho@ionkov.net>
cc: Dominique Martinet <asmadeus@codewreck.org>
cc: Christian Schoenebeck <linux_oss@crudebyte.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Steve French <stfrench@microsoft.com>
cc: Paulo Alcantara <pc@manguebit.com>
cc: Jeff Layton <jlayton@kernel.org>
cc: v9fs@lists.linux.dev
cc: linux-cifs@vger.kernel.org
cc: netfs@lists.linux.dev
cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-02-13 16:00:48 +01:00
..
buffered_read.c netfs: Fix setting NETFS_RREQ_ALL_QUEUED to be after all subreqs queued 2025-02-13 16:00:48 +01:00
buffered_write.c netfs: Remove unnecessary references to pages 2024-10-07 13:45:15 +02:00
direct_read.c netfs: Change the read result collector to only use one work item 2024-12-20 22:34:08 +01:00
direct_write.c vfs-6.14-rc1.netfs 2025-01-20 09:29:11 -08:00
fscache_cache.c netfs: Revert "netfs: Switch debug logging to pr_debug()" 2024-07-24 10:15:37 +02:00
fscache_cookie.c fs/netfs/fscache_cookie: add missing "n_accesses" check 2024-08-12 22:03:26 +02:00
fscache_internal.h netfs, fscache: Combine fscache with netfs 2023-12-24 15:08:46 +00:00
fscache_io.c fscache: Remove duplicate included header 2024-11-21 09:35:25 +01:00
fscache_main.c fscache: delete fscache_cookie_lru_timer when fscache exits to avoid UAF 2024-09-01 10:30:25 +02:00
fscache_proc.c netfs: Fix proc/fs/fscache symlink to point to "netfs" not "../netfs" 2024-01-04 13:15:32 +00:00
fscache_stats.c netfs: Fix interaction between write-streaming and cachefiles culling 2024-01-05 15:42:25 +00:00
fscache_volume.c netfs/fscache: Add a memory barrier for FSCACHE_VOLUME_CREATING 2024-11-11 14:39:38 +01:00
internal.h netfs: Add retry stat counters 2025-02-13 16:00:48 +01:00
iterator.c netfs: Speed up buffered reading 2024-09-12 12:20:41 +02:00
Kconfig netfs: clean up after renaming FSCACHE_DEBUG config 2024-08-12 22:03:26 +02:00
locking.c netfs: Downgrade i_rwsem for a buffered write 2024-10-17 15:33:42 +02:00
main.c netfs: Change the read result collector to only use one work item 2024-12-20 22:34:08 +01:00
Makefile netfs: Add support for caching single monolithic objects such as AFS dirs 2024-12-20 22:34:06 +01:00
misc.c netfs: Add functions to build/clean a buffer in a folio_queue 2024-12-20 22:34:06 +01:00
objects.c netfs: Change the read result collector to only use one work item 2024-12-20 22:34:08 +01:00
read_collect.c netfs: Fix a number of read-retry hangs 2025-02-13 16:00:38 +01:00
read_pgpriv2.c netfs: Change the read result collector to only use one work item 2024-12-20 22:34:08 +01:00
read_retry.c netfs: Add retry stat counters 2025-02-13 16:00:48 +01:00
read_single.c afs: Locally initialise the contents of a new symlink on creation 2024-12-20 22:34:09 +01:00
rolling_buffer.c netfs: Abstract out a rolling folio buffer implementation 2024-12-20 22:34:02 +01:00
stats.c netfs: Add retry stat counters 2025-02-13 16:00:48 +01:00
write_collect.c netfs: Report on NULL folioq in netfs_writeback_unlock_folios() 2024-12-20 22:34:10 +01:00
write_issue.c netfs: Add retry stat counters 2025-02-13 16:00:48 +01:00
write_retry.c netfs: Add retry stat counters 2025-02-13 16:00:48 +01:00