From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by sourceware.org (Postfix) with ESMTPS id 10EA13858D3C for ; Wed, 5 Oct 2022 17:07:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 10EA13858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oo1-xc33.google.com with SMTP id r15-20020a4abf0f000000b004761c7e6be1so11234721oop.9 for ; Wed, 05 Oct 2022 10:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date; bh=+3j8kQ7+sRwaU/UxLS1Bjz6L2zBeCRUXmq+T6xqmc2w=; b=KicCBRuPOParfdRho9G2ZjE8aOZrMJAD7RuqPNfK3UvQK2opkIbiTl64/9Ximh4u5W IlvuuCXb2udW0rcPtZw5pBPXbGozAAmIxVIEeGP2DuD8MZ04QsyJGSGUVweMiIRXAG2U pgEcq9N/gBhE/G12HtTWTzyF9KY1NTDEBrTX1fpD1KgLqayk11ghEP6Xr9LEjSPOlfgA 6KHsD/gdxlCQ0UXYQVgly3wARnxAKpGpCsq3VFo19/Of6WK3/WvahIspFCLmcEsE0tq6 jeuK/OPGuX7bXZQrg5FT1PvizCP/hc2qoCc2pCqy4pnby3IEIqQYOahnk1FNyJBcxEEU XoVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=+3j8kQ7+sRwaU/UxLS1Bjz6L2zBeCRUXmq+T6xqmc2w=; b=eyae8ImyrVMaSCBMiwb2+k0+pK5Ai+mbVy3NkyhM0TyCjQ8pBUoQZa3bo/aio9IBnY mzlEGAsHzHDJnzQp1uabg1wKMBzVsy8EP5u2nwnZR5PsLSn77ja5LcZM2kxlPn5khQET YD0vTQdQvIIzrHig2Xf4DVLopyE+zqTMTJeGqmBcSYOTWNe5cox86MPKEQjFgfv27A4/ vHlSloT19CBtTFKmiM+fAZZzD8hB7EdQsAB8OkASd4daNUZvQfVHkrP9PK1CtOuJY7w7 R+qQhuthkk91ELG4HCDxptvP0j7FKljMjFrGsUVEB9ECtm8mGtoVvbSV0F2M4JLmmdoL Bm3g== X-Gm-Message-State: ACrzQf0PNJcc7rF2X0zubMF6sweRIPOrZw4bRVNWwe4Uxbk8uGWqUBaK hM+zX5nAQdv6ahOv8jnehmV9h7PmafI/HZ85 X-Google-Smtp-Source: AMsMyM6+thK/vIr8UORBwyFZtXYXFKaJUh3g7VV76mclF073J/C6fLFA1LbbLI3KudFi1MBYaM62rw== X-Received: by 2002:a05:6820:512:b0:476:36bb:2a5a with SMTP id m18-20020a056820051200b0047636bb2a5amr180548ooj.11.1664989652053; Wed, 05 Oct 2022 10:07:32 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:b87d:99c2:20cb:d5b8:a210]) by smtp.gmail.com with ESMTPSA id v68-20020acaac47000000b00349a06c581fsm4498945oie.3.2022.10.05.10.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 10:07:31 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Siddhesh Poyarekar Subject: [PATCH] csu: Disable stack protector for static-reloc for static-pie Date: Wed, 5 Oct 2022 14:07:28 -0300 Message-Id: <20221005170728.2350140-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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: 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(-) 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 -- 2.34.1