Skip to content

Commit b64ab56

Browse files
committed
nfs: Fix oops in nfs_netfs_init_request() when copying to cache
jira LE-3460 cve CVE-2024-57927 Rebuild_History Non-Buildable kernel-6.12.0-55.11.1.el10_0 commit-author David Howells <[email protected]> commit 86ad1a5 When netfslib wants to copy some data that has just been read on behalf of nfs, it creates a new write request and calls nfs_netfs_init_request() to initialise it, but with a NULL file pointer. This causes nfs_file_open_context() to oops - however, we don't actually need the nfs context as we're only going to write to the cache. Fix this by just returning if we aren't given a file pointer and emit a warning if the request was for something other than copy-to-cache. Further, fix nfs_netfs_free_request() so that it doesn't try to free the context if the pointer is NULL. Fixes: ee4cdf7 ("netfs: Speed up buffered reading") Reported-by: Max Kellermann <[email protected]> Closes: https://lore.kernel.org/r/CAKPOu+9DyMbKLhyJb7aMLDTb=Fh0T8Teb9sjuf_pze+XWT1VaQ@mail.gmail.com/ Signed-off-by: David Howells <[email protected]> Link: https://lore.kernel.org/r/[email protected] cc: Trond Myklebust <[email protected]> cc: Anna Schumaker <[email protected]> cc: Dave Wysochanski <[email protected]> cc: Jeff Layton <[email protected]> cc: [email protected] cc: [email protected] cc: [email protected] Signed-off-by: Christian Brauner <[email protected]> (cherry picked from commit 86ad1a5) Signed-off-by: Jonathan Maple <[email protected]>
1 parent b9a3473 commit b64ab56

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fs/nfs/fscache.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ int nfs_netfs_readahead(struct readahead_control *ractl)
263263
static atomic_t nfs_netfs_debug_id;
264264
static int nfs_netfs_init_request(struct netfs_io_request *rreq, struct file *file)
265265
{
266+
if (!file) {
267+
if (WARN_ON_ONCE(rreq->origin != NETFS_PGPRIV2_COPY_TO_CACHE))
268+
return -EIO;
269+
return 0;
270+
}
271+
266272
rreq->netfs_priv = get_nfs_open_context(nfs_file_open_context(file));
267273
rreq->debug_id = atomic_inc_return(&nfs_netfs_debug_id);
268274
/* [DEPRECATED] Use PG_private_2 to mark folio being written to the cache. */
@@ -274,7 +280,8 @@ static int nfs_netfs_init_request(struct netfs_io_request *rreq, struct file *fi
274280

275281
static void nfs_netfs_free_request(struct netfs_io_request *rreq)
276282
{
277-
put_nfs_open_context(rreq->netfs_priv);
283+
if (rreq->netfs_priv)
284+
put_nfs_open_context(rreq->netfs_priv);
278285
}
279286

280287
static struct nfs_netfs_io_data *nfs_netfs_alloc(struct netfs_io_subrequest *sreq)

0 commit comments

Comments
 (0)