Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3307945imu; Mon, 19 Nov 2018 13:57:15 -0800 (PST) X-Google-Smtp-Source: AJdET5es5u9pgIJI15Mr3SQB3Vwq224Z+5vk+xXLqKP24laewNBrORzstgfeI/JY7l83QcJC5lS3 X-Received: by 2002:a65:6148:: with SMTP id o8mr21673735pgv.451.1542664635222; Mon, 19 Nov 2018 13:57:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542664635; cv=none; d=google.com; s=arc-20160816; b=b0xgUSVAmeyRmOicVRhf2CS8+J4w6E3cEIaHHPFWjH1l/1ET185D6YdfBdwKLHuBh4 dZsKxvjs8Hrn8Pr6JQYyw0dDLlX3fvY/KN3Ttn6wkSB4xOccOKtLH3pvIigSJGu4/qst tAwMvdt3E4FHdbMMkt7WZVkhAexGNJZb9ig14PjB8czJ/BB56CfV6oH2eLHTJFV8fMgx sGz1tZkk2nGMc/+5JLMBWaOgb/WTWXLr3aLie4GxVyaYN3JRIrR7Edxckx2USNPYmcBu 2B1kZtHeZpoDUoUP8XZpjfa2A+xmaTTUXKjN6TdL4seEjpNKPMDM2V1XE6FzCQsFis8q PVHw== 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=qwvBk6j/AQhaRu5D52VWCF3xBckwceEXvsvcLNj5iAY=; b=ad8STVuBkrHwHcBhQQxkcFTAZMccEXq/RQUYS9GBWjW7GLvWEH4X4dZSwgy8e3Lutb JI3FtlJPjG1z6DMVoXJJ3mBhglkGyvJ6+7kUQ4GSy30FAl+pLmyq8srLoGaHlMG3kwui PUK5i4TP/wGT6SOtKe6lSmi+B+Jan6uJRzkO/ZenhzwkUrkdhl/f1NiIeZLYvbjxExyV CfZzMK7II8k9boWb0i04GB7LiJLYlXgbn2x3QWomE3DKPCsn3lADC0aYtwkjJCbUfCnH VGmpwHFf6RjObcZgOp8pLHit+G09uzGwMdxte2x3mOEXyinYN2TKcr0piSSpbZtKfE8d 7+5w== 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 cc17si11081402plb.265.2018.11.19.13.57.00; Mon, 19 Nov 2018 13:57:15 -0800 (PST) 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 S1731735AbeKTIUh (ORCPT + 99 others); Tue, 20 Nov 2018 03:20:37 -0500 Received: from mga09.intel.com ([134.134.136.24]:32114 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731707AbeKTIUg (ORCPT ); Tue, 20 Nov 2018 03:20:36 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Nov 2018 13:54:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,254,1539673200"; d="scan'208";a="92423889" Received: from yyu32-desk1.sc.intel.com ([143.183.136.147]) by orsmga006.jf.intel.com with ESMTP; 19 Nov 2018 13:54:55 -0800 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 , 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 Cc: Yu-cheng Yu Subject: [RFC PATCH v6 03/11] x86/cet/ibt: Add IBT legacy code bitmap setup function Date: Mon, 19 Nov 2018 13:49:26 -0800 Message-Id: <20181119214934.6174-4-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181119214934.6174-1-yu-cheng.yu@intel.com> References: <20181119214934.6174-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 | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/arch/x86/include/asm/cet.h b/arch/x86/include/asm/cet.h index 810d3e386fdb..db40fc54a905 100644 --- a/arch/x86/include/asm/cet.h +++ b/arch/x86/include/asm/cet.h @@ -29,6 +29,7 @@ void cet_disable_free_shstk(struct task_struct *p); int cet_restore_signal(unsigned long ssp); int cet_setup_signal(bool ia32, unsigned long rstor, unsigned long *new_ssp); 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 fd157a6208c3..18a92a92c50f 100644 --- a/arch/x86/kernel/cet.c +++ b/arch/x86/kernel/cet.c @@ -21,6 +21,7 @@ #include #include #include +#include static int set_shstk_ptr(unsigned long addr) { @@ -333,3 +334,25 @@ void cet_disable_ibt(void) wrmsrl(MSR_IA32_U_CET, r); 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. + */ + rdmsrl(MSR_IA32_U_CET, r); + r |= (MSR_IA32_CET_LEG_IW_EN | bitmap); + wrmsrl(MSR_IA32_U_CET, r); + return 0; +} -- 2.17.1