Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1666994imm; Thu, 27 Sep 2018 00:06:25 -0700 (PDT) X-Google-Smtp-Source: ACcGV60fWyvuEsRG9s2hL28vX9o3My4vM1AQqSmh/3YCv9p0hOaX34ka7OwUrOXMs51CP7qpQaJN X-Received: by 2002:a62:5c03:: with SMTP id q3-v6mr9944741pfb.182.1538031985408; Thu, 27 Sep 2018 00:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538031985; cv=none; d=google.com; s=arc-20160816; b=m7JsYsXiLRdl3Cc2TdO72rzqujBuhxLAId0OiRpJGWyy2oSyCt0WYk0UUs+9Us4uCZ o0GbE/o79RJK5Bw+6JZnofb6Q0sqTA+iPNrNKVy1qmZzPVDF4z6WYI33aYw96yfN1juA 5W/l8o67pwvdQdE3I1lGpP1hC9Y+uV2hYH8he3+uYIrWRq/6g+Y/wvRvC5y3Voegp27b idhgI9dnqpN0LVeVz8J+W+NJRDCqe04u8IT/XL8jRYGujZcPx/5B/Iz2V4OoT/NSt67k ZdL2Mqd8XQq1wD9qEjuKXH2w9zNXPxoiqMgVQh9FoIm5ttvosifpnmTMQL3bIAwZdydG Wjxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id; bh=HLB385Eiw06pKed2GC9QUO+8c2upZSfEXe/l6Iiqxo8=; b=qrEHif7vlj6WTRLrbYkFyYXBII6u8t7Ts1eqZk9/xIz3O+T+NmBkYUuRMVtKyazGOG 4zO2gv3pBVvIpFVf+VBw17lJ8IShTtNKtmYZoYkPJwPe39+RSxgoscf/BFB4HTA5lCTT R/U9coA6d3HxoVUCraswmfV3vld44dDP4SR+8tvXmyqiOLZAsCZs5SQSvvrxq+62ZNJN /xlogD84pEfamoOl2DJseACls+d5nUWx9HGpqMT4gBT9mgAaUJ2m8KPNDWoRlyqqj9E+ b7NpGHtLILefyU89OOjx0ER9Zr91tHEOinJ1MOxKxWYK9tfLXJVd+SfOGdKO4siUXkmc dVWg== ARC-Authentication-Results: i=1; mx.google.com; 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 d186-v6si1403817pfg.23.2018.09.27.00.06.10; Thu, 27 Sep 2018 00:06:25 -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; 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 S1727326AbeI0NWp (ORCPT + 99 others); Thu, 27 Sep 2018 09:22:45 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:64310 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727026AbeI0NWo (ORCPT ); Thu, 27 Sep 2018 09:22:44 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 42LQnc3zpzz9ttKm; Thu, 27 Sep 2018 09:05:56 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id pRDEC95zDCZf; Thu, 27 Sep 2018 09:05:56 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 42LQnc3WlFz9ttFb; Thu, 27 Sep 2018 09:05:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6E9CC8B874; Thu, 27 Sep 2018 09:05:56 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id kU-AmKWDEEI6; Thu, 27 Sep 2018 09:05:56 +0200 (CEST) Received: from pc16082vm.idsi0.si.c-s.fr (unknown [192.168.232.3]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 11A078B75A; Thu, 27 Sep 2018 09:05:56 +0200 (CEST) Received: by pc16082vm.idsi0.si.c-s.fr (Postfix, from userid 0) id E00FD6F1AA; Thu, 27 Sep 2018 07:05:55 +0000 (UTC) Message-Id: <6e570d7ded4f53ef8362cab8a54ef729454429b4.1537987713.git.christophe.leroy@c-s.fr> In-Reply-To: <8e81b0647fea15e533a73ad4e9063c059fdfc6df.1537987712.git.christophe.leroy@c-s.fr> References: <8e81b0647fea15e533a73ad4e9063c059fdfc6df.1537987712.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH v5 2/2] powerpc/64: add stack protector support To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Thu, 27 Sep 2018 07:05:55 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 4 ++++ arch/powerpc/kernel/asm-offsets.c | 3 +++ arch/powerpc/kernel/entry_64.S | 4 ++++ 6 files changed, 23 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 d05d969c98c2..1c8460e23583 100644 --- a/arch/powerpc/include/asm/stackprotector.h +++ b/arch/powerpc/include/asm/stackprotector.h @@ -11,6 +11,7 @@ #include #include #include +#include /* * Initialize the stackprotector canary value. @@ -29,6 +30,9 @@ static __always_inline void boot_init_stack_canary(void) canary &= CANARY_MASK; 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 -- 2.13.3