You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If payload_length exceeds s2n_stuffer_data_available(&conn->in), the subtraction wraps to a very large value, causing s2n_stuffer_wipe_n() to attempt wiping far more data than intended.
The issue chain:
Line 58: uint16_t payload_length = encrypted_length;
Line 85-87: s2n_sub_overflow() computes into uint32_t out, but the result is truncated back to uint16_t payload_length = out;
Line 112: s2n_stuffer_reread(&conn->in) resets the read cursor
Line 121: The subtraction s2n_stuffer_data_available() - payload_length is unguarded and can underflow
Git History
Prior work has addressed related issues in this file but not this specific bug:
Commit 3e8e6bb8b (Oct 2020, "Adding underflow checks Adding underflow checks #2322") added s2n_sub_overflow() for the padding subtraction at line 86 — a related fix, but introduced the uint32_t → uint16_t truncation at line 87 that feeds into this bug.
Commit 4220a4d24 (Apr 2024, "fix: Wipe conn->in on all record parse failures fix: Wipe conn->in on all record parse failures #4499") removed a s2n_stuffer_wipe(&conn->in) from the error path at line 105, but did not address line 121.
The bug at line 121 remains present as of current main.
Summary
In
tls/s2n_record_read_cbc.cline 121, an unsigned integer underflow can occur:If
payload_lengthexceedss2n_stuffer_data_available(&conn->in), the subtraction wraps to a very large value, causings2n_stuffer_wipe_n()to attempt wiping far more data than intended.The issue chain:
uint16_t payload_length = encrypted_length;s2n_sub_overflow()computes intouint32_t out, but the result is truncated back touint16_t payload_length = out;s2n_stuffer_reread(&conn->in)resets the read cursors2n_stuffer_data_available() - payload_lengthis unguarded and can underflowGit History
Prior work has addressed related issues in this file but not this specific bug:
3e8e6bb8b(Oct 2020, "Adding underflow checks Adding underflow checks #2322") addeds2n_sub_overflow()for the padding subtraction at line 86 — a related fix, but introduced theuint32_t→uint16_ttruncation at line 87 that feeds into this bug.4220a4d24(Apr 2024, "fix: Wipe conn->in on all record parse failures fix: Wipe conn->in on all record parse failures #4499") removed as2n_stuffer_wipe(&conn->in)from the error path at line 105, but did not address line 121.The bug at line 121 remains present as of current main.
Suggested Fix
Add an underflow guard before the subtraction:
Also consider fixing the
uint32_t→uint16_ttruncation at line 87:Impact
Could cause memory corruption or denial of service when processing crafted CBC-encrypted TLS records.
Prior Art Search
s2n_record_read_cbc underflow,CBC record underflow,stuffer_wipe_n payload_length,record_read_cbc overflow— no existing reports found.Found during code review.