From patchwork Thu Jul 22 20:57:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-cheng Yu X-Patchwork-Id: 12394751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFD45C00141 for ; Thu, 22 Jul 2021 20:58:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 71CAA60EE9 for ; Thu, 22 Jul 2021 20:58:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 71CAA60EE9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 11A366B0036; Thu, 22 Jul 2021 16:58:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07B6D6B005D; Thu, 22 Jul 2021 16:58:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E371C6B006C; Thu, 22 Jul 2021 16:58:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0132.hostedemail.com [216.40.44.132]) by kanga.kvack.org (Postfix) with ESMTP id C2A156B0036 for ; Thu, 22 Jul 2021 16:58:06 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 74AC5248A9 for ; Thu, 22 Jul 2021 20:58:06 +0000 (UTC) X-FDA: 78391436172.11.AF554FA Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf12.hostedemail.com (Postfix) with ESMTP id B44D41001534 for ; Thu, 22 Jul 2021 20:58:05 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10053"; a="297309439" X-IronPort-AV: E=Sophos;i="5.84,262,1620716400"; d="scan'208";a="297309439" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2021 13:58:04 -0700 X-IronPort-AV: E=Sophos;i="5.84,262,1620716400"; d="scan'208";a="433273367" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2021 13:58: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" , Dave Martin , Weijiang Yang , Pengfei Xu , Haitao Huang , Rick P Edgecombe Cc: Yu-cheng Yu Subject: [PATCH v28 04/10] x86/cet/ibt: Disable IBT for ia32 Date: Thu, 22 Jul 2021 13:57:17 -0700 Message-Id: <20210722205723.9476-5-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210722205723.9476-1-yu-cheng.yu@intel.com> References: <20210722205723.9476-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Authentication-Results: imf12.hostedemail.com; dkim=none; spf=none (imf12.hostedemail.com: domain of yu-cheng.yu@intel.com has no SPF policy when checking 192.55.52.43) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none) X-Stat-Signature: y9xsa1zz8k375izbiq66b5qpfwyp4fxz X-Rspamd-Queue-Id: B44D41001534 X-Rspamd-Server: rspam01 X-HE-Tag: 1626987485-461819 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In a signal, a task's IBT status needs to be saved to the signal frame, and later restored in sigreturn. For the purpose, previous versions of the series add a new struct to the signal frame. However, a new signal frame format (or re-using a reserved space) introduces complex compatibility issues. In the discussion (see link below), Andy Lutomirski proposed using a ucontext flag. The approach is clean and eliminates most compatibility issues. However, a legacy IA32 signal frame does not have ucontext and cannot support a uc flag. Thus, - Disable IBT for ia32. - In ia32 sigreturn, verify ibt is disabled. Signed-off-by: Yu-cheng Yu Cc: Andy Lutomirski Cc: Cyrill Gorcunov Cc: Florian Weimer Cc: H. Peter Anvin Cc: Kees Cook Link: https://lore.kernel.org/linux-api/f6e61dae-9805-c855-8873-7481ceb7ea79@intel.com/ Acked-by: Andy Lutomirski --- arch/x86/ia32/ia32_signal.c | 7 +++++++ arch/x86/include/asm/elf.h | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c index 77d0fa90cc19..946039cb3150 100644 --- a/arch/x86/ia32/ia32_signal.c +++ b/arch/x86/ia32/ia32_signal.c @@ -104,6 +104,13 @@ COMPAT_SYSCALL_DEFINE0(sigreturn) struct sigframe_ia32 __user *frame = (struct sigframe_ia32 __user *)(regs->sp-8); sigset_t set; + /* + * Verify legacy sigreturn does not have IBT enabled. + */ +#ifdef CONFIG_X86_IBT + if (current->thread.shstk.ibt) + goto badframe; +#endif if (!access_ok(frame, sizeof(*frame))) goto badframe; if (__get_user(set.sig[0], &frame->sc.oldmask) diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h index 3281a3d01bd2..cf9eeb30c00c 100644 --- a/arch/x86/include/asm/elf.h +++ b/arch/x86/include/asm/elf.h @@ -6,6 +6,7 @@ * ELF register definitions.. */ #include +#include #include #include @@ -403,7 +404,17 @@ struct arch_elf_state { } #define arch_elf_pt_proc(ehdr, phdr, elf, interp, state) (0) -#define arch_check_elf(ehdr, interp, interp_ehdr, state) (0) +static inline int arch_check_elf(void *ehdr, bool interp, + void *interp_ehdr, + struct arch_elf_state *state) +{ + /* + * Disable IBT for ia32 + */ + if (elf_check_arch_ia32((struct elf32_hdr *)ehdr)) + state->gnu_property &= ~GNU_PROPERTY_X86_FEATURE_1_IBT; + return 0; +} /* Do not change the values. See get_align_mask() */ enum align_flags {