Skip to content

[3.6] Fix IP SAN handling in cert_write and cert_req - #11004

Open
JayOfTheKeyboard wants to merge 2 commits into
Mbed-TLS:mbedtls-3.6from
JayOfTheKeyboard:fix-x509-programs-ip-san-3.6
Open

JayOfTheKeyboard wants to merge 2 commits into
Mbed-TLS:mbedtls-3.6from
JayOfTheKeyboard:fix-x509-programs-ip-san-3.6

Conversation

@JayOfTheKeyboard

Copy link
Copy Markdown

Description

Backport of #11002 to the mbedtls-3.6 branch.

The cert_write and cert_req sample programs pass a 4-byte buffer to mbedtls_x509_crt_parse_cn_inet_pton(), which writes 16 bytes for an IPv6 address, so san=IP:2001:db8::1 overflows the stack. Every IP: entry also shared that one buffer, so san=IP:1.2.3.4;IP:5.6.7.8 wrote 5.6.7.8 twice. The two commits cherry-pick cleanly from #11002. See that PR for the details.

Tested the same way on this branch: an ASan and UBSan build of both programs, five san inputs, with the SAN decoded by openssl. 6 of 10 checks fail on the parent and 10 of 10 pass with this change. code_style.py and assemble_changelog.py pass, and both programs build with gcc and MBEDTLS_FATAL_WARNINGS=ON.

PR checklist

mbedtls_x509_crt_parse_cn_inet_pton() requires a 16-byte buffer and
writes 16 bytes for an IPv6 address, but both programs passed a 4-byte
one. Use a 16-byte buffer and record the length the function returns
instead of sizeof(ip), so IPv6 addresses are encoded as 16 bytes.

Signed-off-by: Jeremy Levartovsky <[email protected]>
Every IP entry in the san list pointed at the same buffer, and the list
is only written once all entries are parsed, so san=IP:1.2.3.4;IP:5.6.7.8
produced two copies of 5.6.7.8. Give each IP entry its own buffer and
free it with the rest of the list.

Signed-off-by: Jeremy Levartovsky <[email protected]>
@gilles-peskine-arm gilles-peskine-arm added bug component-x509 size-s Estimated task size: small (~2d) priority-medium Medium priority - this can be reviewed as time permits needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review labels Oct 19, 2026

@rohankl-arm rohankl-arm left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, faithful backport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug component-x509 needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review priority-medium Medium priority - this can be reviewed as time permits size-s Estimated task size: small (~2d)

Projects

Status: In Development

Development

Successfully merging this pull request may close these issues.

3 participants