Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp393779imm; Wed, 26 Sep 2018 00:06:59 -0700 (PDT) X-Google-Smtp-Source: ACcGV60jzFuggvS6CC24GUKJLmBqi+PNq//n9A2tCe/LFrT69DmaO1vuutiqXRQwybhd9eQGMqYp X-Received: by 2002:a63:9a42:: with SMTP id e2-v6mr4383245pgo.263.1537945619560; Wed, 26 Sep 2018 00:06:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537945619; cv=none; d=google.com; s=arc-20160816; b=CceRpuAWUfJogSgGuE3azoL9oZi6ebpUdZW5ufXaZb8KNn6FfleQ44vSVKGNknQyIJ 8fRoENYhd2QQsFi7nkE3nQKvS3z/Y0EWtoKUlJdsNq3qQT40hVTj/CQmSMviKt8n4DEs R47PJhlyGGnERCcahsKshhm1fjFf346byguhw5XJ0WCsayAiRHVl8xsQ4V2sibyAb+ZP /ZEX5Ro15HG3KvEbUPsqE3dZckZvlRJyaipF71ZnHltvpYi3Q6ChaZVBOXNNjYMiDY0s fzJfV4P3J9LDyNC/jtyzhekbOeh6fmlKjcHqVzOsDKyY4EvKsflUYa/+rV2Ywv7oyn7K lkwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :date:references:in-reply-to:cc:to:from:subject:message-id :dkim-signature; bh=YAAlbgfgco+8zPEzNLVVaxni0CpmWU3G40gJqbgFe6I=; b=jEFNUiBqtxkHP6aNSqtbl5w691AD9ImuhpXaelb8wNSmmRTZxvlIA8Qkt0wrmaNe8p Rgpjw45tcZgNl/FaGqgQI1ghD8w+DfmS2s/PrxoNPvSsSY25oB7JoAjR7pT/Sxe9cwf5 v84U33p5IM+FQUvRBGzAH5pBw0RmaOgQjlb4bpBWyANWPCQbx6LeZM7+b18n82r7+Ss1 cC1pSCfyv9owCOcsbf7U6a9Ur9/JDRnRCCA7fSevLWm9nBu0keALy0HR8E/HyTjLPwaB JFjuWzePLO1LAV9a/inqf6bhXZJbsn9q1Cu7N7m6sH38cV5onspQ8h0Q3xVvgej2Oi2e mT4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=BkrUUpLJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o11-v6si4453969pgl.16.2018.09.26.00.06.43; Wed, 26 Sep 2018 00:06:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=BkrUUpLJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727189AbeIZNRK (ORCPT + 99 others); Wed, 26 Sep 2018 09:17:10 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:57603 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726369AbeIZNRK (ORCPT ); Wed, 26 Sep 2018 09:17:10 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id D45EB21A29; Wed, 26 Sep 2018 03:05:41 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 26 Sep 2018 03:05:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=YAAlbg fgco+8zPEzNLVVaxni0CpmWU3G40gJqbgFe6I=; b=BkrUUpLJrAcMShPVvqOFS9 pzPen3FwM4EoOt3d+GqkRlCakvItJIEtsIiiz8t2Fk4mJXXJEftIVHMmbQkY7JPD xtksL+3lPzkcIAR99WOQflqwpCVdxcJk69iZ+lwIt9OzKfs5+KbmQi/D2/3duBi3 qw8eP9KjFXcv+uMZFy7kPC+rs6sUVCLRelOJePB6xwsiBr/w4Vn+I7fJ/hGuFfwq CZL+35fCnLjDB5cHcMi7HWQIk6EjVwG+Q3v6fWBluRSfriFeflwdM43OfP31Eac5 ugoZ8uzyOLpXjdsMoNvMAZhdxmJ/vs1OOZM+YcZH/knBRDIGcUyKGQmp/BkAARfA == X-ME-Proxy: X-ME-Sender: Received: from snap.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 6F96C102D2; Wed, 26 Sep 2018 03:05:37 -0400 (EDT) Message-ID: Subject: Re: [PATCH v3 2/2] powerpc/64: add stack protector support From: Russell Currey To: Christophe LEROY , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Andrew Donnellan Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org In-Reply-To: <0797fc91-6400-2508-1cc0-4bba78aafbbb@c-s.fr> References: <2b934594d21ade67a4092637cf9e6b7d2d131187.1537801613.git.christophe.leroy@c-s.fr> <0797fc91-6400-2508-1cc0-4bba78aafbbb@c-s.fr> Content-Type: text/plain; charset="UTF-8" Date: Wed, 26 Sep 2018 17:05:34 +1000 Mime-Version: 1.0 X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-09-25 at 17:56 +0200, Christophe LEROY wrote: > Snowpatch reports failure on pmac32_defconfig, as follows: > > arch/powerpc/platforms/powermac/bootx_init.o: In function `bootx_printf': > /var/lib/jenkins-slave/workspace/snowpatch/snowpatch-linux- > sparse/linux/arch/powerpc/platforms/powermac/bootx_init.c:88: > undefined reference to `__stack_chk_fail_local' > arch/powerpc/platforms/powermac/bootx_init.o: In function > `bootx_add_display_props': > /var/lib/jenkins-slave/workspace/snowpatch/snowpatch-linux- > sparse/linux/arch/powerpc/platforms/powermac/bootx_init.c:211: > undefined reference to `__stack_chk_fail_local' > arch/powerpc/platforms/powermac/bootx_init.o: In function > `bootx_scan_dt_build_struct': > /var/lib/jenkins-slave/workspace/snowpatch/snowpatch-linux- > sparse/linux/arch/powerpc/platforms/powermac/bootx_init.c:350: > undefined reference to `__stack_chk_fail_local' > arch/powerpc/platforms/powermac/bootx_init.o: In function `bootx_init': > /var/lib/jenkins-slave/workspace/snowpatch/snowpatch-linux- > sparse/linux/arch/powerpc/platforms/powermac/bootx_init.c:598: > undefined reference to `__stack_chk_fail_local' > ld: .tmp_vmlinux1: hidden symbol `__stack_chk_fail_local' isn't defined > ld: final link failed: Bad value > Makefile:1040: recipe for target 'vmlinux' failed > make: *** [vmlinux] Error 1 > > I don't have this issue with GCC 8.1, bootx_init.o has references to > __stack_chk_fail, not to __stack_chk_fail_local > > Looking online, it may be due to an old build and a lack of 'make > clean', could it be the case here ? We do make mrproper AND clean, just to be sure :) > > Otherwise, can you retry the build to see if it's happen again ? I've retried the build and the same thing happens. Our build environment is using GCC 7.3 on Ubuntu 18.04. Reproduced on a different machine too, running the same OS and compiler. You can see exactly what gets run here: https://github.com/ajdlinux/openpower.xyz-snowpatch/blob/master/kernel-build-sparse.sh - Russell > > Christophe > > Le 24/09/2018 à 17:15, Christophe Leroy a écrit : > > On PPC64, as register r13 points to the paca_struct at all time, > > this patch adds a copy of the canary there, which is copied at > > task_switch. > > That new canary is then used by using the following GCC options: > > -mstack-protector-guard=tls > > -mstack-protector-guard-reg=r13 > > -mstack-protector-guard-offset=offsetof(struct paca_struct, canary)) > > > > Signed-off-by: Christophe Leroy > > --- > > arch/powerpc/Kconfig | 2 +- > > arch/powerpc/Makefile | 8 ++++++++ > > arch/powerpc/include/asm/paca.h | 3 +++ > > arch/powerpc/include/asm/stackprotector.h | 3 +++ > > arch/powerpc/kernel/asm-offsets.c | 3 +++ > > arch/powerpc/kernel/entry_64.S | 4 ++++ > > 6 files changed, 22 insertions(+), 1 deletion(-) > > > > diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig > > index 3bcb05929931..602eea723624 100644 > > --- a/arch/powerpc/Kconfig > > +++ b/arch/powerpc/Kconfig > > @@ -180,7 +180,7 @@ config PPC > > select HAVE_ARCH_SECCOMP_FILTER > > select HAVE_ARCH_TRACEHOOK > > select HAVE_CBPF_JIT if !PPC64 > > - select HAVE_STACKPROTECTOR if $(cc-option,-mstack-protector- > > guard=tls) && PPC32 > > + select HAVE_STACKPROTECTOR if $(cc-option,-mstack-protector- > > guard=tls) > > select HAVE_CONTEXT_TRACKING if PPC64 > > select HAVE_DEBUG_KMEMLEAK > > select HAVE_DEBUG_STACKOVERFLOW > > diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile > > index 45b8eb4d8fe7..81552c7b46eb 100644 > > --- a/arch/powerpc/Makefile > > +++ b/arch/powerpc/Makefile > > @@ -113,7 +113,11 @@ KBUILD_ARFLAGS += --target=elf$(BITS)-$(GNUTARGET) > > endif > > > > cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard=tls > > +ifdef CONFIG_PPC64 > > +cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-reg=r13 > > +else > > cflags-$(CONFIG_STACKPROTECTOR) += -mstack-protector-guard-reg=r2 > > +endif > > > > LDFLAGS_vmlinux-y := -Bstatic > > LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) := -pie > > @@ -411,8 +415,12 @@ ifdef CONFIG_STACKPROTECTOR > > prepare: stack_protector_prepare > > > > stack_protector_prepare: prepare0 > > +ifdef CONFIG_PPC64 > > + $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if > > ($$2 == "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h)) > > +else > > $(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if > > ($$2 == "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h)) > > endif > > +endif > > > > # Use the file '.tmp_gas_check' for binutils tests, as gas won't output > > # to stdout and these checks are run even on install targets. > > diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h > > index 6d6b3706232c..98d883e58945 100644 > > --- a/arch/powerpc/include/asm/paca.h > > +++ b/arch/powerpc/include/asm/paca.h > > @@ -246,6 +246,9 @@ struct paca_struct { > > struct slb_entry *mce_faulty_slbs; > > u16 slb_save_cache_ptr; > > #endif /* CONFIG_PPC_BOOK3S_64 */ > > +#ifdef CONFIG_STACKPROTECTOR > > + unsigned long canary; > > +#endif > > } ____cacheline_aligned; > > > > extern struct paca_struct **paca_ptrs; > > diff --git a/arch/powerpc/include/asm/stackprotector.h > > b/arch/powerpc/include/asm/stackprotector.h > > index 263e2aab1862..e81991955c0d 100644 > > --- a/arch/powerpc/include/asm/stackprotector.h > > +++ b/arch/powerpc/include/asm/stackprotector.h > > @@ -29,6 +29,9 @@ static __always_inline void boot_init_stack_canary(void) > > canary ^= LINUX_VERSION_CODE; > > > > current->stack_canary = canary; > > +#ifdef CONFIG_PPC64 > > + get_paca()->canary = canary; > > +#endif > > } > > > > #endif /* _ASM_STACKPROTECTOR_H */ > > diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm- > > offsets.c > > index a992f7a53cf3..773dee55b3f6 100644 > > --- a/arch/powerpc/kernel/asm-offsets.c > > +++ b/arch/powerpc/kernel/asm-offsets.c > > @@ -81,6 +81,9 @@ int main(void) > > OFFSET(MM, task_struct, mm); > > #ifdef CONFIG_STACKPROTECTOR > > OFFSET(TASK_CANARY, task_struct, stack_canary); > > +#ifdef CONFIG_PPC64 > > + OFFSET(PACA_CANARY, paca_struct, canary); > > +#endif > > #endif > > OFFSET(MMCONTEXTID, mm_struct, context.id); > > #ifdef CONFIG_PPC64 > > diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S > > index 77a888bfcb53..573fa879d785 100644 > > --- a/arch/powerpc/kernel/entry_64.S > > +++ b/arch/powerpc/kernel/entry_64.S > > @@ -624,6 +624,10 @@ _GLOBAL(_switch) > > > > addi r6,r4,-THREAD /* Convert THREAD to 'current' */ > > std r6,PACACURRENT(r13) /* Set new 'current' */ > > +#if defined(CONFIG_STACKPROTECTOR) > > + ld r6, TASK_CANARY(r6) > > + std r6, PACA_CANARY(r13) > > +#endif > > > > ld r8,KSP(r4) /* new stack pointer */ > > #ifdef CONFIG_PPC_BOOK3S_64 > >