Skip to content

tools/nolibc: check for overflow in malloc()

Danish Khateeb linux-kselftest lkml 2 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 2 repliesIn review
  2. v12 patches 1 replySuperseded

Changes in v2 from the cover letter

- 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/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2tools/nolibc: stop rounding malloc() sizes up to 4096 bytestools/include/nolibc/stdlib.h+0 -22 replies
2/2tools/nolibc: check for overflow in malloc()tools/include/nolibc/stdlib.h+5 -10 replies

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchWilly Tarreau
1/2R-b
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/2] tools/nolibc: check for overflow in malloc()

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/[email protected]

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

Signature · 1 line
2.55.0