From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 6A6463886C4C for ; Thu, 24 Jun 2021 09:15:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6A6463886C4C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-438-i2fZ0nYOMauzzvCgGelaZg-1; Thu, 24 Jun 2021 05:15:06 -0400 X-MC-Unique: i2fZ0nYOMauzzvCgGelaZg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D448100C660; Thu, 24 Jun 2021 09:15:05 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-228.ams2.redhat.com [10.36.112.228]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A885B61095; Thu, 24 Jun 2021 09:15:04 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella via Libc-alpha Subject: Re: [PATCH v6 1/5] support: Add support_stack_alloc References: <20210623185115.395812-1-adhemerval.zanella@linaro.org> <20210623185115.395812-2-adhemerval.zanella@linaro.org> Date: Thu, 24 Jun 2021 11:15:02 +0200 In-Reply-To: <20210623185115.395812-2-adhemerval.zanella@linaro.org> (Adhemerval Zanella via Libc-alpha's message of "Wed, 23 Jun 2021 15:51:11 -0300") Message-ID: <87pmwblj3d.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jun 2021 09:15:10 -0000 * 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. Thanks, Florian