Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1107170ybz; Wed, 29 Apr 2020 15:11:47 -0700 (PDT) X-Google-Smtp-Source: APiQypJVN3bl1xvPxX4TJIzwwOI0N/jIC8C84vpCTlR7EZ3bGBKGe/ROSk+hPzg1G2qH9rHyU2pb X-Received: by 2002:a17:907:20a2:: with SMTP id pw2mr4890010ejb.252.1588198307021; Wed, 29 Apr 2020 15:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588198307; cv=none; d=google.com; s=arc-20160816; b=tlu1qfZAumyBX49KcXkkO6hLin+tHgW/PTKg/OSg/nZCoVjGR0G918zBK/7OCCGBHF RhgTtP/+Vz9lsRnZepGkBgr5xEXLQnqYd5V3n+A5lrziBCyMtmf+7UZygTxbqu6OBqj0 Rw+E/Xhs71lOBT4AdDrgPM/QAKjY6U30k+z5mOCIS18ao4DBcD5z679Kobvc8dSzSiI5 W7c/U+l/QUbWE8LMlT+bvrMiereeGfnHaJnls+P4XpOVWh2ccTF6mDmlpptqwgNEIQCV +DY9ITpW+MRHS4JJi8Y8ulQPqkBxfr5uJ+LtMkBaYA5zOT74JPOxJPV2P6Y9sy1EAeXg U85Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=oTdH9YOK3j9zwvtStoBkRuIZIU35TUqOuyO243hGdE8=; b=V/GgNsc/gGtIFiNlyFzJwN3a4c5sr1xIQNNUJqp9ChyMl7dABL5DugmxPH+NWP2+UP qd+wqJ3jNAr+kcG0U5ZdTZYSPyhgqBz0r16fOw1+Ot6zHHo+IbByw99ijvZ95qz1oCqP MGUadxi1exAs7D/54iMft38CNG03AXmvu7p2i48RkPUOz+9WHGd58X5wRJUmjk6ujl8D B5lJoBzgEqfvYlwsizRpr5QQI2lSaPYt9qg5zgLhZK27QvpeqBX5J6iNikiAIN7aZVNF hXfcWT4sIBLrN0y/Uelz5iqGM/SbJmn/sY4ZZVpd/cVN/BD/oC/GIap1MBTyTKkiM1cN aJKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id qo19si4705615ejb.239.2020.04.29.15.11.24; Wed, 29 Apr 2020 15:11:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728090AbgD2WJA (ORCPT + 99 others); Wed, 29 Apr 2020 18:09:00 -0400 Received: from mga09.intel.com ([134.134.136.24]:61302 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728065AbgD2WI6 (ORCPT ); Wed, 29 Apr 2020 18:08:58 -0400 IronPort-SDR: jPtmDdrKDJisvezLJYjwrK2Hxq03Zmj3+8Pgx0/aMkypd6SIDIp0AwidPgu1ghtLX1B+gDvyl4 TA6Zi6J45pVw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 15:08:55 -0700 IronPort-SDR: hCpBR8JgmBUArba48RcnGTPFc5gh6uFPvXCw7CalaqG7T7/E46TXDiTalLMUPIIFuAM8DGo8v2 lWvfarYOuZHQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,333,1583222400"; d="scan'208";a="276308937" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga002.jf.intel.com with ESMTP; 29 Apr 2020 15:08:54 -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 , Weijiang Yang Cc: Yu-cheng Yu Subject: [PATCH v10 24/26] x86/cet/shstk: ELF header parsing for shadow stack Date: Wed, 29 Apr 2020 15:07:30 -0700 Message-Id: <20200429220732.31602-25-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200429220732.31602-1-yu-cheng.yu@intel.com> References: <20200429220732.31602-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Check an ELF file's .note.gnu.property, and setup shadow stack if the application supports it. Signed-off-by: Yu-cheng Yu --- v9: - Change cpu_feature_enabled() to static_cpu_has(). arch/x86/Kconfig | 2 ++ arch/x86/include/asm/elf.h | 13 +++++++++++++ arch/x86/kernel/process_64.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index ac07e1f6a2bc..8b7b97ff5fb4 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1970,6 +1970,8 @@ config X86_INTEL_SHADOW_STACK_USER select X86_INTEL_CET select ARCH_MAYBE_MKWRITE select ARCH_HAS_SHADOW_STACK + select ARCH_USE_GNU_PROPERTY + select ARCH_BINFMT_ELF_STATE help Shadow Stacks provides protection against program stack corruption. It's a hardware feature. This only matters 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 5ef9d8f25b0e..93ba4afd0c19 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -730,3 +730,32 @@ unsigned long KSTK_ESP(struct task_struct *task) { return task_pt_regs(task)->sp; } + +#ifdef CONFIG_ARCH_USE_GNU_PROPERTY +int arch_parse_elf_property(u32 type, const void *data, size_t datasz, + bool compat, struct arch_elf_state *state) +{ + if (type != GNU_PROPERTY_X86_FEATURE_1_AND) + return 0; + + if (datasz != sizeof(unsigned int)) + return -ENOEXEC; + + state->gnu_property = *(unsigned int *)data; + return 0; +} + +int arch_setup_elf_property(struct arch_elf_state *state) +{ + int r = 0; + + memset(¤t->thread.cet, 0, sizeof(struct cet_status)); + + if (static_cpu_has(X86_FEATURE_SHSTK)) { + if (state->gnu_property & GNU_PROPERTY_X86_FEATURE_1_SHSTK) + r = cet_setup_shstk(); + } + + return r; +} +#endif -- 2.21.0