From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>,
Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH v6 1/5] support: Add support_stack_alloc
Date: Thu, 24 Jun 2021 08:33:35 -0300 [thread overview]
Message-ID: <a3b9ab04-45b1-a29c-fc8a-ef857b2a1e66@linaro.org> (raw)
In-Reply-To: <87pmwblj3d.fsf@oldenburg.str.redhat.com>
On 24/06/2021 06:15, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
>
>> diff --git a/support/support_stack_alloc.c b/support/support_stack_alloc.c
>> new file mode 100644
>> index 0000000000..08323f43d5
>> --- /dev/null
>> +++ b/support/support_stack_alloc.c
>> @@ -0,0 +1,76 @@
>
>> + /* The guard bands need to be large enough to intercept offset
>> + accesses from a stack address that might otherwise hit another
>> + mapping. Make them at least twice as big as the stack itself, to
>> + defend against an offset by the entire size of a large
>> + stack-allocated array. The minimum is 1MiB, which is arbitrarily
>> + chosen to be larger than any "typical" wild pointer offset.
>> + Again, no matter what the number is, round it up to a whole
>> + number of pages. */
>> + size_t guardsize = roundup (MAX (2 * stacksize, 1024 * 1024), pagesize);
>> + size_t alloc_size = guardsize + stacksize + guardsize;
>> + /* Use MAP_NORESERVE so that RAM will not be wasted on the guard
>> + bands; touch all the pages of the actual stack before returning,
>> + so we know they are allocated. */
>> + void *alloc_base = xmmap (0,
>> + alloc_size,
>> + PROT_NONE,
>> + MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|MAP_STACK,
>> + -1);
>> + xmprotect (alloc_base + guardsize, stacksize, PROT_READ | PROT_WRITE);
>> + memset (alloc_base + guardsize, 0xA5, stacksize);
>> + return (struct support_stack) { alloc_base + guardsize,
>> + stacksize, guardsize };
>> +}
>
> Missing _STACK_GROWS_DOWN/_STACK_GROWS_UP support for guard location
> handling, and missing executable stack handling (in case it's needed on
> Hurd for trampolines; I'm not sure what the current state there is).
>
> But I see it was already missing, so maybe that's not a big deal.
It seems a worth addition, I will update the patch.
next prev parent reply other threads:[~2021-06-24 11:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-23 18:51 [PATCH v6 0/5] Add close_range, closefrom, and posix_spawn_file_actions_closefrom_np Adhemerval Zanella
2021-06-23 18:51 ` [PATCH v6 1/5] support: Add support_stack_alloc Adhemerval Zanella
2021-06-24 9:15 ` Florian Weimer
2021-06-24 11:33 ` Adhemerval Zanella [this message]
2021-06-23 18:51 ` [PATCH v6 2/5] support: Add xclone Adhemerval Zanella
2021-06-24 9:15 ` Florian Weimer
2021-06-23 18:51 ` [PATCH v6 3/5] linux: Add close_range Adhemerval Zanella
2021-06-27 17:23 ` Florian Weimer
2021-06-23 18:51 ` [PATCH v6 4/5] io: Add closefrom [BZ #10353] Adhemerval Zanella
2021-07-03 14:45 ` Jonathon Anderson
2021-07-05 20:26 ` Adhemerval Zanella
2021-07-06 11:37 ` Florian Weimer
2021-06-23 18:51 ` [PATCH v6 5/5] posix: Add posix_spawn_file_actions_closefrom_np Adhemerval Zanella
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=a3b9ab04-45b1-a29c-fc8a-ef857b2a1e66@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).