From: u-uy74@aetey.se
To: musl@lists.openwall.com
Subject: Re: "non-float" malloc (was: incompatibility between libtheora/mmx and musl)
Date: Sun, 2 Oct 2016 13:17:38 +0200 [thread overview]
Message-ID: <20161002111738.GN28325@example.net> (raw)
In-Reply-To: <20161002105950.GM28325@example.net>
On Sun, Oct 02, 2016 at 12:59:50PM +0200, u-uy74@aetey.se wrote:
> Would you mind adding the brk()/stack overlap checking to this variant
> of the code?
Something like (shamelessly cut-n-pasted from expand_heap.c)
--- malloc.c.ori 2016-10-02 13:06:34.407671803 +0200
+++ malloc.c 2016-10-02 13:13:06.787149613 +0200
@@ -60,6 +60,27 @@
#define IS_MMAPPED(c) !((c)->csize & (C_INUSE))
+/* This function returns true if the interval [old,new]
+ * intersects the 'len'-sized interval below &libc.auxv
+ * (interpreted as the main-thread stack) or below &b
+ * (the current stack). It is used to defend against
+ * buggy brk implementations that can cross the stack. */
+
+static int traverses_stack_p(uintptr_t old, uintptr_t new)
+{
+ const uintptr_t len = 8<<20;
+ uintptr_t a, b;
+
+ b = (uintptr_t)libc.auxv;
+ a = b > len ? b-len : 0;
+ if (new>a && old<b) return 1;
+
+ b = (uintptr_t)&b;
+ a = b > len ? b-len : 0;
+ if (new>a && old<b) return 1;
+
+ return 0;
+}
/* Synchronization tools */
@@ -204,7 +225,8 @@
new = mal.brk + n + SIZE_ALIGN + PAGE_SIZE - 1 & -PAGE_SIZE;
n = new - mal.brk;
- if (__brk(new) != new) {
+ if (traverses_stack_p(mal.brk, new) ||
+ __brk(new) != new) {
size_t min = (size_t)PAGE_SIZE << mal.mmap_step/2;
n += -n & PAGE_SIZE-1;
if (n < min) n = min;
Does it look correct?
Regards,
Rune
next prev parent reply other threads:[~2016-10-02 11:17 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-13 18:06 incompatibility between libtheora/mmx and musl ? u-uy74
2016-09-13 19:20 ` Markus Wichmann
2016-09-13 20:41 ` Rich Felker
2016-09-13 20:43 ` Rich Felker
2016-09-14 10:32 ` u-uy74
2016-09-14 11:24 ` Szabolcs Nagy
2016-09-14 14:04 ` u-uy74
2016-09-14 14:28 ` Rich Felker
2016-09-14 14:31 ` Timo Teras
2016-09-14 14:39 ` Rich Felker
2016-09-14 14:40 ` Rich Felker
2016-09-14 14:41 ` Szabolcs Nagy
2016-09-14 15:11 ` u-uy74
2016-10-02 10:59 ` "non-float" malloc (was: incompatibility between libtheora/mmx and musl) u-uy74
2016-10-02 11:17 ` u-uy74 [this message]
2016-10-02 12:08 ` Szabolcs Nagy
2016-10-02 12:24 ` u-uy74
2016-10-02 13:24 ` u-uy74
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=20161002111738.GN28325@example.net \
--to=u-uy74@aetey.se \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).