2024-02-05 11:21:26

by Fedor Pchelkin

[permalink] [raw]
Subject: [PATCH] ksmbd: free aux buffer if ksmbd_iov_pin_rsp_read fails

ksmbd_iov_pin_rsp_read() doesn't free the provided aux buffer if it
fails. Seems to be the caller's responsibility to clear the buffer in
error case.

Found by Linux Verification Center (linuxtesting.org).

Fixes: e2b76ab8b5c9 ("ksmbd: add support for read compound")
Cc: [email protected]
Signed-off-by: Fedor Pchelkin <[email protected]>
---
fs/smb/server/smb2pdu.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index ba7a72a6a4f4..0c97d3c86072 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -6173,8 +6173,10 @@ static noinline int smb2_read_pipe(struct ksmbd_work *work)
err = ksmbd_iov_pin_rsp_read(work, (void *)rsp,
offsetof(struct smb2_read_rsp, Buffer),
aux_payload_buf, nbytes);
- if (err)
+ if (err) {
+ kvfree(aux_payload_buf);
goto out;
+ }
kvfree(rpc_resp);
} else {
err = ksmbd_iov_pin_rsp(work, (void *)rsp,
@@ -6384,8 +6386,10 @@ int smb2_read(struct ksmbd_work *work)
err = ksmbd_iov_pin_rsp_read(work, (void *)rsp,
offsetof(struct smb2_read_rsp, Buffer),
aux_payload_buf, nbytes);
- if (err)
+ if (err) {
+ kvfree(aux_payload_buf);
goto out;
+ }
ksmbd_fd_put(work, fp);
return 0;

--
2.39.2



2024-02-05 11:45:40

by Namjae Jeon

[permalink] [raw]
Subject: Re: [PATCH] ksmbd: free aux buffer if ksmbd_iov_pin_rsp_read fails

2024-02-05 20:19 GMT+09:00, Fedor Pchelkin <[email protected]>:
> ksmbd_iov_pin_rsp_read() doesn't free the provided aux buffer if it
> fails. Seems to be the caller's responsibility to clear the buffer in
> error case.
>
> Found by Linux Verification Center (linuxtesting.org).
>
> Fixes: e2b76ab8b5c9 ("ksmbd: add support for read compound")
> Cc: [email protected]
> Signed-off-by: Fedor Pchelkin <[email protected]>
Applied it to #ksmbd-for-next-next.
Thanks for your patch!