[klibc] malloc: Fail if requested size > PTRDIFF_MAX
authorBen Hutchings <ben@decadent.org.uk>
Wed, 28 Apr 2021 02:03:49 +0000 (04:03 +0200)
committerBen Hutchings <benh@debian.org>
Fri, 30 Apr 2021 01:05:23 +0000 (02:05 +0100)
commit3c744358e92b3475e351e6d9b3b7c6882de9f18c
tree4989ebb79b8082eedd6968295fee0f19a4c9b410
parentd898e3f5ca14eeb41f2e3d211b649afbd4e27860
[klibc] malloc: Fail if requested size > PTRDIFF_MAX

Origin: https://git.kernel.org/pub/scm/libs/klibc/klibc.git/commit/?id=a31ae8c508fc8d1bca4f57e9f9f88127572d5202
Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2021-31873

malloc() adds some overhead to the requested size, which may result in
an integer overflow and subsequent buffer overflow if it is close to
SIZE_MAX.  It should fail if size is large enough for this to happen.

Further, it's not legal for a C object to be larger than
PTRDIFF_MAX (half of SIZE_MAX) as pointer arithmetic within it could
overflow.  So return failure immediately if size is greater than that.

CVE-2021-31873

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Name 0036-klibc-malloc-Fail-if-requested-size-PTRDIFF_MAX.patch
usr/klibc/malloc.c