[openssl/openssl] 92851e: ktls: Fix invalid memory access on retry with movi...

"'Ilya Maximets' via openssl-commits" <[email protected]>
Newsgroups gmane.comp.encryption.openssl.cvs
Message-ID <openssl/openssl/push/refs/heads/openssl-3.5/[email protected]>
  Branch: refs/heads/openssl-3.5
  Home:   https://github.com/openssl/openssl
  Commit: 92851e15db796f17ce93829ede76373f06b511bf
      https://github.com/openssl/openssl/commit/92851e15db796f17ce93829ede76373f06b511bf
  Author: Ilya Maximets <[email protected]>
  Date:   2026-06-01 (Mon, 01 Jun 2026)

  Changed paths:
    M ssl/record/methods/ktls_meth.c
    M ssl/record/methods/tls_common.c
    M test/sslapitest.c

  Log Message:
  -----------
  ktls: Fix invalid memory access on retry with moving write buffer

kTLS write is using application buffer always without a memory copy.
And it completely ignores SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER as a
result.  If the user frees or re-uses the original buffer and retries
the send on SSL_ERROR_WANT_WRITE, the code will read and send the data
from the original already freed buffer sending whatever happens to be
in that memory now and corrupting the message, potentially crashing
the application as well.

Fix by making a copy if we can't send the whole thing right away and
the moving write buffer is configured.

This preserves the zero-copy semantics for the happy path and avoids
the invalid memory access and data corruption when retry is necessary.
The copy is done in the common code as it is hard to preserve the
zero-copy behavior otherwise.

Test is added that reproduces the issue.  It may be possible to modify
the existing kTLS test to conditionally enable the modes and do the
BIO swap, but it feels like the issue deserves a separate one.

The test doesn't rely on any specific cypher or TLS version, so only
one combination is checked, but it should be enough.

There is no TLS_BUFFER_set_len() and the original kTLS code never
sets it, so not setting it on the copy either for now.

Fixes: 50ec750567e0 "ssl: Linux TLS Tx Offload"
Fixes #21202

Assisted-by: claude-opus-4.6

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Eugene Syromiatnikov <[email protected]>
MergeDate: Mon Jun  1 07:29:48 2026
(Merged from https://github.com/openssl/openssl/pull/31146)



To unsubscribe from these emails, change your notification settings at https://github.com/openssl/openssl/settings/notifications

-- 
You received this message because you are subscribed to the Google Groups "openssl-commits" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/a/openssl.org/d/msgid/openssl-commits/openssl/openssl/push/refs/heads/openssl-3.5/c7732a-92851e%40github.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.