Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Namjae Jeon <linkinjeon@kernel.org>
To: gregkh@linuxfoundation.org, stable@vger.kernel.org, sashal@kernel.org
Cc: smfrench@gmail.com, Namjae Jeon <linkinjeon@kernel.org>,
	Steve French <stfrench@microsoft.com>
Subject: [PATCH 6.6.y 02/19] ksmbd: reorganize ksmbd_iov_pin_rsp()
Date: Sun, 31 Dec 2023 16:19:02 +0900	[thread overview]
Message-ID: <20231231071919.32103-3-linkinjeon@kernel.org> (raw)
In-Reply-To: <20231231071919.32103-1-linkinjeon@kernel.org>

[ Upstream commit 1819a904299942b309f687cc0f08b123500aa178 ]

If ksmbd_iov_pin_rsp fail, io vertor should be rollback.
This patch moves memory allocations to before setting the io vector
to avoid rollbacks.

Fixes: e2b76ab8b5c9 ("ksmbd: add support for read compound")
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/smb/server/ksmbd_work.c | 43 +++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/fs/smb/server/ksmbd_work.c b/fs/smb/server/ksmbd_work.c
index 51def3ca74c0..a2ed441e837a 100644
--- a/fs/smb/server/ksmbd_work.c
+++ b/fs/smb/server/ksmbd_work.c
@@ -95,11 +95,28 @@ bool ksmbd_queue_work(struct ksmbd_work *work)
 	return queue_work(ksmbd_wq, &work->work);
 }
 
-static int ksmbd_realloc_iov_pin(struct ksmbd_work *work, void *ib,
-				 unsigned int ib_len)
+static inline void __ksmbd_iov_pin(struct ksmbd_work *work, void *ib,
+				   unsigned int ib_len)
 {
+	work->iov[++work->iov_idx].iov_base = ib;
+	work->iov[work->iov_idx].iov_len = ib_len;
+	work->iov_cnt++;
+}
+
+static int __ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len,
+			       void *aux_buf, unsigned int aux_size)
+{
+	struct aux_read *ar;
+	int need_iov_cnt = 1;
 
-	if (work->iov_alloc_cnt <= work->iov_cnt) {
+	if (aux_size) {
+		need_iov_cnt++;
+		ar = kmalloc(sizeof(struct aux_read), GFP_KERNEL);
+		if (!ar)
+			return -ENOMEM;
+	}
+
+	if (work->iov_alloc_cnt < work->iov_cnt + need_iov_cnt) {
 		struct kvec *new;
 
 		work->iov_alloc_cnt += 4;
@@ -111,16 +128,6 @@ static int ksmbd_realloc_iov_pin(struct ksmbd_work *work, void *ib,
 		work->iov = new;
 	}
 
-	work->iov[++work->iov_idx].iov_base = ib;
-	work->iov[work->iov_idx].iov_len = ib_len;
-	work->iov_cnt++;
-
-	return 0;
-}
-
-static int __ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len,
-			       void *aux_buf, unsigned int aux_size)
-{
 	/* Plus rfc_length size on first iov */
 	if (!work->iov_idx) {
 		work->iov[work->iov_idx].iov_base = work->response_buf;
@@ -129,19 +136,13 @@ static int __ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len,
 		work->iov_cnt++;
 	}
 
-	ksmbd_realloc_iov_pin(work, ib, len);
+	__ksmbd_iov_pin(work, ib, len);
 	inc_rfc1001_len(work->iov[0].iov_base, len);
 
 	if (aux_size) {
-		struct aux_read *ar;
-
-		ksmbd_realloc_iov_pin(work, aux_buf, aux_size);
+		__ksmbd_iov_pin(work, aux_buf, aux_size);
 		inc_rfc1001_len(work->iov[0].iov_base, aux_size);
 
-		ar = kmalloc(sizeof(struct aux_read), GFP_KERNEL);
-		if (!ar)
-			return -ENOMEM;
-
 		ar->buf = aux_buf;
 		list_add(&ar->entry, &work->aux_read_list);
 	}
-- 
2.25.1


  parent reply	other threads:[~2023-12-31  7:19 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-31  7:19 [PATCH 6.6.y 00/19] ksmbd backport patches for linux-6.6.y Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 01/19] ksmbd: Remove unused field in ksmbd_user struct Namjae Jeon
2023-12-31  7:19 ` Namjae Jeon [this message]
2023-12-31  7:19 ` [PATCH 6.6.y 03/19] ksmbd: fix kernel-doc comment of ksmbd_vfs_setxattr() Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 04/19] ksmbd: fix missing RDMA-capable flag for IPoIB device in ksmbd_rdma_capable_netdev() Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 05/19] ksmbd: add support for surrogate pair conversion Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 06/19] ksmbd: no need to wait for binded connection termination at logoff Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 07/19] ksmbd: fix kernel-doc comment of ksmbd_vfs_kern_path_locked() Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 08/19] ksmbd: prevent memory leak on error return Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 09/19] ksmbd: separately allocate ci per dentry Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 10/19] ksmbd: move oplock handling after unlock parent dir Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 11/19] ksmbd: release interim response after sending status pending response Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 12/19] ksmbd: move setting SMB2_FLAGS_ASYNC_COMMAND and AsyncId Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 13/19] ksmbd: don't update ->op_state as OPLOCK_STATE_NONE on error Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 14/19] ksmbd: set epoch in create context v2 lease Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 15/19] ksmbd: set v2 lease capability Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 16/19] ksmbd: downgrade RWH lease caching state to RH for directory Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 17/19] ksmbd: send v2 lease break notification " Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 18/19] ksmbd: lazy v2 lease break on smb2_write() Namjae Jeon
2023-12-31  7:19 ` [PATCH 6.6.y 19/19] ksmbd: avoid duplicate opinfo_put() call on error of smb21_lease_break_ack() Namjae Jeon
2024-01-01 18:11 ` [PATCH 6.6.y 00/19] ksmbd backport patches for linux-6.6.y Sasha Levin

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=20231231071919.32103-3-linkinjeon@kernel.org \
    --to=linkinjeon@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=sashal@kernel.org \
    --cc=smfrench@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=stfrench@microsoft.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