Skip to content

Commit 7a64238

Browse files
kalofoliyoe
authored andcommitted
Fix nbd-server infinite loop for TLS
When the nbd-client disconnects from a TLS connection, the gnutls_record_recv function will return a zero value. Due to a faulty/missing check, this causes the readit_tls call to enter an infinite loop, with all terrible consequences that this has. This is a very problematic bug that causes a full CPU usage, and is only treatable by killing the nbd-server. This fix adds the missing check and an appropriate message that terminates the forked server child graceously. Signed-off-by: Janis Kalofolias <code@kalofolias.de>
1 parent 17043b0 commit 7a64238

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

nbd-server.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ static int readit_tls(gnutls_session_t s, void *buf, size_t len) {
333333
m = g_strdup_printf("could not receive data: %s", gnutls_strerror(res));
334334
err_nonfatal(m);
335335
return -1;
336+
} else if(res == 0) {
337+
nbd_err("TLS End of data: Remote connection closed.");
336338
} else {
337339
len -= res;
338340
buf += res;

0 commit comments

Comments
 (0)