GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||
GeezerVison is showing github.com — Don't spin in SslHandler.wrapMultiple(...) when the engine consumes nothing by allthingssecurity · Pull Request #17728 · netty/netty Conversation
Contributor
Don't spin in SslHandler.wrapMultiple(...) when the engine consumes nothing Motivation:
If such a buffer is flushed before the handshake is done, the
This happens with the JDK and the OpenSSL engines, on the client side (for example Modification:
Result: Writing a large buffer before the handshake is done no longer hangs the event loop when the wrap data size is <= 0 or bigger than 16384.
Prepared with Claude Code on behalf of allthingssecurity. 🤖 Generated with Claude Code
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…othing Motivation: When `setWrapDataSize(...)` is set to a value bigger than the maximum TLS plaintext length (16384) or to a value <= 0, a flushed buffer bigger than 16384 bytes is encrypted by `wrapMultiple(...)`, slice by slice. If such a buffer is flushed before the handshake is done, the `SSLEngine` returns `OK` / `NEED_UNWRAP` without consuming or producing anything. `wrapMultiple(...)` then resets the reader index and tries the same slice again. Nothing is produced, so the out buffer never fills up, and the loop never ends: the event loop spins at 100% CPU, never reads the peer's handshake response and runs no other task. Both the JDK and the OpenSSL engines behave like this, on the client and on the server side. Modification: - Break out of `wrapMultiple(...)` when the engine did not consume anything. `wrap(...)` then keeps the buffer queued and handles the handshake status as it does for buffers that fit into one record, and the data is written once the handshake is done. - Add `ParameterizedSslHandlerTest.testWriteBiggerThanPacketLengthBeforeHandshakeWithLargeWrapDataSize`, which flushes 40000 bytes before the handshake with a wrap data size of -1 and of 64 KiB, completes the handshake and checks that the server receives all bytes. Result: Writing a large buffer before the handshake is done no longer hangs the event loop when a large wrap data size is used. Co-Authored-By: Claude Opus 5.5 <[email protected]>
normanmaurer
reviewed
Uh oh!
There was an error while loading. Please reload this page.
normanmaurer
requested changes
…nor produced anything Motivation: Review feedback: if the engine produced bytes (for example handshake data) without consuming any input, the loop should continue so that data is written, and only an iteration without any progress must end it. Modification: Check bytesProduced() as well as bytesConsumed() before breaking out of the loop. Result: wrapMultiple(...) only stops early when the engine made no progress at all. Co-Authored-By: Claude Opus 5.5 <[email protected]>
normanmaurer
requested changes
Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
✅ All tests passed ✅🏷️ Commit: 6ec3206 Learn more about TestLens at testlens.app/docs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@normanmaurer both suggestions are applied (c98aca9: stop only when the engine neither consumed nor produced; 67b79d4: release the expected buffer), and CI is green. Could you take another look when you have a moment? Prepared with Claude Code on behalf of allthingssecurity |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Could not create auto-port PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Auto-port PR for 5.0: #17821 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Port for 4.1: #17822 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…gine consumes nothing (#17821) Auto-port of #17728 to 5.0 Cherry-picked commit: d18c480 --- Don't spin in SslHandler.wrapMultiple(...) when the engine consumes nothing Motivation: `SslHandler.setWrapDataSize(...)` accepts a value bigger than the maximum TLS plaintext length (16384), and a value <= 0 to write each buffer as is. In both cases a flushed buffer bigger than 16384 bytes is encrypted by `wrapMultiple(...)` (#13551), slice by slice, into one out buffer. If such a buffer is flushed before the handshake is done, the `SSLEngine` returns `OK` / `NEED_UNWRAP` and consumes and produces nothing. `wrapMultiple(...)` then resets the reader index and wraps the same slice again. Its only exits are a `CLOSED` status and a full out buffer, and the out buffer never fills up because nothing is produced. So the loop never ends: - the event loop spins at 100% CPU in `wrapMultiple(...)`, - it never reads the peer's handshake response, so the handshake can't finish, - it runs no other task, so every other channel on that event loop stalls too. This happens with the JDK and the OpenSSL engines, on the client side (for example `writeAndFlush(...)` of a large buffer right after `connect()`) and on the server side (a large write from `channelActive(...)`). With the default wrap data size the buffer is cut into records of at most 16384 bytes before it reaches the engine, so `wrap(...)` handles `NEED_UNWRAP` and keeps the data queued until the handshake is done. Modification: - Break out of `wrapMultiple(...)` when the engine did not consume anything. `wrap(...)` then re-queues the rest of the buffer and handles the handshake status, as it does for a buffer that fits into one record. The pending data is written once the handshake is done. - Add `ParameterizedSslHandlerTest.testWriteBiggerThanPacketLengthBeforeHandshakeWithLargeWrapDataSize` for all provider combinations. It flushes 40000 bytes before the handshake with a wrap data size of -1 and of 64 KiB, completes the handshake between two `EmbeddedChannel`s, and checks that the write succeeds and the server receives all bytes. Result: Writing a large buffer before the handshake is done no longer hangs the event loop when the wrap data size is <= 0 or bigger than 16384. --------- Co-authored-by: allthingssecurity <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
…consumes nothing (#17728) (#17822) Don't spin in SslHandler.wrapMultiple(...) when the engine consumes nothing Motivation: `SslHandler.setWrapDataSize(...)` accepts a value bigger than the maximum TLS plaintext length (16384), and a value <= 0 to write each buffer as is. In both cases a flushed buffer bigger than 16384 bytes is encrypted by `wrapMultiple(...)` (#13551), slice by slice, into one out buffer. If such a buffer is flushed before the handshake is done, the `SSLEngine` returns `OK` / `NEED_UNWRAP` and consumes and produces nothing. `wrapMultiple(...)` then resets the reader index and wraps the same slice again. Its only exits are a `CLOSED` status and a full out buffer, and the out buffer never fills up because nothing is produced. So the loop never ends: - the event loop spins at 100% CPU in `wrapMultiple(...)`, - it never reads the peer's handshake response, so the handshake can't finish, - it runs no other task, so every other channel on that event loop stalls too. This happens with the JDK and the OpenSSL engines, on the client side (for example `writeAndFlush(...)` of a large buffer right after `connect()`) and on the server side (a large write from `channelActive(...)`). With the default wrap data size the buffer is cut into records of at most 16384 bytes before it reaches the engine, so `wrap(...)` handles `NEED_UNWRAP` and keeps the data queued until the handshake is done. Modification: - Break out of `wrapMultiple(...)` when the engine did not consume anything. `wrap(...)` then re-queues the rest of the buffer and handles the handshake status, as it does for a buffer that fits into one record. The pending data is written once the handshake is done. - Add `ParameterizedSslHandlerTest.testWriteBiggerThanPacketLengthBeforeHandshakeWithLargeWrapDataSize` for all provider combinations. It flushes 40000 bytes before the handshake with a wrap data size of -1 and of 64 KiB, completes the handshake between two `EmbeddedChannel`s, and checks that the write succeeds and the server receives all bytes. Result: Writing a large buffer before the handshake is done no longer hangs the event loop when the wrap data size is <= 0 or bigger than 16384. --------- Co-authored-by: Norman Maurer <[email protected]> Co-authored-by: allthingssecurity <[email protected]>
…consumes nothing (netty#17728) (netty#17822) Don't spin in SslHandler.wrapMultiple(...) when the engine consumes nothing Motivation: `SslHandler.setWrapDataSize(...)` accepts a value bigger than the maximum TLS plaintext length (16384), and a value <= 0 to write each buffer as is. In both cases a flushed buffer bigger than 16384 bytes is encrypted by `wrapMultiple(...)` (netty#13551), slice by slice, into one out buffer. If such a buffer is flushed before the handshake is done, the `SSLEngine` returns `OK` / `NEED_UNWRAP` and consumes and produces nothing. `wrapMultiple(...)` then resets the reader index and wraps the same slice again. Its only exits are a `CLOSED` status and a full out buffer, and the out buffer never fills up because nothing is produced. So the loop never ends: - the event loop spins at 100% CPU in `wrapMultiple(...)`, - it never reads the peer's handshake response, so the handshake can't finish, - it runs no other task, so every other channel on that event loop stalls too. This happens with the JDK and the OpenSSL engines, on the client side (for example `writeAndFlush(...)` of a large buffer right after `connect()`) and on the server side (a large write from `channelActive(...)`). With the default wrap data size the buffer is cut into records of at most 16384 bytes before it reaches the engine, so `wrap(...)` handles `NEED_UNWRAP` and keeps the data queued until the handshake is done. Modification: - Break out of `wrapMultiple(...)` when the engine did not consume anything. `wrap(...)` then re-queues the rest of the buffer and handles the handshake status, as it does for a buffer that fits into one record. The pending data is written once the handshake is done. - Add `ParameterizedSslHandlerTest.testWriteBiggerThanPacketLengthBeforeHandshakeWithLargeWrapDataSize` for all provider combinations. It flushes 40000 bytes before the handshake with a wrap data size of -1 and of 64 KiB, completes the handshake between two `EmbeddedChannel`s, and checks that the write succeeds and the server receives all bytes. Result: Writing a large buffer before the handshake is done no longer hangs the event loop when the wrap data size is <= 0 or bigger than 16384. --------- Co-authored-by: Norman Maurer <[email protected]> Co-authored-by: allthingssecurity <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.