Skip to content

io/channel-websock: fix an unauthenticated crash in the handshake

Denis V. Lunev qemu-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 11 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6io/channel-socket: do not treat a zero length write as an errorio/channel-socket.c+1 -11 reply
2/6io/channel-websock: send an HTTP 400 when the greeting has no spaceio/channel-websock.c+1 -11 reply
3/6io/channel-websock: handle a blocked write during the handshakeio/channel-websock.c+5 -01 reply
4/6tests/unit: add websock handshake testtests/unit/meson.build tests/unit/test-io-channel-websock.c+106 -01 reply
5/6io/channel-websock: do not lose QIO_CHANNEL_ERR_BLOCK while readingio/channel-websock.c+3 -01 reply
6/6tests/unit: cover blocked IO during the websock handshaketests/unit/test-io-channel-websock.c+147 -31 reply

Reviews trailers per patch

All 6 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchMarc-André LureauDaniel P. Berrangé
SeriesR-b
1/6R-b
2/6R-b
3/6R-b
4/6R-b
5/6R-b
6/6R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/6] io/channel-websock: fix an unauthenticated crash in the handshake

A client which can reach a VNC websocket port crashes QEMU before it has authenticated, by sending an HTTP greeting whose request line holds no space:

printf 'stats\r\nx\r\n\r\n' | nc $host $port

Three defects line up to produce it. The greeting is rejected without queueing a response, so the handshake goes on to flush an empty buffer. A zero length sendmsg() succeeds and returns 0, which qio_channel_socket_writev() mistakes for failure and reports as QIO_CHANNEL_ERR_BLOCK with errp left unset. The handshake treats every negative return as fatal and hands that NULL Error to error_get_pretty(). Patches 1 to 3 close the three links.

Patch 5 is the same NULL Error on the read side of the handshake, where ERR_BLOCK is folded into -1. It is reachable for a wss:// client, whose master channel is then a TLS channel: a wakeup carrying only part of a record makes gnutls report EAGAIN.

The tests drive the handshake through a channel which reports ERR_BLOCK on demand, covering both directions. No test reproduces the original crash itself, which turns on a stale errno and is not reliably reproducible in a unit test. What they pin is that a 400 is emitted and that ERR_BLOCK no longer reaches error_get_pretty().

CC Daniel P. Berrangé <[email protected]>
CC Marc-André Lureau <[email protected]>

Denis V. Lunev (6):
io/channel-socket: do not treat a zero length write as an error io/channel-websock: send an HTTP 400 when the greeting has no space io/channel-websock: handle a blocked write during the handshake tests/unit: add websock handshake test io/channel-websock: do not lose QIO_CHANNEL_ERR_BLOCK while reading tests/unit: cover blocked IO during the websock handshake

 io/channel-socket.c                  |   2 +-
 io/channel-websock.c                 |  10 +-
 tests/unit/meson.build               |   1 +
 tests/unit/test-io-channel-websock.c | 249 +++++++++++++++++++++++++++
 4 files changed, 260 insertions(+), 2 deletions(-)
 create mode 100644 tests/unit/test-io-channel-websock.c
Signature · 1 line
2.53.0