linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ksmbd: send proper error response in smb2_tree_connect()
@ 2022-12-22 10:47 Marios Makassikis
  2022-12-23  4:21 ` Namjae Jeon
  2022-12-23 10:59 ` [PATCH v2] " Marios Makassikis
  0 siblings, 2 replies; 4+ messages in thread
From: Marios Makassikis @ 2022-12-22 10:47 UTC (permalink / raw)
  To: linux-cifs; +Cc: Marios Makassikis

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>
---
 fs/ksmbd/smb2pdu.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
index 14d7f3599c63..bd2ff9ffa965 100644
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -1882,12 +1882,14 @@ int smb2_tree_connect(struct ksmbd_work *work)
 	if (IS_ERR(treename)) {
 		pr_err("treename is NULL\n");
 		status.ret = KSMBD_TREE_CONN_STATUS_ERROR;
+		smb2_set_err_rsp(work);
 		goto out_err1;
 	}
 
 	name = ksmbd_extract_sharename(conn->um, treename);
 	if (IS_ERR(name)) {
 		status.ret = KSMBD_TREE_CONN_STATUS_ERROR;
+		smb2_set_err_rsp(work);
 		goto out_err1;
 	}
 
@@ -1895,10 +1897,12 @@ int smb2_tree_connect(struct ksmbd_work *work)
 		    name, treename);
 
 	status = ksmbd_tree_conn_connect(conn, sess, name);
-	if (status.ret == KSMBD_TREE_CONN_STATUS_OK)
+	if (status.ret == KSMBD_TREE_CONN_STATUS_OK) {
 		rsp->hdr.Id.SyncId.TreeId = cpu_to_le32(status.tree_conn->id);
-	else
+	} else {
+		smb2_set_err_rsp(work);
 		goto out_err1;
+	}
 
 	share = status.tree_conn->share_conf;
 	if (test_share_config_flag(share, KSMBD_SHARE_FLAG_PIPE)) {
@@ -1928,13 +1932,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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ksmbd: send proper error response in smb2_tree_connect()
  2022-12-22 10:47 [PATCH] ksmbd: send proper error response in smb2_tree_connect() Marios Makassikis
@ 2022-12-23  4:21 ` Namjae Jeon
  2022-12-23 10:59 ` [PATCH v2] " Marios Makassikis
  1 sibling, 0 replies; 4+ messages in thread
From: Namjae Jeon @ 2022-12-23  4:21 UTC (permalink / raw)
  To: Marios Makassikis; +Cc: linux-cifs

2022-12-22 19:47 GMT+09:00, Marios Makassikis <mmakassikis@freebox.fr>:
Hi Marios,
> 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>
> ---
>  fs/ksmbd/smb2pdu.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
> index 14d7f3599c63..bd2ff9ffa965 100644
> --- a/fs/ksmbd/smb2pdu.c
> +++ b/fs/ksmbd/smb2pdu.c
> @@ -1882,12 +1882,14 @@ int smb2_tree_connect(struct ksmbd_work *work)
>  	if (IS_ERR(treename)) {
>  		pr_err("treename is NULL\n");
>  		status.ret = KSMBD_TREE_CONN_STATUS_ERROR;
> +		smb2_set_err_rsp(work);
>  		goto out_err1;
>  	}
>
>  	name = ksmbd_extract_sharename(conn->um, treename);
>  	if (IS_ERR(name)) {
>  		status.ret = KSMBD_TREE_CONN_STATUS_ERROR;
> +		smb2_set_err_rsp(work);
>  		goto out_err1;
>  	}
>
> @@ -1895,10 +1897,12 @@ int smb2_tree_connect(struct ksmbd_work *work)
>  		    name, treename);
>
>  	status = ksmbd_tree_conn_connect(conn, sess, name);
> -	if (status.ret == KSMBD_TREE_CONN_STATUS_OK)
> +	if (status.ret == KSMBD_TREE_CONN_STATUS_OK) {
>  		rsp->hdr.Id.SyncId.TreeId = cpu_to_le32(status.tree_conn->id);
> -	else
> +	} else {
> +		smb2_set_err_rsp(work);
>  		goto out_err1;
> +	}
>
>  	share = status.tree_conn->share_conf;
>  	if (test_share_config_flag(share, KSMBD_SHARE_FLAG_PIPE)) {
> @@ -1928,13 +1932,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);

How about moving smb2_set_err_rsp() to the end of this function to simplify?

@@ -1987,6 +1987,9 @@ out_err1:
                rsp->hdr.Status = STATUS_ACCESS_DENIED;
        }

+       if (status.ret != KSMBD_TREE_CONN_STATUS_OK)
+               smb2_set_err_rsp(work);
+
        return rc;
 }

> --
> 2.25.1
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] ksmbd: send proper error response in smb2_tree_connect()
  2022-12-22 10:47 [PATCH] ksmbd: send proper error response in smb2_tree_connect() Marios Makassikis
  2022-12-23  4:21 ` Namjae Jeon
@ 2022-12-23 10:59 ` Marios Makassikis
  2022-12-27 15:05   ` Namjae Jeon
  1 sibling, 1 reply; 4+ messages in thread
From: Marios Makassikis @ 2022-12-23 10:59 UTC (permalink / raw)
  To: linux-cifs; +Cc: Marios Makassikis

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(-)

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;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] ksmbd: send proper error response in smb2_tree_connect()
  2022-12-23 10:59 ` [PATCH v2] " Marios Makassikis
@ 2022-12-27 15:05   ` Namjae Jeon
  0 siblings, 0 replies; 4+ messages in thread
From: Namjae Jeon @ 2022-12-27 15:05 UTC (permalink / raw)
  To: Marios Makassikis; +Cc: linux-cifs

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!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-27 15:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-22 10:47 [PATCH] ksmbd: send proper error response in smb2_tree_connect() Marios Makassikis
2022-12-23  4:21 ` Namjae Jeon
2022-12-23 10:59 ` [PATCH v2] " Marios Makassikis
2022-12-27 15:05   ` Namjae Jeon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).