-
Notifications
You must be signed in to change notification settings - Fork 947
Closed
Labels
Description
Contact Details
arjunaajalahla100@gmail.com (pelioro)
Version
current branch
Description
Yo, found a sketchy integer overflow in the SE050 hash code. Check this out at wolfcrypt/src/port/nxp/se050_port.c around line 275:
if (se050Ctx->len < se050Ctx->used + len) { // overflow could happen here
tmp = XMALLOC(se050Ctx->used + len, ...); // allocates less than expected
}
XMEMCPY(se050Ctx->msg + se050Ctx->used, data, len); // writes too muchSo basically if se050Ctx->used is like 4GB-ish (0xFFFFFFF0) and len is small, the addition wraps around and we allocate tiny buffer but copy full data = heap overflow city.
Suggested fix
Just slap an overflow check before the addition:
// Before line 275
if (se050Ctx->used > 0xFFFFFFFFU - len) {
return BUFFER_E; // overflow would happen, bail out
}Or use the existing WC_SAFE_SUM_WORD32() macro if available.
Bottom line
Not a critical vuln but should be patched to keep the code robust. Better safe than sorry right?
Reproduction steps
How to trigger
Build with SE050 support:
./configure --enable-se050
# or in user_settings.h:
#define WOLFSSL_SE050_HASHNeed SE050 hardware connected via I2C.
Repro steps
Theoretical repro (not really exploitable irl due to hardware limits):
- Init hash with
se050_hash_init() - Keep calling
se050_hash_update()untilusednears 4GB - Pass
lenthat causesused + lento overflow - BOOM - small alloc, big write = heap corruption
- Impact: Low-ish - SE050 max buffer is like 200KB, so hitting 4GB is basically impossible
- Risk: Still worth fixing for defense-in-depth
- Exploitable: Nah, not really, but it's bad practice to not check for overflow
Relevant log output
Reactions are currently unavailable