Skip to content

ktls: Accept anonymous EXT_SFBUF mbufs on receive (fixes #673) - #674

Merged
laffer1 merged 1 commit into
masterfrom
ktls-rx-sfbuf-anon
Nov 20, 2026
Merged

laffer1 merged 1 commit into
masterfrom
ktls-rx-sfbuf-anon

Conversation

@laffer1

@laffer1 laffer1 commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Fixes #673.

Our CVE-2026-45257 fix (257e33b) makes KTLS receive reject any record that contains an EXT_SFBUF mbuf. The loopback interface doesn't handle unmapped mbufs, so _mb_unmapped_to_ext() turns the sender's encrypted, anonymous M_EXTPG pages into EXT_SFBUF mbufs. Valid records of about a page or more were therefore rejected with EBADMSG on any loopback connection with KTLS on both ends.

This ports FreeBSD 0af1065b3a57 ("ktls: Propagate EPG_FLAG_ANON to mapped mbufs"), FreeBSD's fix for the same regression in its version of the CVE fix (FreeBSD PR 296498):

  • sys/sys/mbuf.h: new EXT_FLAG_SFBUF_ANON.
  • _mb_unmapped_to_ext(): sets EXT_FLAG_SFBUF_ANON when the source pages have EPG_FLAG_ANON.
  • ktls_record_has_shared_mbuf(): accepts EXT_SFBUF mbufs that carry the flag. FreeBSD's check is in ktls_mbuf_crypto_state(); ours is here.

File-backed sendfile pages, the CVE case, are still rejected. They are either non-anonymous M_EXTPG, or EXT_SFBUF without the flag.

This is independent of #672 and merges cleanly either way.

Testing

amd64 GENERIC with INVARIANTS and WITNESS, from master plus this commit, in a bhyve guest with ktls_ocf.ko loaded:

  • ktls_test: 271/281, the same as master. ktls_receive_loopback_sendfile, the CVE regression test from 257e33b, passes. The 10 failures are the ktls_receive_unsupported_*_cbc_* errno cases from tests: ktls_test needs ktls_ocf loaded; CBC receive tests expect EPROTONOSUPPORT #667, which ktls: Build the OCF software backend into the kernel (fixes #667) #672 fixes.

  • KTLS loopback with kernel receive: a guest-only program sends a 400 KiB file through a KTLS loopback connection with kernel KTLS receive on the peer. It covers 8 offset and length mixes (1 byte to 400 KiB, unaligned and page-aligned) and 10 suites (AES-GCM 128/256 and ChaCha20-Poly1305 for TLS 1.2 and 1.3; AES-CBC for TLS 1.0, 1.1 and 1.2).

    Mode What it tests Before (master) After
    rx sendfile → kernel RX AEAD: 36 of 48 runs fail with EBADMSG (every record of 4 KiB or more) 0 failures
    write write(2) → kernel RX AEAD: 36 of 48 runs fail 0 failures
    user sendfile → OpenSSL in userspace 0 failures 0 failures

    CBC runs use userspace decryption in every mode, because KTLS receive doesn't support CBC.

  • No lock-order reversals and no panics during the tests.

🤖 Generated with Claude Code

Summary by Sourcery

Restore KTLS loopback receive support for records backed by anonymous sendfile pages while preserving protection against shared file-backed buffers.

Bug Fixes:

  • Allow valid anonymous KTLS receive buffers to pass through loopback connections without being rejected as malformed records.
  • Continue rejecting non-anonymous sendfile buffers associated with the CVE mitigation.

Enhancements:

  • Propagate anonymous-page metadata when converting unmapped pages to sendfile buffers and use it to distinguish safe KTLS receive buffers.

Otherwise ktls_record_has_shared_mbuf() rejects mbufs created by
_mb_unmapped_to_ext(), which arises when transmitting packets through
an interface that doesn't support unmapped mbufs, and the loopback
interface in particular.  KTLS receive on a loopback connection then
fails with EBADMSG for records of about a page or more, even though
the sender's encrypted pages are anonymous.

Adapted from FreeBSD's fix for the same regression in its version of
the CVE-2026-45257 fix; our check lives in
ktls_record_has_shared_mbuf() (257e33b) rather than
ktls_mbuf_crypto_state().  File-backed sendfile pages are still
rejected.

Fixes:		#673
Fixes:		257e33b ("ktls: reject shared mbufs on receive decrypt")
Obtained from:	FreeBSD 0af1065b3a57
AI-Assisted-by:	Claude Opus 5.5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lucas Holt <luke@foolishgames.com>
@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Define the mbuf flag used to mark SFBUF pages originating from anonymous pages.

  • sys/sys/mbuf.h L606

Implementation

Propagate the anonymous-page marker when converting unmapped mbufs, then allow marked SFBUF mbufs through the KTLS shared-mbuf check while continuing to reject unmarked ones.

  • sys/kern/kern_mbuf.c L1038-1040
  • sys/kern/uipc_ktls.c L1910-1911

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@laffer1
laffer1 merged commit 2d8e69e into master Nov 20, 2026
12 of 16 checks passed
@laffer1
laffer1 deleted the ktls-rx-sfbuf-anon branch November 20, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ktls: receive rejects valid records over loopback (EXT_SFBUF treated as shared)

2 participants