From patchwork Fri May 16 22:56:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ondrej Bilka X-Patchwork-Id: 997 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx20.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id 2CCEE3600B4 for ; Fri, 16 May 2014 15:56:17 -0700 (PDT) Received: by homiemail-mx20.g.dreamhost.com (Postfix, from userid 14307373) id D571F41EDC99D; Fri, 16 May 2014 15:56:16 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx20.g.dreamhost.com 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 homiemail-mx20.g.dreamhost.com (Postfix) with ESMTPS id B52F041EDC99B for ; Fri, 16 May 2014 15:56:16 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-transfer-encoding :in-reply-to; q=dns; s=default; b=exdPtQwGWphfOd+pmN9f6l97ZhlcEt RI2xf3mub1EibJGIngn4lVN8b6gStNgUlBNctqcf40tiyJBy7ok8x/T1VgmzlYu4 1mBu4B1WBpFM1KUtfUGijlqa51ZsPb5IR2vh0M3EN0CJtV/gZClVGkGUyIbiF1Sd h3bKLtxUqKtW0= 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:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-transfer-encoding :in-reply-to; s=default; bh=sq0Y8Ok639SQkoNfW+x9w1ytCS0=; b=HfG0 ZVT5BgCvMX3bRpqHKON1hkJd/eQH0P98YVfSzgLa3/6P8Kxo7DlrRKkObsiZJ4C1 7yO6hM96K+0cN3LXpCOdm4w0FX8+3SfmETXBcxhpFdcgsLAih7oOXWT6pnOEKt0A 9BcxUiZhSmawCxw3L/K5gNsRiEEvuNU3PBhbrkQ= Received: (qmail 8680 invoked by alias); 16 May 2014 22:56:14 -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 8667 invoked by uid 89); 16 May 2014 22:56:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, SPF_NEUTRAL autolearn=no version=3.3.2 X-HELO: popelka.ms.mff.cuni.cz Date: Sat, 17 May 2014 00:56:08 +0200 From: =?utf-8?B?T25kxZllaiBCw61sa2E=?= To: Rich Felker Cc: Florian Weimer , Will Newton , Konstantin Serebryany , GNU C Library Subject: Re: why Glibc does not build with clang? Message-ID: <20140516225608.GA17863@domone.podge> References: <53760025.10204@redhat.com> <53760826.6090203@redhat.com> <20140516135304.GA29829@domone.podge> <20140516190504.GF507@brightrain.aerifal.cx> <20140516203140.GA16889@domone.podge> <20140516213200.GG507@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140516213200.GG507@brightrain.aerifal.cx> User-Agent: Mutt/1.5.20 (2009-06-14) X-DH-Original-To: glibc@patchwork.siddhesh.in On Fri, May 16, 2014 at 05:32:00PM -0400, Rich Felker wrote: > On Fri, May 16, 2014 at 10:31:40PM +0200, Ondřej Bílka wrote: > > On Fri, May 16, 2014 at 03:05:04PM -0400, Rich Felker wrote: > > > On Fri, May 16, 2014 at 03:53:04PM +0200, Ondřej Bílka wrote: > > > > On Fri, May 16, 2014 at 02:44:22PM +0200, Florian Weimer wrote: > > > > > On 05/16/2014 02:37 PM, Will Newton wrote: > > > > > > > > > > >I'm curious as to why you want to get rid of alloca? > > > > > > > > > > There's no explicit checking if the stack has room for the requested > > > > > size. It is not always clear if the implied length check through > > > > > the explicit guard page prevents deliberate misuse of such alloca > > > > > failures for nefarious purposes. So we risk having crashes (already > > > > > quite bad) and often cannot rule out any further security impact > > > > > beyond the crash (worse). > > > > > > > > > > Same thing applies to VLAs on the stack, obviously. > > > > > > > > > > GCC could provide fairly cheap instrumentation (both in terms of > > > > > code size and execution speed) that turns alloca failures (and > > > > > too-large VLas) into reliable crashes, but that GCC feature is > > > > > currently somewhat broken and not usable at all. > > > > > > > > > All you need is reliable way to get stack boundaries. I proposed to add > > > > these some time ago. It would make alloca failures reliable without > > > > need of gcc support. > > > > > > The cost of a function call to look up the current stack boundaries > > > (or a TLS access to get that info on some archs where TLS access is > > > expensive) defeats much of the purpose of using alloca. > > > > > Oh really? It does not follow malloc also needs tls so you will always > > be faster. > > If TLS is the dominating factor (think old MIPS where the instruction > to read the TLS register traps and gets emulated by the kernel), it > brings the cost of alloca up on par with malloc, no? > It does but question is if it will be enabled. > > Also you could avoid that check most times by checking > > request if you crosses page boundary or creating lookup table which page > > belongs to which tread. > > Perhaps, but this gets to be a lot more overhead/complexity for little > if any demonstrable gain. > If there is little gain then you do not have to worry about performance degradation in first place. > > > Moreover, turning alloca failures into "reliable crashes" is not a > > > solution. If an operation requires allocation which could fail, it > > > must be able to back out whatever work it already did and report > > > failure. Crashing is not an acceptable implementation. > > > > > No, when it is third party codebase and it does not want to rewrite > > existing code do you have a better proposal? > > I was talking about internal usage of alloca in glibc. I don't think > glibc can fix use in third-party software. > I was not talking about glibc, I was saying how to fix alloca in general. This could make check reliably any alloca in system if you recompile binaries. Enabling that from glibc is technically easy, apply following patch. It is feasible to add this with some sort of configure option. diff --git a/stdlib/alloca.h b/stdlib/alloca.h index 2d592d4..255af45 100644 --- a/stdlib/alloca.h +++ b/stdlib/alloca.h @@ -32,7 +32,7 @@ __BEGIN_DECLS extern void *alloca (size_t __size) __THROW; #ifdef __GNUC__ -# define alloca(size) __builtin_alloca (size) +# define alloca(size) (VERIFY_ALLOCA (size) ? __builtin_alloca (size) : (abort, NULL)) #endif /* GCC. */ __END_DECLS