Linux CIFS filesystem development
 help / color / mirror / Atom feed
* [PATCH v2 1/2] ksmbd: set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO
@ 2021-12-16  1:37 Namjae Jeon
  2021-12-16  1:37 ` [PATCH v2 2/2] ksmbd: set both ipv4 and ipv6 " Namjae Jeon
  2021-12-16 13:11 ` [PATCH v2 1/2] ksmbd: set RSS capable " Hyunchul Lee
  0 siblings, 2 replies; 4+ messages in thread
From: Namjae Jeon @ 2021-12-16  1:37 UTC (permalink / raw)
  To: linux-cifs; +Cc: Namjae Jeon

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.

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
 v2:
   - Add missing free ksmbd_user before returning.

 fs/ksmbd/mgmt/user_config.c | 10 ++++++++++
 fs/ksmbd/mgmt/user_config.h |  1 +
 fs/ksmbd/smb2pdu.c          | 15 ++++++++++-----
 3 files changed, 21 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..2ff4f813026e 100644
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -1429,10 +1429,16 @@ 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)) {
+			ksmbd_free_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 +2042,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 +7246,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


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

* [PATCH v2 2/2] ksmbd: set both ipv4 and ipv6 in FSCTL_QUERY_NETWORK_INTERFACE_INFO
  2021-12-16  1:37 [PATCH v2 1/2] ksmbd: set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO Namjae Jeon
@ 2021-12-16  1:37 ` Namjae Jeon
  2021-12-16 13:20   ` Hyunchul Lee
  2021-12-16 13:11 ` [PATCH v2 1/2] ksmbd: set RSS capable " Hyunchul Lee
  1 sibling, 1 reply; 4+ messages in thread
From: Namjae Jeon @ 2021-12-16  1:37 UTC (permalink / raw)
  To: linux-cifs; +Cc: Namjae Jeon

Set ipv4 and ipv6 address in FSCTL_QUERY_NETWORK_INTERFACE_INFO.

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
 v2:
   - move buffer check to under ipv6_retry to validate overflow.

 fs/ksmbd/smb2pdu.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
index 2ff4f813026e..0fbb62f9d509 100644
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -7224,15 +7224,10 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
 	struct sockaddr_storage_rsp *sockaddr_storage;
 	unsigned int flags;
 	unsigned long long speed;
-	struct sockaddr_in6 *csin6 = (struct sockaddr_in6 *)&conn->peer_addr;
 
 	rtnl_lock();
 	for_each_netdev(&init_net, netdev) {
-		if (out_buf_len <
-		    nbytes + sizeof(struct network_interface_info_ioctl_rsp)) {
-			rtnl_unlock();
-			return -ENOSPC;
-		}
+		bool ipv4_set = false;
 
 		if (netdev->type == ARPHRD_LOOPBACK)
 			continue;
@@ -7240,6 +7235,12 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
 		flags = dev_get_flags(netdev);
 		if (!(flags & IFF_RUNNING))
 			continue;
+ipv6_retry:
+		if (out_buf_len <
+		    nbytes + sizeof(struct network_interface_info_ioctl_rsp)) {
+			rtnl_unlock();
+			return -ENOSPC;
+		}
 
 		nii_rsp = (struct network_interface_info_ioctl_rsp *)
 				&rsp->Buffer[nbytes];
@@ -7272,8 +7273,7 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
 					nii_rsp->SockAddr_Storage;
 		memset(sockaddr_storage, 0, 128);
 
-		if (conn->peer_addr.ss_family == PF_INET ||
-		    ipv6_addr_v4mapped(&csin6->sin6_addr)) {
+		if (!ipv4_set) {
 			struct in_device *idev;
 
 			sockaddr_storage->Family = cpu_to_le16(INTERNETWORK);
@@ -7284,6 +7284,9 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
 				continue;
 			sockaddr_storage->addr4.IPv4address =
 						idev_ipv4_address(idev);
+			nbytes += sizeof(struct network_interface_info_ioctl_rsp);
+			ipv4_set = true;
+			goto ipv6_retry;
 		} else {
 			struct inet6_dev *idev6;
 			struct inet6_ifaddr *ifa;
@@ -7305,9 +7308,8 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
 				break;
 			}
 			sockaddr_storage->addr6.ScopeId = 0;
+			nbytes += sizeof(struct network_interface_info_ioctl_rsp);
 		}
-
-		nbytes += sizeof(struct network_interface_info_ioctl_rsp);
 	}
 	rtnl_unlock();
 
-- 
2.25.1


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

* Re: [PATCH v2 1/2] ksmbd: set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO
  2021-12-16  1:37 [PATCH v2 1/2] ksmbd: set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO Namjae Jeon
  2021-12-16  1:37 ` [PATCH v2 2/2] ksmbd: set both ipv4 and ipv6 " Namjae Jeon
@ 2021-12-16 13:11 ` Hyunchul Lee
  1 sibling, 0 replies; 4+ messages in thread
From: Hyunchul Lee @ 2021-12-16 13:11 UTC (permalink / raw)
  To: Namjae Jeon; +Cc: linux-cifs

2021년 12월 16일 (목) 오후 5:48, 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.
>
> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>

Acked-by: Hyunchul Lee <hyc.lee@gmail.com>

> ---
>  v2:
>    - Add missing free ksmbd_user before returning.
>
>  fs/ksmbd/mgmt/user_config.c | 10 ++++++++++
>  fs/ksmbd/mgmt/user_config.h |  1 +
>  fs/ksmbd/smb2pdu.c          | 15 ++++++++++-----
>  3 files changed, 21 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..2ff4f813026e 100644
> --- a/fs/ksmbd/smb2pdu.c
> +++ b/fs/ksmbd/smb2pdu.c
> @@ -1429,10 +1429,16 @@ 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)) {
> +                       ksmbd_free_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 +2042,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 +7246,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
>


-- 
Thanks,
Hyunchul

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

* Re: [PATCH v2 2/2] ksmbd: set both ipv4 and ipv6 in FSCTL_QUERY_NETWORK_INTERFACE_INFO
  2021-12-16  1:37 ` [PATCH v2 2/2] ksmbd: set both ipv4 and ipv6 " Namjae Jeon
@ 2021-12-16 13:20   ` Hyunchul Lee
  0 siblings, 0 replies; 4+ messages in thread
From: Hyunchul Lee @ 2021-12-16 13:20 UTC (permalink / raw)
  To: Namjae Jeon; +Cc: linux-cifs

2021년 12월 16일 (목) 오후 5:48, Namjae Jeon <linkinjeon@kernel.org>님이 작성:
>
> Set ipv4 and ipv6 address in FSCTL_QUERY_NETWORK_INTERFACE_INFO.
>
> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>

Acked-by: Hyunchul Lee <hyc.lee@gmail.com>

> ---
>  v2:
>    - move buffer check to under ipv6_retry to validate overflow.
>
>  fs/ksmbd/smb2pdu.c | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
> index 2ff4f813026e..0fbb62f9d509 100644
> --- a/fs/ksmbd/smb2pdu.c
> +++ b/fs/ksmbd/smb2pdu.c
> @@ -7224,15 +7224,10 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
>         struct sockaddr_storage_rsp *sockaddr_storage;
>         unsigned int flags;
>         unsigned long long speed;
> -       struct sockaddr_in6 *csin6 = (struct sockaddr_in6 *)&conn->peer_addr;
>
>         rtnl_lock();
>         for_each_netdev(&init_net, netdev) {
> -               if (out_buf_len <
> -                   nbytes + sizeof(struct network_interface_info_ioctl_rsp)) {
> -                       rtnl_unlock();
> -                       return -ENOSPC;
> -               }
> +               bool ipv4_set = false;
>
>                 if (netdev->type == ARPHRD_LOOPBACK)
>                         continue;
> @@ -7240,6 +7235,12 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
>                 flags = dev_get_flags(netdev);
>                 if (!(flags & IFF_RUNNING))
>                         continue;
> +ipv6_retry:
> +               if (out_buf_len <
> +                   nbytes + sizeof(struct network_interface_info_ioctl_rsp)) {
> +                       rtnl_unlock();
> +                       return -ENOSPC;
> +               }
>
>                 nii_rsp = (struct network_interface_info_ioctl_rsp *)
>                                 &rsp->Buffer[nbytes];
> @@ -7272,8 +7273,7 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
>                                         nii_rsp->SockAddr_Storage;
>                 memset(sockaddr_storage, 0, 128);
>
> -               if (conn->peer_addr.ss_family == PF_INET ||
> -                   ipv6_addr_v4mapped(&csin6->sin6_addr)) {
> +               if (!ipv4_set) {
>                         struct in_device *idev;
>
>                         sockaddr_storage->Family = cpu_to_le16(INTERNETWORK);
> @@ -7284,6 +7284,9 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
>                                 continue;
>                         sockaddr_storage->addr4.IPv4address =
>                                                 idev_ipv4_address(idev);
> +                       nbytes += sizeof(struct network_interface_info_ioctl_rsp);
> +                       ipv4_set = true;
> +                       goto ipv6_retry;
>                 } else {
>                         struct inet6_dev *idev6;
>                         struct inet6_ifaddr *ifa;
> @@ -7305,9 +7308,8 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,
>                                 break;
>                         }
>                         sockaddr_storage->addr6.ScopeId = 0;
> +                       nbytes += sizeof(struct network_interface_info_ioctl_rsp);
>                 }
> -
> -               nbytes += sizeof(struct network_interface_info_ioctl_rsp);
>         }
>         rtnl_unlock();
>
> --
> 2.25.1
>


-- 
Thanks,
Hyunchul

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

end of thread, other threads:[~2021-12-16 13:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-16  1:37 [PATCH v2 1/2] ksmbd: set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO Namjae Jeon
2021-12-16  1:37 ` [PATCH v2 2/2] ksmbd: set both ipv4 and ipv6 " Namjae Jeon
2021-12-16 13:20   ` Hyunchul Lee
2021-12-16 13:11 ` [PATCH v2 1/2] ksmbd: set RSS capable " Hyunchul Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox