From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from black.elm.relay.mailchannels.net (black.elm.relay.mailchannels.net [23.83.212.19]) by sourceware.org (Postfix) with ESMTPS id C93143858C54 for ; Wed, 5 Oct 2022 18:23:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C93143858C54 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 760D2122A89; Wed, 5 Oct 2022 18:23:32 +0000 (UTC) Received: from pdx1-sub0-mail-a305 (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 014E0122D55; Wed, 5 Oct 2022 18:23:31 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1664994212; a=rsa-sha256; cv=none; b=NPDSQPkmnyDrJ7mJuPlmkCQuGsoKCFYZ8Y8q4uVK+ax3QlFMmXGA2Nie9uGs7r5aPBeSFA RiD6jr+QQbZRppO5mVjLod32hLIkhOWRSpgGJDz3WwYXILWbUs8xNIRpTCaCPwQ9xvDEdD fDm14aEFPyj4uMsyarWEOxAveyJRJnokxCwhZP1sfi/bT6pQgoE0fKZm9P9gmDCffP/vn9 ESlVAARzHjuh0tLRx68Q1IIHoq4/ew415X7n3krU/68QhKbXu43N8gmh2+JJNfNRiP5LIf Osum2oyc6hgl2J9xcsSD4DjfLSUGj6dmRs91cGgnow27JvMCWQU3p9Lk6vgi+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1664994212; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oIwQUQP0QJigvLIcvu0ZNe4KvJm1+nZg7FUlLn23tnQ=; b=v5LepxF7oNOZw4nydSHsrpo8MfahrPNevFEK8KWpe2QBWZ5xWU2eia67k9nR0xHSK9k4bm Stxr2Bmhfw/M2OmmxmbD0/gmY2yzY8tHgI+CvHzKMCr3D8cZxt7eyar/iG33/gOUb1Nf7i PGiv4xR2viBtCuSu9lM2QthXHAtcRgl1hnGmiz+cT4t39xioDdCzfDL46iui6izPGuRFHY ik8A3/7PErIB371KB1A5bVAhk8B43PfLh15MLCcmhKMGQmt6uHXehuDqAJZDJK2uTTWU8c oBjU2hdnpTA3bGZMDVuArYCeP9v7ttWA+m2adq0WY9RMxCDzvkBf0/T79+LGKA== ARC-Authentication-Results: i=1; rspamd-6d4bb977-j7hpn; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Left-Stop: 00b9772560e56427_1664994212284_1627483888 X-MC-Loop-Signature: 1664994212284:2670405271 X-MC-Ingress-Time: 1664994212283 Received: from pdx1-sub0-mail-a305 (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.112.55.219 (trex/6.7.1); Wed, 05 Oct 2022 18:23:32 +0000 Received: from [192.168.0.182] (bras-base-toroon4834w-grc-23-76-68-24-82.dsl.bell.ca [76.68.24.82]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a305 (Postfix) with ESMTPSA id 4MjNHR0GfczH9; Wed, 5 Oct 2022 11:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1664994211; bh=oIwQUQP0QJigvLIcvu0ZNe4KvJm1+nZg7FUlLn23tnQ=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=VcMlJDbAkH2j9B4EOkMs1Y/tJOMGzq1uJ1mWb8VW8WzuVbt9XPdfcsyRORROUezDS 759hkt85vMceKCb5tWc6AqBCZBHch6y0ig5UKVl5O73Iw0OQtlgOAFIYohHNnRycgu eIbBztDQLxbQzo7zRq4Pb4JqKoQSywoGCcyrNdWuJYWgX7C1Saw5lXy9gRnXdY31RR V0S8SH9BTrRdwSUJ68aM/X2t647Em/YjCSI81Ei0CfVoxVzx0DyVvlSksZlNVwowBX U74wErptrZV/9t/WSrN7XI24rQ/jmtrOHlhbSJ+4kWTu5HyBNkx7LGR0lTEsbv3C5R yeC2JkFD8aoEg== Message-ID: Date: Wed, 5 Oct 2022 14:23:29 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH] csu: Disable stack protector for static-reloc for static-pie Content-Language: en-US To: Adhemerval Zanella , libc-alpha@sourceware.org References: <20221005170728.2350140-1-adhemerval.zanella@linaro.org> From: Siddhesh Poyarekar In-Reply-To: <20221005170728.2350140-1-adhemerval.zanella@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3038.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2022-10-05 13:07, Adhemerval Zanella wrote: > For instance on x86_64 with gcc 12.1.1 andwith fstack-protector > enabled the empty function still generates a stack protector code > sequence: > > 0000000000000000 <_dl_relocate_static_pie>: > 0: 48 83 ec 18 sub $0x18,%rsp > 4: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax > b: 00 00 > d: 48 89 44 24 08 mov %rax,0x8(%rsp) > 12: 31 c0 xor %eax,%eax > 14: 48 8b 44 24 08 mov 0x8(%rsp),%rax > 19: 64 48 2b 04 25 28 00 sub %fs:0x28,%rax > 20: 00 00 > 22: 75 05 jne 29 <_dl_relocate_static_pie+0x29> > 24: 48 83 c4 18 add $0x18,%rsp > 28: c3 ret > 29: e8 00 00 00 00 call 2e <_dl_relocate_static_pie+0x2e> > > And since the function is called prior thread pointer setup, it > triggers a invalid memory access (this is shown with the failure > of elf/tst-tls1-static-non-pie). > > Although it might characterizes as compiler issue or missed > optimization, to be safe also disables stack protector on > static-reloc object. > > Checked on x86_64-linux-gnu and sparc64-linux-gnu. > --- > csu/Makefile | 16 +++++++++++----- > 1 file changed, 11 insertions(+), 5 deletions(-) Hmm, that's odd, the the stack protector code sequence is useless given that there's no stack variables in that function. Anyway, the change is not wrong, so LGTM. Reviewed-by: Siddhesh Poyarekar > > diff --git a/csu/Makefile b/csu/Makefile > index 2e8a28e851..f71a5eb6c6 100644 > --- a/csu/Makefile > +++ b/csu/Makefile > @@ -50,15 +50,21 @@ tests = > # applications, so that build flags matter. > # See . > # > +# The function is called prior the thread pointer setup, and if stack > +# protector is enabled the compiler might still generate the stack check > +# (which requires the thread pointer correctly set). > +extra-no-ssp = static-reloc > + > # libc-start.os is safe to be built with stack protector since > # __libc_start_main is called after stack canary setup is done. > -ssp-safe.os = static-reloc libc-start > +ssp-safe.os = libc-start > > -CFLAGS-.o += $(call elide-stack-protector,.o,$(routines)) > -CFLAGS-.op += $(call elide-stack-protector,.op,$(routines)) > -CFLAGS-.oS += $(call elide-stack-protector,.oS,$(routines)) > +CFLAGS-.o += $(call elide-stack-protector,.o,$(routines) $(extra-no-ssp)) > +CFLAGS-.op += $(call elide-stack-protector,.op,$(routines) $(extra-no-ssp)) > +CFLAGS-.oS += $(call elide-stack-protector,.oS,$(routines) $(extra-no-ssp)) > CFLAGS-.os += $(call elide-stack-protector,.os,$(filter-out \ > - $(ssp-safe.os),$(routines))) > + $(ssp-safe.os), \ > + $(routines) $(extra-no-ssp))) > > ifeq (yes,$(build-shared)) > extra-objs += S$(start-installed-name) gmon-start.os