[klibc] cpio: Fix possible integer overflow on 32-bit systems
Origin: https://git.kernel.org/pub/scm/libs/klibc/klibc.git/commit/?id=
9b1c91577aef7f2e72c3aa11a27749160bd278ff
Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2021-31872
The maximum name and file sizes in the "new" header format are 32-bit
unsigned values. However, the I/O functions mostly use long for sizes
and offsets, so that sizes >= 2^31 are handled wrongly on 32-bit
systems.
The current GNU cpio code doesn't seem to have this problem, but the
divergence between this version and that is large enough that I can't
simply cherry-pick a fix for it.
As a short-term fix, in read_in_new_ascii(), fail if c_namesize or
c_filesize is > LONG_MAX.
CVE-2021-31872
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Name 0039-klibc-cpio-Fix-possible-integer-overflow-on-32-bit-s.patch
[klibc] calloc: Fail if multiplication overflows
Origin: https://git.kernel.org/pub/scm/libs/klibc/klibc.git/commit/?id=
292650f04c2b5348b4efbad61fb014ed09b4f3f2
Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2021-31870
calloc() multiplies its 2 arguments together and passes the result to
malloc(). Since the factors and product both have type size_t, this
can result in an integer overflow and subsequent buffer overflow.
Check for this and fail if it happens.
CVE-2021-31870
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Name 0037-klibc-calloc-Fail-if-multiplication-overflows.patch
[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
[klibc] malloc: Set errno on failure
Origin: https://git.kernel.org/pub/scm/libs/klibc/klibc.git/commit/?id=
7f6626d12daa2f1efd9953d1f4ba2065348dc5cd
malloc() is specified to set errno = ENOMEM on failure, so do that.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Name 0035-klibc-malloc-Set-errno-on-failure.patch