Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8494925ybi; Thu, 6 Jun 2019 13:22:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyyKW5bh5cQfkfYoZVJhgC2AijwYRr13SU3aCbsSuV3VuaeApdjvUmBHrkb8VO6NVE9r1jO X-Received: by 2002:a65:62c4:: with SMTP id m4mr348793pgv.308.1559852527569; Thu, 06 Jun 2019 13:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559852527; cv=none; d=google.com; s=arc-20160816; b=CHL4BpcTat/UXA64bZAjdrgMz+3Ni/DJQpaGYYlV4s/pNzC0uR96M5vqWs/aau+D4z 4EuPu2pn0qh3Tfk5HdBLX0RVhN7J0+4oAnauPvfiUrwTEl3QhU3S9EXf7LEdiB5ZNfII oSMCMuTpyiAb6WBtUbQ+4MC7KDGmhFTKqSkuShgqqfpvPyZRHLnHC4gIe4g9z2une4rV t0DS4Y0dAWKTn7g/CrKX5TOD1ZOqZsB6J3NIplA84YNmx/JYxEKHxu2X+WJi+JcgIN5c /7s01mnGjVCayKiX9FAYrhFSSdAO9ZmWLmqtO6cXLBW+cBUEsOaTfj29XtkjvE33EO6K BMuQ== 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=JTPqqzl61LcXZknOh3vX8Y4ZIjcvIm2PCMu/cmAquKI=; b=c+W6PXs86ivnbT/jsAHDENT0NSkmc6C/CkJ0B+KYaQP1Mc0b7czQ6qCkfk5l6PhWgd ELylHN6bheKjp2CW1THsKnWi6wdz/dSNhUoypdDLc/lARMksBrBzK/HC5IDlSv0TUUpK 3MGH32pPsZLnUbnjQz9/l01U3qXuubuJbxwVfVRZNAITqI9ZriIXs8nwXNurKHaqwlGy RP/WzehDm4S00Fh1hrZZ6LpKS3Dvu/EfTKPkh5bSvy6DUhT/fiTlVK8NPrFEUMcbU0r0 FQOPx4+UqVtTHfRLAccQ7yO/fNfC5wS6DfgVyiGd0uHg/bEP7kC+3aXaG59xrVA7dxm4 e4Gg== 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 31si47996plz.290.2019.06.06.13.21.51; Thu, 06 Jun 2019 13:22:07 -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 S1726970AbfFFUSC (ORCPT + 99 others); Thu, 6 Jun 2019 16:18:02 -0400 Received: from mga07.intel.com ([134.134.136.100]:42899 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729659AbfFFURk (ORCPT ); Thu, 6 Jun 2019 16:17:40 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jun 2019 13:17:31 -0700 X-ExtLoop1: 1 Received: from yyu32-desk1.sc.intel.com ([143.183.136.147]) by fmsmga001.fm.intel.com with ESMTP; 06 Jun 2019 13:17:30 -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 v7 03/14] x86/cet/ibt: Add IBT legacy code bitmap setup function Date: Thu, 6 Jun 2019 13:09:15 -0700 Message-Id: <20190606200926.4029-4-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190606200926.4029-1-yu-cheng.yu@intel.com> References: <20190606200926.4029-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 Indirect Branch Tracking (IBT) provides an optional legacy code bitmap that allows execution of legacy, non-IBT compatible library by an IBT-enabled application. When set, each bit in the bitmap indicates one page of legacy code. The bitmap is allocated and setup from the application. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/cet.h | 1 + arch/x86/kernel/cet.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/arch/x86/include/asm/cet.h b/arch/x86/include/asm/cet.h index 89330e4159a9..9e613a6598c9 100644 --- a/arch/x86/include/asm/cet.h +++ b/arch/x86/include/asm/cet.h @@ -31,6 +31,7 @@ void cet_disable_free_shstk(struct task_struct *p); int cet_restore_signal(bool ia32, struct sc_ext *sc); int cet_setup_signal(bool ia32, unsigned long rstor, struct sc_ext *sc); int cet_setup_ibt(void); +int cet_setup_ibt_bitmap(unsigned long bitmap, unsigned long size); void cet_disable_ibt(void); #else static inline int prctl_cet(int option, unsigned long arg2) { return -EINVAL; } diff --git a/arch/x86/kernel/cet.c b/arch/x86/kernel/cet.c index 14ad25b8ff21..e0ef996d3148 100644 --- a/arch/x86/kernel/cet.c +++ b/arch/x86/kernel/cet.c @@ -22,6 +22,7 @@ #include #include #include +#include #include static int set_shstk_ptr(unsigned long addr) @@ -361,3 +362,28 @@ void cet_disable_ibt(void) current->thread.cet.ibt_enabled = 0; } + +int cet_setup_ibt_bitmap(unsigned long bitmap, unsigned long size) +{ + u64 r; + + if (!current->thread.cet.ibt_enabled) + return -EINVAL; + + if (!PAGE_ALIGNED(bitmap) || (size > TASK_SIZE_MAX)) + return -EINVAL; + + current->thread.cet.ibt_bitmap_addr = bitmap; + current->thread.cet.ibt_bitmap_size = size; + + /* + * Turn on IBT legacy bitmap. + */ + modify_fpu_regs_begin(); + rdmsrl(MSR_IA32_U_CET, r); + r |= (MSR_IA32_CET_LEG_IW_EN | bitmap); + wrmsrl(MSR_IA32_U_CET, r); + modify_fpu_regs_end(); + + return 0; +} -- 2.17.1