mirror of
https://github.com/torvalds/linux.git
synced 2026-10-23 23:51:02 +02:00
malloc() adds the size of its header to the requested size without
checking for overflow. For a size within the header size of SIZE_MAX,
the sum wraps around to a few bytes, and malloc() returns a single page
instead of NULL.
calloc() checks its multiplication for overflow, but then passes the
product to malloc(), so calloc(SIZE_MAX, 1) returns a single page too.
So does realloc(ptr, SIZE_MAX).
Such a size is usually a bug in the caller, for instance a length of -1
used as a size_t, and returning a page instead of NULL can turn it into
a heap overflow.
Fail with ENOMEM when adding the header overflows, as glibc does for
sizes this large.
Fixes:
|
||
|---|---|---|
| .. | ||
| asm | ||
| asm-generic | ||
| generated | ||
| io_uring | ||
| linux | ||
| nolibc | ||
| perf | ||
| tools | ||
| trace/events | ||
| uapi | ||
| vdso | ||