From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/6] dlmalloc: fail allocations exceeding MALLOC_MAX_SIZE
Date: Thu, 20 Feb 2025 21:30:29 +0100 [thread overview]
Message-ID: <20250220203032.3350247-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250220203032.3350247-1-a.fatoum@pengutronix.de>
We already enforce a maximum allocation size of LONG_MAX in dlmalloc,
but this is larger than any reasonable allocation size we would have.
Let's reduce it to the new common maximum of SZ_1G.
While at it, enforce this limit for all size and alignment
parameters.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/dlmalloc.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index 731c46b584b0..2b5723e127c4 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -1162,7 +1162,7 @@ void *dlmalloc(size_t bytes)
INTERNAL_SIZE_T nb;
- if ((long) bytes < 0) {
+ if (bytes > MALLOC_MAX_SIZE) {
errno = ENOMEM;
return NULL;
}
@@ -1499,7 +1499,7 @@ void *dlrealloc(void *oldmem, size_t bytes)
}
#endif
- if ((long)bytes < 0) {
+ if (bytes > MALLOC_MAX_SIZE) {
errno = ENOMEM;
return NULL;
}
@@ -1668,7 +1668,7 @@ void *dlmemalign(size_t alignment, size_t bytes)
mchunkptr remainder; /* spare room at end to split off */
long remainder_size; /* its size */
- if ((long) bytes < 0) {
+ if (bytes > MALLOC_MAX_SIZE || alignment > MALLOC_MAX_SIZE) {
errno = ENOMEM;
return NULL;
}
@@ -1753,7 +1753,7 @@ void *dlcalloc(size_t n, size_t elem_size)
mchunkptr oldtop = top;
INTERNAL_SIZE_T oldtopsize = chunksize(top);
- if ((long)n < 0) {
+ if (sz > MALLOC_MAX_SIZE) {
errno = ENOMEM;
return NULL;
}
--
2.39.5
next prev parent reply other threads:[~2025-02-20 20:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-20 20:30 [PATCH 1/6] malloc: define a maximum malloc size Ahmad Fatoum
2025-02-20 20:30 ` [PATCH 2/6] tlsf: fail allocations exceeding MALLOC_MAX_SIZE Ahmad Fatoum
2025-02-20 20:30 ` Ahmad Fatoum [this message]
2025-02-20 20:30 ` [PATCH 4/6] sandbox: libc_malloc: " Ahmad Fatoum
2025-02-20 20:30 ` [PATCH 5/6] dummy_malloc: " Ahmad Fatoum
2025-02-20 20:30 ` [PATCH 6/6] test: self: malloc: adapt to addition of MALLOC_MAX_SIZE Ahmad Fatoum
2025-02-21 12:20 ` [PATCH 1/6] malloc: define a maximum malloc size Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250220203032.3350247-3-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox