ksmbd: free aux buffer if ksmbd_iov_pin_rsp_read fails
authorFedor Pchelkin <pchelkin@ispras.ru>
Mon, 5 Feb 2024 11:19:16 +0000 (14:19 +0300)
committerSteve French <stfrench@microsoft.com>
Thu, 8 Feb 2024 02:23:37 +0000 (20:23 -0600)
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: stable@vger.kernel.org
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/server/smb2pdu.c

index ba7a72a6a4f45f6b756768c4a3a48e19d74e3683..0c97d3c860726a303081eb25927d38439bfaf4ea 100644 (file)
@@ -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;