mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] tools/nolibc: check for overflow in malloc()
@ 2026-09-26 15:24 Danish Khateeb
  2026-09-26 15:24 ` [PATCH v2 1/2] tools/nolibc: stop rounding malloc() sizes up to 4096 bytes Danish Khateeb
  2026-09-26 15:24 ` [PATCH v2 2/2] tools/nolibc: check for overflow in malloc() Danish Khateeb
  0 siblings, 2 replies; 5+ messages in thread
From: Danish Khateeb @ 2026-09-26 15:24 UTC (permalink / raw)
  To: Willy Tarreau, Thomas Weißschuh
  Cc: Shuah Khan, linux-kselftest, linux-kernel, Danish Khateeb

malloc() does not check the addition of its header size for overflow,
so malloc(SIZE_MAX), calloc(SIZE_MAX, 1) and realloc(ptr, SIZE_MAX)
return a single page instead of NULL.

As suggested by Thomas, patch 1 drops the rounding to 4096 bytes, and
patch 2 adds the overflow check on top.

Tested on x86_64 (GCC and clang), i386, and on arm, arm64 and sparc64
under qemu-user:

- nolibc-test: no failures, with patch 1 alone and with the series.

- A separate program: malloc(), calloc() and realloc() with sizes close
  to SIZE_MAX fail with ENOMEM, and free() still unmaps every page.

Changes in v2:
- Drop the rounding in a separate patch, instead of checking it for
  overflow (Thomas)
- Drop the test patch (Thomas)
- Link to v1: https://lore.kernel.org/r/20260926134332.58184-1-danishkhateeb03@gmail.com

Danish Khateeb (2):
  tools/nolibc: stop rounding malloc() sizes up to 4096 bytes
  tools/nolibc: check for overflow in malloc()

 tools/include/nolibc/stdlib.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)


base-commit: 0e1c44b472e1ec21efdad1df21b10e5c568b65b5
-- 
2.55.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-26 17:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-26 15:24 [PATCH v2 0/2] tools/nolibc: check for overflow in malloc() Danish Khateeb
2026-09-26 15:24 ` [PATCH v2 1/2] tools/nolibc: stop rounding malloc() sizes up to 4096 bytes Danish Khateeb
2026-09-26 15:50   ` Thomas Weißschuh
2026-09-26 17:14     ` Willy Tarreau
2026-09-26 15:24 ` [PATCH v2 2/2] tools/nolibc: check for overflow in malloc() Danish Khateeb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®