diff mbox series

[1/3] ksmbd: set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO

Message ID 20211215060206.8048-1-linkinjeon@kernel.org (mailing list archive)
State New, archived
Headers show
Series [1/3] ksmbd: set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO | expand

Commit Message

Namjae Jeon Dec. 15, 2021, 6:02 a.m. UTC
Set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO if netdev has
multi tx queues. And add ksmbd_compare_user() to avoid racy condition
issue in ksmbd_free_user(). because windows client is simultaneously used
to send session setup requests for multichannel connection.

Tested-by: Ziwei Xie <zw.xie@high-flyer.cn>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
 fs/ksmbd/mgmt/user_config.c | 10 ++++++++++
 fs/ksmbd/mgmt/user_config.h |  1 +
 fs/ksmbd/smb2pdu.c          | 14 +++++++++-----
 3 files changed, 20 insertions(+), 5 deletions(-)

Comments

Hyunchul Lee Dec. 15, 2021, 10:15 p.m. UTC | #1
2021년 12월 16일 (목) 오전 4:47, Namjae Jeon <linkinjeon@kernel.org>님이 작성:
>
> Set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO if netdev has
> multi tx queues. And add ksmbd_compare_user() to avoid racy condition
> issue in ksmbd_free_user(). because windows client is simultaneously used
> to send session setup requests for multichannel connection.
>
> Tested-by: Ziwei Xie <zw.xie@high-flyer.cn>
> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
> ---
>  fs/ksmbd/mgmt/user_config.c | 10 ++++++++++
>  fs/ksmbd/mgmt/user_config.h |  1 +
>  fs/ksmbd/smb2pdu.c          | 14 +++++++++-----
>  3 files changed, 20 insertions(+), 5 deletions(-)
>
> diff --git a/fs/ksmbd/mgmt/user_config.c b/fs/ksmbd/mgmt/user_config.c
> index 1019d3677d55..279d00feff21 100644
> --- a/fs/ksmbd/mgmt/user_config.c
> +++ b/fs/ksmbd/mgmt/user_config.c
> @@ -67,3 +67,13 @@ int ksmbd_anonymous_user(struct ksmbd_user *user)
>                 return 1;
>         return 0;
>  }
> +
> +bool ksmbd_compare_user(struct ksmbd_user *u1, struct ksmbd_user *u2)
> +{
> +       if (strcmp(u1->name, u2->name))
> +               return false;
> +       if (memcmp(u1->passkey, u2->passkey, u1->passkey_sz))
> +               return false;
> +
> +       return true;
> +}
> diff --git a/fs/ksmbd/mgmt/user_config.h b/fs/ksmbd/mgmt/user_config.h
> index aff80b029579..6a44109617f1 100644
> --- a/fs/ksmbd/mgmt/user_config.h
> +++ b/fs/ksmbd/mgmt/user_config.h
> @@ -64,4 +64,5 @@ struct ksmbd_user *ksmbd_login_user(const char *account);
>  struct ksmbd_user *ksmbd_alloc_user(struct ksmbd_login_response *resp);
>  void ksmbd_free_user(struct ksmbd_user *user);
>  int ksmbd_anonymous_user(struct ksmbd_user *user);
> +bool ksmbd_compare_user(struct ksmbd_user *u1, struct ksmbd_user *u2);
>  #endif /* __USER_CONFIG_MANAGEMENT_H__ */
> diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
> index f7bea92d4c98..7aee3b58b16f 100644
> --- a/fs/ksmbd/smb2pdu.c
> +++ b/fs/ksmbd/smb2pdu.c
> @@ -1429,10 +1429,15 @@ static int ntlm_authenticate(struct ksmbd_work *work)
>                         ksmbd_free_user(user);
>                         return 0;
>                 }
> -               ksmbd_free_user(sess->user);
> +
> +               if (!ksmbd_compare_user(sess->user, user))
> +                       return -EPERM;
> +

We  don't need to free the user? Other than that, this looks good to me.

> +               ksmbd_free_user(user);
> +       } else {
> +               sess->user = user;
>         }
>
> -       sess->user = user;
>         if (user_guest(sess->user)) {
>                 if (conn->sign) {
>                         ksmbd_debug(SMB, "Guest login not allowed when signing enabled\n");
> @@ -2036,9 +2041,6 @@ int smb2_session_logoff(struct ksmbd_work *work)
>
>         ksmbd_debug(SMB, "request\n");
>
> -       /* Got a valid session, set connection state */
> -       WARN_ON(sess->conn != conn);
> -
>         /* setting CifsExiting here may race with start_tcp_sess */
>         ksmbd_conn_set_need_reconnect(work);
>         ksmbd_close_session_fds(work);
> @@ -7243,6 +7245,8 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
>                 nii_rsp->IfIndex = cpu_to_le32(netdev->ifindex);
>
>                 nii_rsp->Capability = 0;
> +               if (netdev->real_num_tx_queues > 1)
> +                       nii_rsp->Capability |= cpu_to_le32(RSS_CAPABLE);
>                 if (ksmbd_rdma_capable_netdev(netdev))
>                         nii_rsp->Capability |= cpu_to_le32(RDMA_CAPABLE);
>
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/fs/ksmbd/mgmt/user_config.c b/fs/ksmbd/mgmt/user_config.c
index 1019d3677d55..279d00feff21 100644
--- a/fs/ksmbd/mgmt/user_config.c
+++ b/fs/ksmbd/mgmt/user_config.c
@@ -67,3 +67,13 @@  int ksmbd_anonymous_user(struct ksmbd_user *user)
 		return 1;
 	return 0;
 }
+
+bool ksmbd_compare_user(struct ksmbd_user *u1, struct ksmbd_user *u2)
+{
+	if (strcmp(u1->name, u2->name))
+		return false;
+	if (memcmp(u1->passkey, u2->passkey, u1->passkey_sz))
+		return false;
+
+	return true;
+}
diff --git a/fs/ksmbd/mgmt/user_config.h b/fs/ksmbd/mgmt/user_config.h
index aff80b029579..6a44109617f1 100644
--- a/fs/ksmbd/mgmt/user_config.h
+++ b/fs/ksmbd/mgmt/user_config.h
@@ -64,4 +64,5 @@  struct ksmbd_user *ksmbd_login_user(const char *account);
 struct ksmbd_user *ksmbd_alloc_user(struct ksmbd_login_response *resp);
 void ksmbd_free_user(struct ksmbd_user *user);
 int ksmbd_anonymous_user(struct ksmbd_user *user);
+bool ksmbd_compare_user(struct ksmbd_user *u1, struct ksmbd_user *u2);
 #endif /* __USER_CONFIG_MANAGEMENT_H__ */
diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
index f7bea92d4c98..7aee3b58b16f 100644
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -1429,10 +1429,15 @@  static int ntlm_authenticate(struct ksmbd_work *work)
 			ksmbd_free_user(user);
 			return 0;
 		}
-		ksmbd_free_user(sess->user);
+
+		if (!ksmbd_compare_user(sess->user, user))
+			return -EPERM;
+
+		ksmbd_free_user(user);
+	} else {
+		sess->user = user;
 	}
 
-	sess->user = user;
 	if (user_guest(sess->user)) {
 		if (conn->sign) {
 			ksmbd_debug(SMB, "Guest login not allowed when signing enabled\n");
@@ -2036,9 +2041,6 @@  int smb2_session_logoff(struct ksmbd_work *work)
 
 	ksmbd_debug(SMB, "request\n");
 
-	/* Got a valid session, set connection state */
-	WARN_ON(sess->conn != conn);
-
 	/* setting CifsExiting here may race with start_tcp_sess */
 	ksmbd_conn_set_need_reconnect(work);
 	ksmbd_close_session_fds(work);
@@ -7243,6 +7245,8 @@  static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
 		nii_rsp->IfIndex = cpu_to_le32(netdev->ifindex);
 
 		nii_rsp->Capability = 0;
+		if (netdev->real_num_tx_queues > 1)
+			nii_rsp->Capability |= cpu_to_le32(RSS_CAPABLE);
 		if (ksmbd_rdma_capable_netdev(netdev))
 			nii_rsp->Capability |= cpu_to_le32(RDMA_CAPABLE);