From patchwork Mon Apr 17 12:13:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John David Anglin X-Patchwork-Id: 751294 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w66cF5kD1z9s0Z for ; Mon, 17 Apr 2017 22:13:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Tx9gf7L4"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:mime-version:content-type:from :in-reply-to:date:cc:message-id:references:to; q=dns; s=default; b= VpyEq3bAINwjlsLL+SD3pQxyDO3b54f3cNpCMWvCZ6vudI631B+kGnBQi1rakpNN 8Bh1wTrJN6oOGEwS1RRQbxnjsMKCaqzRGRYS/WuNvJ21Bu3DVLwcNm2sZnUM04tZ xt5C0ZOTX7/Rt00UVVZZjw3BFdDO171/pqAqB+Iw07U= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:mime-version:content-type:from :in-reply-to:date:cc:message-id:references:to; s=default; bh=/WW nyP5tDxriGxFPtsXiLXD1vz8=; b=Tx9gf7L4bMVqdSmowRoq+ftvh4llOYWfap/ nKbhpd5KnyH0zMe7NcebSmEzFKmwvqg07FlZzfnJTCPNNF87lw7pfA3JGCzWFyKs Dpp9/GtOn7GUataVUYTxTSU91S2dsJZkybr4sXw4jupfyaTsBDBCg4Y7i8BD5WJo EgIo8meQ= 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-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@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) From: John David Anglin In-Reply-To: <87mvbgnmm2.fsf@linux-m68k.org> Date: Mon, 17 Apr 2017 08:13:22 -0400 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 On 2017-04-16, at 4:06 PM, Andreas Schwab wrote: > On Apr 16 2017, John David Anglin wrote: > >> + char *new_guard = (char *)(((uintptr_t) pd - guardsize) & ~pagesize_m1); >> + char *old_guard = (char *)(((uintptr_t) pd - pd->guardsize) & ~pagesize_m1); > > The lines are too long. The long lines are fixed in this version. Otherwise, unchanged. Dave --- John David Anglin dave.anglin@bell.net 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, struct pthread **pdp, prot) != 0) goto mprot_error; #elif _STACK_GROWS_UP - if (mprotect ((char *) pd - pd->guardsize, - pd->guardsize - guardsize, prot) != 0) + char *new_guard = (char *)(((uintptr_t) pd - guardsize) + & ~pagesize_m1); + char *old_guard = (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) != 0) goto mprot_error; #endif