Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1513705ybl; Tue, 13 Aug 2019 14:04:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxQ6oI1W18DVIVQjpgsDQm3GCY2wMGeQlirCgiwY2qEO21l4EAI5yhyqLKkmL8F7MKyFh+R X-Received: by 2002:a63:4a51:: with SMTP id j17mr35895695pgl.284.1565730294604; Tue, 13 Aug 2019 14:04:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565730294; cv=none; d=google.com; s=arc-20160816; b=nFj1nck4d6Thx/NEI/SL1osuFZ3DGYsUp6L47jVlEvcoKkaycorpwuqATHk5NRE8T7 sFhH0nXfyfTeHVgzz+QDgsZXP9mhEAbJw2M25puSoDlqMhcnGfS5+fNQHar6kPfqDmq/ /2dnXQtCfAAivKm7ZLQUyaSvwzaue3xGCDHIDBnNUrmz0HRpLYUulegNdUdt/chEErTQ d5hKuCmz3nEs1r8LFCNmkQISqJgGLevbhiZ6r018WEAxhCYQijiuMV2YGsXhCYtZoWXY nDD8Gz3Qe8OuG8WZTOkFP1q7tH0vW3PgMZZiBk9Mz+dgCHg5NK3lLX9FL2Kzs/nN38B7 zafg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=egEC09X7AAUqE9JkldOPSAl8P+MftWVMqoRAfJTWlng=; b=ZKOXnRYg8Pj7XLa+4U0JhCYJ47wmCceO3ohZM0hzTmQE1To0uW3GxWd6179FJ8ETrq 9QR/YTc62yO0JC9Al5nVGQcQ5MWaaSXkbJyNKaKDwoK1zK18zHekeo1W/5kpMLx93O2F a+I/TE/38l5gfL5ZnqkIrkbr9X0+elCicBEBFQux3mqd3PiSV9o/GtL5TJofiIz8V+Zm 50nb5miThYvwB0UjJW7QbZ6Ttxysy+Gg968HEYoaIoNbAoLoRBwHOOk4/vacgnEtmhwG 79Go9c0ZkWp4DF7uxLacgjSczJZdo9eaNk/+zlbcMkEuZo6589k7Jtf5io9J09NbOfmz wTIQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v1si669646plo.118.2019.08.13.14.04.39; Tue, 13 Aug 2019 14:04:54 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727169AbfHMVDe (ORCPT + 99 others); Tue, 13 Aug 2019 17:03:34 -0400 Received: from mga06.intel.com ([134.134.136.31]:16085 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727009AbfHMVDG (ORCPT ); Tue, 13 Aug 2019 17:03:06 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Aug 2019 14:03:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,382,1559545200"; d="scan'208";a="187901529" Received: from yyu32-desk1.sc.intel.com ([10.144.153.205]) by orsmga002.jf.intel.com with ESMTP; 13 Aug 2019 14:03:04 -0700 From: Yu-cheng Yu To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin Cc: Yu-cheng Yu Subject: [PATCH v8 23/27] x86/cet/shstk: ELF header parsing of Shadow Stack Date: Tue, 13 Aug 2019 13:52:21 -0700 Message-Id: <20190813205225.12032-24-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190813205225.12032-1-yu-cheng.yu@intel.com> References: <20190813205225.12032-1-yu-cheng.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Look in .note.gnu.property of an ELF file and check if Shadow Stack needs to be enabled for the task. Signed-off-by: Yu-cheng Yu --- arch/x86/Kconfig | 2 ++ arch/x86/include/asm/elf.h | 13 +++++++++++++ arch/x86/kernel/process_64.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index eaf86ef13348..7d13ba326962 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1947,6 +1947,8 @@ config X86_INTEL_SHADOW_STACK_USER select ARCH_USES_HIGH_VMA_FLAGS select X86_INTEL_CET select ARCH_HAS_SHSTK + select ARCH_USE_GNU_PROPERTY + select ARCH_BINFMT_ELF_STATE ---help--- Shadow stack provides hardware protection against program stack corruption. Only when all the following are true will an application diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h index 69c0f892e310..fac79b621e0a 100644 --- a/arch/x86/include/asm/elf.h +++ b/arch/x86/include/asm/elf.h @@ -367,6 +367,19 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp); #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages +#ifdef CONFIG_ARCH_BINFMT_ELF_STATE +struct arch_elf_state { + unsigned int gnu_property; +}; + +#define INIT_ARCH_ELF_STATE { \ + .gnu_property = 0, \ +} + +#define arch_elf_pt_proc(ehdr, phdr, elf, interp, state) (0) +#define arch_check_elf(ehdr, interp, interp_ehdr, state) (0) +#endif + /* Do not change the values. See get_align_mask() */ enum align_flags { ALIGN_VA_32 = BIT(0), diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index af64519b2695..1232f7a6c023 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -818,3 +818,37 @@ unsigned long KSTK_ESP(struct task_struct *task) { return task_pt_regs(task)->sp; } + +#ifdef CONFIG_ARCH_USE_GNU_PROPERTY +int arch_parse_property(void *ehdr, void *phdr, struct file *f, bool inter, + struct arch_elf_state *state) +{ + int r = 0; + unsigned int property = 0; + + r = get_gnu_property(ehdr, phdr, f, GNU_PROPERTY_X86_FEATURE_1_AND, + &property); + + if (r) + return r; + + state->gnu_property = property; + return 0; +} + +int arch_setup_property(struct arch_elf_state *state) +{ + int r = 0; + + memset(¤t->thread.cet, 0, sizeof(struct cet_status)); + + if (cpu_feature_enabled(X86_FEATURE_SHSTK)) { + if (state->gnu_property & GNU_PROPERTY_X86_FEATURE_1_SHSTK) + r = cet_setup_shstk(); + if (r < 0) + return r; + } + + return r; +} +#endif -- 2.17.1