Skip to content

Commit cb092fc

Browse files
namjaejeongregkh
authored andcommitted
ksmbd: limit repeated connections from clients with the same IP
commit e6bb919 upstream. Repeated connections from clients with the same IP address may exhaust the max connections and prevent other normal client connections. This patch limit repeated connections from clients with the same IP. Reported-by: tianshuo han <hantianshuo233@gmail.com> Cc: stable@vger.kernel.org Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ee42cb1 commit cb092fc

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

fs/smb/server/connection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct ksmbd_conn {
4545
struct mutex srv_mutex;
4646
int status;
4747
unsigned int cli_cap;
48+
__be32 inet_addr;
4849
char *request_buf;
4950
struct ksmbd_transport *transport;
5051
struct nls_table *local_nls;

fs/smb/server/transport_tcp.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static struct tcp_transport *alloc_transport(struct socket *client_sk)
8787
return NULL;
8888
}
8989

90+
conn->inet_addr = inet_sk(client_sk->sk)->inet_daddr;
9091
conn->transport = KSMBD_TRANS(t);
9192
KSMBD_TRANS(t)->conn = conn;
9293
KSMBD_TRANS(t)->ops = &ksmbd_tcp_transport_ops;
@@ -226,6 +227,8 @@ static int ksmbd_kthread_fn(void *p)
226227
{
227228
struct socket *client_sk = NULL;
228229
struct interface *iface = (struct interface *)p;
230+
struct inet_sock *csk_inet;
231+
struct ksmbd_conn *conn;
229232
int ret;
230233

231234
while (!kthread_should_stop()) {
@@ -244,6 +247,20 @@ static int ksmbd_kthread_fn(void *p)
244247
continue;
245248
}
246249

250+
/*
251+
* Limits repeated connections from clients with the same IP.
252+
*/
253+
csk_inet = inet_sk(client_sk->sk);
254+
down_read(&conn_list_lock);
255+
list_for_each_entry(conn, &conn_list, conns_list)
256+
if (csk_inet->inet_daddr == conn->inet_addr) {
257+
ret = -EAGAIN;
258+
break;
259+
}
260+
up_read(&conn_list_lock);
261+
if (ret == -EAGAIN)
262+
continue;
263+
247264
if (server_conf.max_connections &&
248265
atomic_inc_return(&active_num_conn) >= server_conf.max_connections) {
249266
pr_info_ratelimited("Limit the maximum number of connections(%u)\n",

0 commit comments

Comments
 (0)