Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3308598imu; Mon, 19 Nov 2018 13:58:04 -0800 (PST) X-Google-Smtp-Source: AJdET5fwIKgqwlXAfxAoiaSnD81mmBjNwQNLyiJMD4XshgScI7w67Q+cEq/HNih0Aki0DgyOKfnF X-Received: by 2002:a63:4e15:: with SMTP id c21mr21784517pgb.50.1542664684301; Mon, 19 Nov 2018 13:58:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542664684; cv=none; d=google.com; s=arc-20160816; b=07hilFpPcBNTmaCLWHUnfnYXb+4fr1tC6wvUuORdJZ+dcNNxkHAwpIxRsvDygSwSn+ mskdBkf2X558bb1oUup3oUbyIWRWyNldyxaxO5kL8ExiagME0Bjqignm0Kk4kfq3+yv2 2QNbihqOPRTGTSlvpm6S2O8WvnWWHL5zsG0w7R82eZ+9B3aDRISrh0OxHPb7XdIktrEc D+0M2Vd1QVlqaJGmnuz/nV/sxqKrCjB6FiDO1hivVyj65giA2qPWmRW8YMmJZIhIT139 u94MsU7oPPnPRYOnDOB9lTn8L8ASJ1+hXU9IeK0Z1aCvgYz+7ZNOr4gU3S/HvcgmptSl DgrQ== 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=Jr5OEgZMFm1CVpCy6A4/sKFO9JSC7hHXqBtrAH6VUPw=; b=RF86paG3HCkNr+uPshyTCEmVFhF+HF5LlRKJ3aa+fRhVHS7M4JfXYMNBeqeK+EeL3b k/7aMuGCDj8z1r5YEvhvvMQLtsWBtpOj8V95+9cLXKxIYOS0sm3RIiFPPow5w3pgFpFg dlKtt4snuPwArq86NWT0KFf5/545jn6jrHBryuZyQi4BBJuHgDfetfnH1kFWr0dvJZ+h AuJ8yEoFvNIhjAq2rmxuL8xBpCiWpG3hntJQTLZB1NTikysUYEH7Z9e1UqQ1+i/m12em 7tXouDSYWTSxx03JyznehWj/oAjl9XPb+NXFP/h7V1CEKvz3HwbPtKIio39vCeH4OGyV YdzQ== 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 d1-v6si25972129pll.301.2018.11.19.13.57.49; Mon, 19 Nov 2018 13:58:04 -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 S1731790AbeKTIUl (ORCPT + 99 others); Tue, 20 Nov 2018 03:20:41 -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 S1731775AbeKTIUk (ORCPT ); Tue, 20 Nov 2018 03:20:40 -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:55:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,254,1539673200"; d="scan'208";a="92423905" Received: from yyu32-desk1.sc.intel.com ([143.183.136.147]) by orsmga006.jf.intel.com with ESMTP; 19 Nov 2018 13:54:59 -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 06/11] x86/cet/ibt: Add arch_prctl functions for IBT Date: Mon, 19 Nov 2018 13:49:29 -0800 Message-Id: <20181119214934.6174-7-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 Update ARCH_X86_CET_STATUS and ARCH_X86_CET_DISABLE to include Indirect Branch Tracking features. Introduce: arch_prctl(ARCH_X86_CET_SET_LEGACY_BITMAP, unsigned long *addr) Enable the Indirect Branch Tracking legacy code bitmap. The parameter 'addr' is a pointer to a user buffer that has: *addr = IBT bitmap base address *(addr + 1) = IBT bitmap size Signed-off-by: H.J. Lu Signed-off-by: Yu-cheng Yu --- arch/x86/include/uapi/asm/prctl.h | 2 ++ arch/x86/kernel/cet_prctl.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/arch/x86/include/uapi/asm/prctl.h b/arch/x86/include/uapi/asm/prctl.h index d962f0ec9ccf..5eb9aeb5c662 100644 --- a/arch/x86/include/uapi/asm/prctl.h +++ b/arch/x86/include/uapi/asm/prctl.h @@ -18,5 +18,7 @@ #define ARCH_X86_CET_DISABLE 0x3002 #define ARCH_X86_CET_LOCK 0x3003 #define ARCH_X86_CET_ALLOC_SHSTK 0x3004 +#define ARCH_X86_CET_GET_LEGACY_BITMAP 0x3005 /* deprecated */ +#define ARCH_X86_CET_SET_LEGACY_BITMAP 0x3006 #endif /* _ASM_X86_PRCTL_H */ diff --git a/arch/x86/kernel/cet_prctl.c b/arch/x86/kernel/cet_prctl.c index 320dbb620d61..a752d73cb1f4 100644 --- a/arch/x86/kernel/cet_prctl.c +++ b/arch/x86/kernel/cet_prctl.c @@ -21,6 +21,8 @@ static int handle_get_status(unsigned long arg2) if (current->thread.cet.shstk_enabled) features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK; + if (current->thread.cet.ibt_enabled) + features |= GNU_PROPERTY_X86_FEATURE_1_IBT; shstk_base = current->thread.cet.shstk_base; shstk_size = current->thread.cet.shstk_size; @@ -56,6 +58,17 @@ static int handle_alloc_shstk(unsigned long arg2) return 0; } +static int handle_bitmap(unsigned long arg2) +{ + unsigned long addr, size; + + if (get_user(addr, (unsigned long __user *)arg2) || + get_user(size, (unsigned long __user *)arg2 + 1)) + return -EFAULT; + + return cet_setup_ibt_bitmap(addr, size); +} + int prctl_cet(int option, unsigned long arg2) { if (!cpu_x86_cet_enabled()) @@ -70,6 +83,8 @@ int prctl_cet(int option, unsigned long arg2) return -EPERM; if (arg2 & GNU_PROPERTY_X86_FEATURE_1_SHSTK) cet_disable_free_shstk(current); + if (arg2 & GNU_PROPERTY_X86_FEATURE_1_IBT) + cet_disable_ibt(); return 0; @@ -80,6 +95,12 @@ int prctl_cet(int option, unsigned long arg2) case ARCH_X86_CET_ALLOC_SHSTK: return handle_alloc_shstk(arg2); + /* + * Allocate legacy bitmap and return address & size to user. + */ + case ARCH_X86_CET_SET_LEGACY_BITMAP: + return handle_bitmap(arg2); + default: return -EINVAL; } -- 2.17.1