Skip to content

Comments

ktls: harden Linux recv path#28861

Closed
MegaManSec wants to merge 5 commits intoopenssl:masterfrom
MegaManSec:24
Closed

ktls: harden Linux recv path#28861
MegaManSec wants to merge 5 commits intoopenssl:masterfrom
MegaManSec:24

Conversation

@MegaManSec
Copy link
Contributor

@MegaManSec MegaManSec commented Oct 11, 2025

  • zero the 5 prepended TLS header bytes before recvmsg to avoid stale header bytes when no TLS_GET_RECORD_TYPE cmsg is delivered

  • require MSG_EOR and reject MSG_CTRUNC to avoid treating partial records as complete

  • drop subtraction of EVP_GCM_TLS_TAG_LEN from msg_iov.iov_len (kernel already strips the tag). Restores full plaintext capacity and matches the FreeBSD path

Copy link
Contributor

@Sashan Sashan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please provide a core file. I just want to be sure this change has desired effect. thanks.

Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the fix FreeBSD unaligned write promised by the title?


ret = recvmsg(fd, &msg, 0);
if (ret < 0)
if (ret <= 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? A 0 return value from recvmsg means we successfully received a TLS record with 0 bytes in it. But that's ok. That's a success. We should probably let the upper layers figure out what to do with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it? recv(2) states:

  When a stream socket peer has performed an orderly shutdown, the
  return value will be 0 (the traditional "end-of-file" return).

and

  Datagram sockets in various domains (e.g., the UNIX and Internet
  domains) permit zero-size datagrams.  When such a datagram is
  received, the return value is 0.

kTLS runs over TCP, so the zero-sized datagram doesn't seem relevant here.

/* returned length is limited to msg_iov.iov_len above */
p[3] = (ret >> 8) & 0xff;
p[4] = ret & 0xff;
ret += prepend_length;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should just return immediately here and return -1 in the fall through case below. It really makes very little sense in returning success, where we have not prepended the record header. This would also make the memset that you added above redundant.

@mattcaswell mattcaswell added branch: master Applies to master branch approval: review pending This pull request needs review by a committer triaged: cleanup The issue/pr deals with cleanup of comments/docs not altering code significantly tests: exempted The PR is exempt from requirements for testing labels Oct 14, 2025
@openssl-machine
Copy link
Collaborator

This PR is in a state where it requires action by @openssl/committers but the last update was 30 days ago

@t8m t8m added waiting-for: contributor response This pull request is awaiting a response by the contributor and removed approval: review pending This pull request needs review by a committer labels Nov 14, 2025
@t8m
Copy link
Member

t8m commented Nov 14, 2025

ping @MegaManSec there are comments.

@MegaManSec MegaManSec changed the title ktls: harden Linux recv path and fix FreeBSD unaligned write ktls: harden Linux recv path Dec 5, 2025
@MegaManSec
Copy link
Contributor Author

I don't see the fix FreeBSD unaligned write promised by the title?

Fixed (by removing it from the title and description). Originally I was going to submit this PR with #28860 combined, but decided to de-couple, but forgot to update the actual PR.

@mattcaswell mattcaswell added the approval: review pending This pull request needs review by a committer label Dec 5, 2025
@mattcaswell mattcaswell requested review from Sashan and t8m December 5, 2025 08:46
@t8m t8m added triaged: refactor The issue/pr requests/implements refactoring approval: done This pull request has the required number of approvals and removed triaged: cleanup The issue/pr deals with cleanup of comments/docs not altering code significantly approval: review pending This pull request needs review by a committer waiting-for: contributor response This pull request is awaiting a response by the contributor labels Dec 5, 2025
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Dec 6, 2025
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@t8m t8m closed this Dec 11, 2025
@t8m t8m reopened this Dec 11, 2025
openssl-machine pushed a commit that referenced this pull request Dec 11, 2025
- drop tag subtraction in recv buffer sizing
- enforce MSG_EOR and reject MSG_CTRUNC
- zero prepended header bytes before recvmsg

Signed-off-by: Joshua Rogers <[email protected]>

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #28861)
@t8m
Copy link
Member

t8m commented Dec 11, 2025

Squashed, applied clang-reformat and merged to the master branch. Thank you for your contribution.

@t8m t8m closed this Dec 11, 2025
cxx194832 pushed a commit to cxx194832/openssl that referenced this pull request Dec 12, 2025
- drop tag subtraction in recv buffer sizing
- enforce MSG_EOR and reject MSG_CTRUNC
- zero prepended header bytes before recvmsg

Signed-off-by: Joshua Rogers <[email protected]>

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#28861)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch tests: exempted The PR is exempt from requirements for testing triaged: refactor The issue/pr requests/implements refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants