mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] nfs: fix refcount leak in nfs_direct_read_schedule_iovec()
@ 2026-06-11 14:59 WenTao Liang
  2026-06-11 17:24 ` Trond Myklebust
  0 siblings, 1 reply; 2+ messages in thread
From: WenTao Liang @ 2026-06-11 14:59 UTC (permalink / raw)
  To: trondmy, anna; +Cc: linux-nfs, linux-kernel, WenTao Liang, stable

When nfs_direct_read_schedule_iovec() encounters an error after
get_dreq(dreq) increments the io_count but fails to start any I/O
(requested_bytes == 0), it falls through to the error path. That
path calls nfs_direct_req_release() to drop the I/O path’s kref,
but it never calls put_dreq() to balance the io_count. This leaves
the request’s io_count permanently elevated, a reference counting
violation that corrupts the teardown logic once the object is
freed via the remaining kref.

Fix the leak by calling put_dreq(dreq) before
nfs_direct_req_release() in the zero-bytes error path, so the
io_count is properly balanced.

Cc: stable@vger.kernel.org
Fixes: 65caafd0d214 ("SUNRPC reverting d03727b248d0 ("NFSv4 fix CLOSE not waiting for direct IO compeletion")")
Signed-off-by: WenTao Liang <vulab@iscas.ac.cn>
---
 fs/nfs/direct.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 48d89716193a..41a6cabb0592 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -400,6 +400,7 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq,
 	 */
 	if (requested_bytes == 0) {
 		inode_dio_end(inode);
+		put_dreq(dreq);
 		nfs_direct_req_release(dreq);
 		return result < 0 ? result : -EIO;
 	}
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] nfs: fix refcount leak in nfs_direct_read_schedule_iovec()
  2026-06-11 14:59 [PATCH] nfs: fix refcount leak in nfs_direct_read_schedule_iovec() WenTao Liang
@ 2026-06-11 17:24 ` Trond Myklebust
  0 siblings, 0 replies; 2+ messages in thread
From: Trond Myklebust @ 2026-06-11 17:24 UTC (permalink / raw)
  To: WenTao Liang, anna; +Cc: linux-nfs, linux-kernel, stable

On Thu, 2026-06-11 at 22:59 +0800, WenTao Liang wrote:
> When nfs_direct_read_schedule_iovec() encounters an error after
> get_dreq(dreq) increments the io_count but fails to start any I/O
> (requested_bytes == 0), it falls through to the error path. That
> path calls nfs_direct_req_release() to drop the I/O path’s kref,
> but it never calls put_dreq() to balance the io_count. This leaves
> the request’s io_count permanently elevated, a reference counting
> violation that corrupts the teardown logic once the object is
> freed via the remaining kref.

Exactly how is this corruption supposed to happen? I'm not seeing
anything that cares about the value of io_count either in
nfs_file_direct_read or in nfs_direct_req_free.

> 
> Fix the leak by calling put_dreq(dreq) before
> nfs_direct_req_release() in the zero-bytes error path, so the
> io_count is properly balanced.
> 
> Cc: stable@vger.kernel.org
> Fixes: 65caafd0d214 ("SUNRPC reverting d03727b248d0 ("NFSv4 fix CLOSE
> not waiting for direct IO compeletion")")
> Signed-off-by: WenTao Liang <vulab@iscas.ac.cn>
> ---
>  fs/nfs/direct.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
> index 48d89716193a..41a6cabb0592 100644
> --- a/fs/nfs/direct.c
> +++ b/fs/nfs/direct.c
> @@ -400,6 +400,7 @@ static ssize_t
> nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq,
>  	 */
>  	if (requested_bytes == 0) {
>  		inode_dio_end(inode);
> +		put_dreq(dreq);
>  		nfs_direct_req_release(dreq);
>  		return result < 0 ? result : -EIO;
>  	}

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trondmy@kernel.org, trond.myklebust@hammerspace.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-11 17:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-11 14:59 [PATCH] nfs: fix refcount leak in nfs_direct_read_schedule_iovec() WenTao Liang
2026-06-11 17:24 ` Trond Myklebust

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®