Skip to content

Commit

Permalink
Fix nbd-server infinite loop for TLS
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kalofoli authored and yoe committed Dec 20, 2024
1 parent 17043b0 commit 7a64238
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nbd-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ static int readit_tls(gnutls_session_t s, void *buf, size_t len) {
m = g_strdup_printf("could not receive data: %s", gnutls_strerror(res));
err_nonfatal(m);
return -1;
} else if(res == 0) {
nbd_err("TLS End of data: Remote connection closed.");
} else {
len -= res;
buf += res;
Expand Down

0 comments on commit 7a64238

Please sign in to comment.