Contact Details
arjunaajalahla100@gmail.com (pelioro)
Version
main branch
Description
Found the same sketchy integer overflow pattern in two more files. Check these out:
File 1: wolfcrypt/src/hash.c around line 1957
if (*len < *used + inSz) { // [OVERFLOW]
*msg = XMALLOC(*used + inSz, heap, ...); // [SMALL ALLOC]
}
XMEMCPY(*msg + *used, in, inSz); // [HEAP OVERFLOW]
File 2: wolfcrypt/src/port/ti/ti-hash.c around line 81
if (hash->len < hash->used+len) { // [OVERFLOW]
p = XMALLOC(hash->used+len, NULL, ...); // [SMALL ALLOC]
}
XMEMCPY(hash->msg+hash->used, data, len); // [HEAP OVERFLOW]
Same deal as the SE050 issue (#9951) - if used is near 4GB and len causes addition to wrap around, we get tiny allocation but full write = heap overflow.
How to trigger
Build with hash keep feature:
./configure --enable-hashkeep
# or in user_settings.h:
#define WOLFSSL_HASH_KEEP
For TI hash, need TI hardware with:
Same bug pattern as #9951, just in different files. Low severity but should be patched to keep the code consistent and robust. Better safe than sorry right?
Reproduction steps
Repro steps
Theoretical repro (not really exploitable irl due to memory limits):
- Init hash context
- Keep calling hash update until
used nears 4GB
- Pass
inSz that causes used + inSz to overflow
- Crash - small alloc, big write = heap corruption
Real talk on severity
Suggested fix
Just add overflow check before the addition (same fix as SE050 #9954):
// For hash.c:1957
if (!WC_SAFE_SUM_WORD32(*used, inSz, tmpSz)) {
return BUFFER_E; // overflow would happen, bail out
}
// For ti-hash.c:81
if (!WC_SAFE_SUM_WORD32(hash->used, len, tmpSz)) {
return BAD_FUNC_ARG; // overflow would happen, bail out
}
Relevant log output
Contact Details
arjunaajalahla100@gmail.com (pelioro)
Version
main branch
Description
Found the same sketchy integer overflow pattern in two more files. Check these out:
File 1:
wolfcrypt/src/hash.caround line 1957File 2:
wolfcrypt/src/port/ti/ti-hash.caround line 81Same deal as the SE050 issue (#9951) - if
usedis near 4GB andlencauses addition to wrap around, we get tiny allocation but full write = heap overflow.How to trigger
Build with hash keep feature:
For TI hash, need TI hardware with:
Same bug pattern as #9951, just in different files. Low severity but should be patched to keep the code consistent and robust. Better safe than sorry right?
Reproduction steps
Repro steps
Theoretical repro (not really exploitable irl due to memory limits):
usednears 4GBinSzthat causesused + inSzto overflowReal talk on severity
Suggested fix
Just add overflow check before the addition (same fix as SE050 #9954):
Relevant log output