Closed jwinzig-at-hilscher closed 10 months ago
Hi,
Testing this on a 64-bit platform, there is a problem in this reproducer is caused by passing in an int
rather than a size_t
for val_len
. Since this is signed (0xFFFFFFFF == -1
) it is first promoted to 64-bit -1 (0xFFFFFFFFFFFFFFFF
) then converted to a size_t
. This value then overflows to zero.
If I try changing val_len
in the reproducer to be a size_t
I correctly allocate the large amount of memory and then segfault when trying to copy from the (non-existent) buffer.
However, I agree that this will be a problem for 32-bit platforms. I will review the fix.
Summary
When calling the function
mbedtls_x509_set_extension(..)
with the value0xFFFFFFFF
for the parameterval_len
, an internal overflow leads to a segmentation fault.System information
Mbed TLS version (number or commit id): 4aad0ff (current development branch) Operating system and version: Ubuntu 22.04.3 LTS Configuration (if not default, please attach
mbedtls_config.h
): default Compiler and options (if you used a pre-built binary, please indicate how you obtained it): see "Steps to reproduce" Additional environment information: -Expected behavior
Return error (e.g.
MBEDTLS_ERR_X509_BAD_INPUT_DATA
).Actual behavior
Segmentation fault at line 390, when writing a byte to a
NULL
-pointer (cur->val.p
).Steps to reproduce
Call
mbedtls_x509_set_extension(..)
with the value0xFFFFFFFF
for the parameterval_len
. Inmbedtls_x509_set_extension(..)
the valueval_len
is incremented by 1 when callingmbedtls_asn1_store_named_data(..)
. Since it overflows, its has the value0
inside the function. Therefore no buffer is allocated forcur->val.p
and the valueNULL
is assigned to it.Example
programs/x509/set_ext.c:
Build command:
Execution and Output:
Additional information
-