From patchwork Wed Feb 3 05:42:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1435110 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=d5Ka2LGB; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DVrDW3k9bz9sVt for ; Wed, 3 Feb 2021 16:42:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 621B9398D002; Wed, 3 Feb 2021 05:42:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 621B9398D002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1612330953; bh=DaPRc+lXCbR+K8ZAzalZVu6/NkJrQ9bjGRg0qTXwKqw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=d5Ka2LGBLntZHy5V6RCmCwCidNomiqjRaoMh4oRGLwkybIIuAsYvqCOKbT2C1Qy8J MiUCZbnHs5H7nPm64ar0Pel5fau0UDKf/oJc2TpXArj5mUPHnrDI2iD3utbsU5GRZ4 b/I22pqRxtbMn5qhG/gHDunHgEVol1SZO5WQ392o= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from cyan.elm.relay.mailchannels.net (cyan.elm.relay.mailchannels.net [23.83.212.47]) by sourceware.org (Postfix) with ESMTPS id 886AD396EC4C for ; Wed, 3 Feb 2021 05:42:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 886AD396EC4C 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 339497E21C5 for ; Wed, 3 Feb 2021 05:42:29 +0000 (UTC) Received: from pdx1-sub0-mail-a56.g.dreamhost.com (100-96-15-8.trex.outbound.svc.cluster.local [100.96.15.8]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id C28C07E21C3 for ; Wed, 3 Feb 2021 05:42:28 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a56.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.15.8 (trex/6.0.2); Wed, 03 Feb 2021 05:42:29 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Dime-Slimy: 688aa04847c374be_1612330949070_2318395364 X-MC-Loop-Signature: 1612330949069:1069047236 X-MC-Ingress-Time: 1612330949069 Received: from pdx1-sub0-mail-a56.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a56.g.dreamhost.com (Postfix) with ESMTP id 6AD367F097 for ; Tue, 2 Feb 2021 21:42:28 -0800 (PST) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a56.g.dreamhost.com (Postfix) with ESMTPSA id 4912B7E37A for ; Tue, 2 Feb 2021 21:42:26 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a56 To: libc-alpha@sourceware.org Subject: [PATCH] Build libc-start with stack protector for SHARED Date: Wed, 3 Feb 2021 11:12:19 +0530 Message-Id: <20210203054219.1589041-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3495.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This does not change the emitted code since __libc_start_main does not return, but is important for formal flags compliance. This also cleans up the cosmetic inconsistency in the stack protector flags in csu, especially the incorrect value of STACK_PROTECTOR_LEVEL. --- Makeconfig | 4 ++++ csu/Makefile | 30 ++++++++++++++++-------------- elf/Makefile | 4 ---- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Makeconfig b/Makeconfig index 0a4811b5e5..c99464fdfa 100644 --- a/Makeconfig +++ b/Makeconfig @@ -856,6 +856,10 @@ ifneq ($(stack-protector),) +stack-protector=$(stack-protector) endif +define elide-stack-protector +$(if $(filter $(@F),$(patsubst %,%$(1),$(2))), $(no-stack-protector)) +endef + # This is the program that generates makefile dependencies from C source files. # The -MP flag tells GCC >= 3.2 (which we now require) to produce dummy # targets for headers so that removed headers don't break the build. diff --git a/csu/Makefile b/csu/Makefile index c9385df2e9..b2e46ae1bb 100644 --- a/csu/Makefile +++ b/csu/Makefile @@ -46,25 +46,27 @@ install-lib = $(start-installed-name) g$(start-installed-name) $(csu-dummies) # code is compiled with special flags. tests = -CFLAGS-.o += $(no-stack-protector) -CFLAGS-.op += $(no-stack-protector) -CFLAGS-.os += $(no-stack-protector) - -# Dummy object not actually used for anything. It is linked into -# crt1.o nevertheless, which in turn is statically linked into +# static-reloc.os is a dummy object not actually used for anything. It is +# linked into crt1.o nevertheless, which in turn is statically linked into # applications, so that build flags matter. # See . -# NB: Using $(stack-protector) in this way causes a wrong definition -# STACK_PROTECTOR_LEVEL due to the preceding $(no-stack-protector), -# but it does not matter for this source file. -CFLAGS-static-reloc.os += $(stack-protector) +# +# 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 -# This file is not actually part of the startup code in the nonshared -# case and statically linked into applications. See +# elf-init.oS is not actually part of the startup code in the nonshared case +# and statically linked into applications. See # , # . -# Also see the note above regarding STACK_PROTECTOR_LEVEL. -CFLAGS-elf-init.oS += $(stack-protector) +ssp-safe.oS = elf-init + +CFLAGS-.o += $(call elide-stack-protector,.o,$(routines)) +CFLAGS-.op += $(call elide-stack-protector,.op,$(routines)) +CFLAGS-.os += $(call elide-stack-protector,.os,$(filter-out \ + $(ssp-safe.os),$(routines))) +CFLAGS-.os += $(call elide-stack-protector,.os,$(filter-out \ + $(ssp-safe.oS),$(routines))) ifeq (yes,$(build-shared)) extra-objs += S$(start-installed-name) gmon-start.os diff --git a/elf/Makefile b/elf/Makefile index 16c89b6d07..1c3045376e 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -83,10 +83,6 @@ endif # Also compile all routines in the static library that are elided from # the shared libc because they are in libc.a in the same way. -define elide-stack-protector -$(if $(filter $(@F),$(patsubst %,%$(1),$(2))), $(no-stack-protector)) -endef - CFLAGS-.o += $(call elide-stack-protector,.o,$(elide-routines.os)) CFLAGS-.op += $(call elide-stack-protector,.op,$(elide-routines.os)) CFLAGS-.os += $(call elide-stack-protector,.os,$(all-rtld-routines))