Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Youling Tang <youling.tang@linux.dev>
To: linkinjeon@kernel.org, pc@manguebit.org,
	ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com,
	bharathsm@microsoft.com, metze@samba.org,
	chenxiaosong@chenxiaosong.com
Cc: linux-cifs@vger.kernel.org, Youling Tang <tangyouling@kylinos.cn>,
	ChenXiaoSong <chenxiaosong@kylinos.cn>
Subject: [PATCH 2/3] smb/client: fix refcount leak in smb2_async_readv() and smb2_async_writev()
Date: Fri,  4 Dec 2026 16:41:10 +0800	[thread overview]
Message-ID: <20261204084111.1483103-3-youling.tang@linux.dev> (raw)
In-Reply-To: <20261204084111.1483103-1-youling.tang@linux.dev>

From: Youling Tang <tangyouling@kylinos.cn>

See the procedure below:

  netfs_prepare_write
    netfs_alloc_subrequest
      refcount_set(&subreq->ref, 2) // one for the list, one for I/O

  smb2_async_writev
    wdata->mr = smbd_register_mr(...)
    adjust_credits // fails before submission
    __set_bit(NETFS_SREQ_NEED_RETRY, ...)
    cifs_write_subrequest_terminated // MR still registered
      netfs_write_subrequest_terminated
        netfs_put_subrequest // drop this I/O's reference
          __refcount_dec_and_test // 2 -> 1, returns false

  netfs_collect_write_results
    if (test_bit(NETFS_SREQ_NEED_RETRY, ...)
    netfs_retry_writes
      netfs_retry_write_stream
        netfs_get_subrequest // take an I/O reference for the retry (1 -> 2)
        netfs_reissue_write
          netfs_do_issue_write
            cifs_issue_write // stream->issue_write()
              __cifs_issue_write
                smb2_async_writev // wdata->server->ops->async_writev()
                  wdata->mr = smbd_register_mr(...) // old MR reference leaks

Fixes: 69c3c023af25 ("cifs: Implement netfslib hooks")
Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
 fs/smb/client/smb2pdu.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index 74309e063403..8defc8bc7ae8 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -5017,6 +5017,8 @@ smb2_async_readv(struct cifs_io_subrequest *rdata)
 
 async_readv_out:
 	cifs_small_buf_release(buf);
+	if (rc)
+		smb2_release_io_mr(rdata);
 
 out:
 	/* if the send error is retryable, let netfs know about it */
@@ -5439,6 +5441,7 @@ smb2_async_writev(struct cifs_io_subrequest *wdata)
 	}
 
 	if (rc) {
+		smb2_release_io_mr(wdata);
 		trace_smb3_rw_credits(wdata->rreq->debug_id,
 				      wdata->subreq.debug_index,
 				      wdata->credits.value,
-- 
2.55.0


  parent reply	other threads:[~2026-12-04  8:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  8:41 [PATCH 0/3] fix refcount leak in smb2_async_readv() and smb2_async_writev() Youling Tang
2026-12-04  8:41 ` [PATCH 1/3] smb/client: factor out smb2_release_io_mr() Youling Tang
2026-12-04  8:41 ` Youling Tang [this message]
2026-12-04  8:41 ` [PATCH 3/3] smb/client: remove redundant MR release from cifs_free_subrequest() Youling Tang

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=20261204084111.1483103-3-youling.tang@linux.dev \
    --to=youling.tang@linux.dev \
    --cc=bharathsm@microsoft.com \
    --cc=chenxiaosong@chenxiaosong.com \
    --cc=chenxiaosong@kylinos.cn \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=metze@samba.org \
    --cc=pc@manguebit.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=sprasad@microsoft.com \
    --cc=tangyouling@kylinos.cn \
    --cc=tom@talpey.com \
    /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