From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 42329 invoked by alias); 17 Apr 2017 12:13:24 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 42307 invoked by uid 89); 17 Apr 2017 12:13:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham version=3.3.2 spammy= X-HELO: mtlfep02.bell.net Subject: [PATCH v2] Fix stack memory protection on targets where the stack grows upward Mime-Version: 1.0 (Apple Message framework v1085) Content-Type: multipart/mixed; boundary=Apple-Mail-12-875410393 From: John David Anglin In-Reply-To: <87mvbgnmm2.fsf@linux-m68k.org> Date: Mon, 17 Apr 2017 12:13:00 -0000 Cc: GNU C Library , Carlos O'Donell , Mike Frysinger , Aurelien Jarno , Helge Deller Message-Id: <6F4B764B-DEC3-4A85-91FD-809EF7A4C0D0@bell.net> References: <87mvbgnmm2.fsf@linux-m68k.org> To: Andreas Schwab X-SW-Source: 2017-04/txt/msg00282.txt.bz2 --Apple-Mail-12-875410393 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Content-length: 440 On 2017-04-16, at 4:06 PM, Andreas Schwab wrote: > On Apr 16 2017, John David Anglin wrote: >=20 >> + char *new_guard =3D (char *)(((uintptr_t) pd - guardsize) & ~pagesiz= e_m1); >> + char *old_guard =3D (char *)(((uintptr_t) pd - pd->guardsize) & ~pag= esize_m1); >=20 > The lines are too long. The long lines are fixed in this version. Otherwise, unchanged. Dave -- John David Anglin dave.anglin@bell.net --Apple-Mail-12-875410393 Content-Disposition: attachment; filename=allocatestack-v2.d.txt Content-Type: text/plain; name="allocatestack-v2.d.txt" Content-Transfer-Encoding: quoted-printable Content-length: 1035 2017-04-17 John David Anglin * nptl/allocatestack.c (allocate_stack): Align old and new guard addresses to page boundaries when the stack grows up. diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index e5c5f79a82..595a858861 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -647,8 +647,14 @@ allocate_stack (const struct pthread_attr *attr, struc= t pthread **pdp, prot) !=3D 0) goto mprot_error; #elif _STACK_GROWS_UP - if (mprotect ((char *) pd - pd->guardsize, - pd->guardsize - guardsize, prot) !=3D 0) + char *new_guard =3D (char *)(((uintptr_t) pd - guardsize) + & ~pagesize_m1); + char *old_guard =3D (char *)(((uintptr_t) pd - pd->guardsize) + & ~pagesize_m1); + /* The guard size difference might be > 0, but once rounded + to the nearest page the size difference might be zero. */ + if (new_guard > old_guard + && mprotect (old_guard, new_guard - old_guard, prot) !=3D 0) goto mprot_error; #endif =20 --Apple-Mail-12-875410393--