Skip to content

Commit e6bb919

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: limit repeated connections from clients with the same IP
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 <[email protected]> Cc: [email protected] Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent a6c015b commit e6bb919

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

fs/smb/server/connection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct ksmbd_conn {
4646
struct mutex srv_mutex;
4747
int status;
4848
unsigned int cli_cap;
49+
__be32 inet_addr;
4950
char *request_buf;
5051
struct ksmbd_transport *transport;
5152
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;
@@ -230,6 +231,8 @@ static int ksmbd_kthread_fn(void *p)
230231
{
231232
struct socket *client_sk = NULL;
232233
struct interface *iface = (struct interface *)p;
234+
struct inet_sock *csk_inet;
235+
struct ksmbd_conn *conn;
233236
int ret;
234237

235238
while (!kthread_should_stop()) {
@@ -248,6 +251,20 @@ static int ksmbd_kthread_fn(void *p)
248251
continue;
249252
}
250253

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

0 commit comments

Comments
 (0)