Skip to content

Commit 83dcedd

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: fix infinite loop in ksmbd_conn_handler_loop()
If kernel_recvmsg() return -EAGAIN in ksmbd_tcp_readv() and go round again, It will cause infinite loop issue. And all threads from next connections would be doing that. This patch add max retry count(2) to avoid it. kernel_recvmsg() will wait during 7sec timeout and try to retry two time if -EAGAIN is returned. And add flags of kvmalloc to __GFP_NOWARN and __GFP_NORETRY to disconnect immediately without retrying on memory alloation failure. Fixes: 0626e66 ("cifsd: add server handler for central processing and tranport layers") Cc: [email protected] Reported-by: [email protected] # ZDI-CAN-18259 Reviewed-by: Sergey Senozhatsky <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 797805d commit 83dcedd

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

fs/ksmbd/connection.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,12 @@ int ksmbd_conn_handler_loop(void *p)
316316

317317
/* 4 for rfc1002 length field */
318318
size = pdu_size + 4;
319-
conn->request_buf = kvmalloc(size, GFP_KERNEL);
319+
conn->request_buf = kvmalloc(size,
320+
GFP_KERNEL |
321+
__GFP_NOWARN |
322+
__GFP_NORETRY);
320323
if (!conn->request_buf)
321-
continue;
324+
break;
322325

323326
memcpy(conn->request_buf, hdr_buf, sizeof(hdr_buf));
324327
if (!ksmbd_smb_request(conn))

fs/ksmbd/transport_tcp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ static int ksmbd_tcp_readv(struct tcp_transport *t, struct kvec *iov_orig,
295295
struct msghdr ksmbd_msg;
296296
struct kvec *iov;
297297
struct ksmbd_conn *conn = KSMBD_TRANS(t)->conn;
298+
int max_retry = 2;
298299

299300
iov = get_conn_iovec(t, nr_segs);
300301
if (!iov)
@@ -321,9 +322,11 @@ static int ksmbd_tcp_readv(struct tcp_transport *t, struct kvec *iov_orig,
321322
} else if (conn->status == KSMBD_SESS_NEED_RECONNECT) {
322323
total_read = -EAGAIN;
323324
break;
324-
} else if (length == -ERESTARTSYS || length == -EAGAIN) {
325+
} else if ((length == -ERESTARTSYS || length == -EAGAIN) &&
326+
max_retry) {
325327
usleep_range(1000, 2000);
326328
length = 0;
329+
max_retry--;
327330
continue;
328331
} else if (length <= 0) {
329332
total_read = -EAGAIN;

0 commit comments

Comments
 (0)