diff mbox series

[v2] ksmbd: send proper error response in smb2_tree_connect()

Message ID 20221223105930.1405307-1-mmakassikis@freebox.fr
State New
Headers show
Series [v2] ksmbd: send proper error response in smb2_tree_connect() | expand

Commit Message

Marios Makassikis Dec. 23, 2022, 10:59 a.m. UTC
Currently, smb2_tree_connect doesn't send an error response packet on
error.

This causes libsmb2 to skip the specific error code and fail with the
following:
 smb2_service failed with : Failed to parse fixed part of command
 payload. Unexpected size of Error reply. Expected 9, got 8

Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
---
v2:
 move smb2_set_err_rsp() call to the end to simplify, as suggested by Namjae

 fs/ksmbd/smb2pdu.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Namjae Jeon Dec. 27, 2022, 3:05 p.m. UTC | #1
2022-12-23 19:59 GMT+09:00, Marios Makassikis <mmakassikis@freebox.fr>:
> Currently, smb2_tree_connect doesn't send an error response packet on
> error.
>
> This causes libsmb2 to skip the specific error code and fail with the
> following:
>  smb2_service failed with : Failed to parse fixed part of command
>  payload. Unexpected size of Error reply. Expected 9, got 8
>
> Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>

Thanks!
diff mbox series

Patch

diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
index 14d7f3599c63..38fbda52e06f 100644
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -1928,13 +1928,13 @@  int smb2_tree_connect(struct ksmbd_work *work)
 	if (conn->posix_ext_supported)
 		status.tree_conn->posix_extensions = true;
 
-out_err1:
 	rsp->StructureSize = cpu_to_le16(16);
+	inc_rfc1001_len(work->response_buf, 16);
+out_err1:
 	rsp->Capabilities = 0;
 	rsp->Reserved = 0;
 	/* default manual caching */
 	rsp->ShareFlags = SMB2_SHAREFLAG_MANUAL_CACHING;
-	inc_rfc1001_len(work->response_buf, 16);
 
 	if (!IS_ERR(treename))
 		kfree(treename);
@@ -1967,6 +1967,9 @@  int smb2_tree_connect(struct ksmbd_work *work)
 		rsp->hdr.Status = STATUS_ACCESS_DENIED;
 	}
 
+	if (status.ret != KSMBD_TREE_CONN_STATUS_OK)
+		smb2_set_err_rsp(work);
+
 	return rc;
 }