Fix SOCK_CLOEXEC handling to maintain socktype equality checks#20808
Fix SOCK_CLOEXEC handling to maintain socktype equality checks#20808
Conversation
|
Nice catch. Note that the proposed change will stop affecting the |
As the SOCK_CLOEXEC and SOCK_NONBLOCK get ORed to the socktype, this introduces a SOCKTYPE() macro to use when checking for the specific socket type: DGRAM or STREAM. The macro filters off the non-type related bits to enable the comparison. Follow-up to 0536769
|
@aisle-analyzer augment review |
🔒 Aisle Security Analysis✅ We scanned this PR and did not find any security vulnerabilities. Aisle supplements but does not replace security review. Analyzed PR: #20808 at commit Last updated on: 2026-03-07T10:34:27Z |
🤖 Augment PR SummarySummary: Prevents TCP-specific socket options from being skipped when 🤖 Was this summary useful? React with 👍 or 👎 |
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression in cf_socket_open() where SOCK_CLOEXEC (and potentially SOCK_NONBLOCK) being ORed into addr->socktype caused direct equality checks against SOCK_STREAM/SOCK_DGRAM to fail, skipping TCP-specific socket options and miscomputing connection state.
Changes:
- Introduce a
SOCKTYPE()helper macro to stripSOCK_CLOEXEC/SOCK_NONBLOCKbits before comparing socket types. - Use
SOCKTYPE(ctx->addr.socktype)for TCP detection (SOCK_STREAM) and forsock_connecteddetermination (SOCK_DGRAM).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
socket_open unconditionally ORs SOCK_CLOEXEC into addr->socktype. The same addr structure is later reused in cf_socket_open, which checks ctx->addr.socktype == SOCK_STREAM to decide whether to enable TCP_NODELAY and TCP keepalive. With SOCK_CLOEXEC set, the equality check fails, so TCP-specific options are skipped and ctx->sock_connected is also computed against SOCK_DGRAM with a mismatching value.
Follow-up to 0536769
Found by Codex Security
/cc @ibookstein