From patchwork Thu Oct 11 15:16:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-cheng Yu X-Patchwork-Id: 10636921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 997CD112B for ; Thu, 11 Oct 2018 15:23:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88B972BA19 for ; Thu, 11 Oct 2018 15:23:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8075E2BA61; Thu, 11 Oct 2018 15:23:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 013162BA5C for ; Thu, 11 Oct 2018 15:23:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFC8C6B02A4; Thu, 11 Oct 2018 11:22:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C42E46B02AC; Thu, 11 Oct 2018 11:22:09 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 741046B02A0; Thu, 11 Oct 2018 11:22:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 321B16B02A6 for ; Thu, 11 Oct 2018 11:22:09 -0400 (EDT) Received: by mail-pl1-f199.google.com with SMTP id v4-v6so6505802plz.21 for ; Thu, 11 Oct 2018 08:22:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=1Gs7vOzKcSnO1Z0mJBHrDtF4yXiqvuuOOTyzIpVDKT4=; b=A11aRHDbNWkD9yCzCAeXkBZoIGK7m5MnHeXzVd2syJH+ltBTrtweBRAc5l08u5bAYk ofS0QQntQK+SayhAsYVrtlk26yHu4qTB4pSNdGsyt+/ypX+bzm67zR2FuIoDxvWvyyxr p3AjCiM0ahkBdrAFv3uX6gbe0kO8UK8NbPF4iXMjrsNBa+PInMm7c0n3zqfN/5lKwLM7 nk7vT4lp9Eh8HSj9iRPhr0l31wDPJ0UQVSphKdF/3R7hjM6WGP1WKYHpEdRcSam7u9mG /m/T+Plcz1Whze/KgpIUQLZrx9qTJs78/C6icNWP1Ku8GgEY4hENmbrM35rW7fUyc38K 8Q/A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: ABuFfojV+58OaDFpIYNBBkPsdJOKWDZEVeqKyWgJLBWrZJcf1SAfi8S7 cVDQJ+GT+FKoFzdBdDTlhDN2JNYlhAX6NTRxObOa19StXyMCqhWFMj4PYNLgp5Xo2MQnGFNo5Yh yLyZ9lOr4O3TsmplJjTiJDEmj/ID5FgFXPy10DQmJJOzzgUSdeQGxcROo5IQNMyB1GQ== X-Received: by 2002:a17:902:b90c:: with SMTP id bf12-v6mr2005691plb.259.1539271328881; Thu, 11 Oct 2018 08:22:08 -0700 (PDT) X-Google-Smtp-Source: ACcGV61o0mffTuGsGLyCVSCgQjnfnMcL1AfZvOcsq9K5b+XHv59OPGxylZFkszYmpeB29zu9tQte X-Received: by 2002:a17:902:b90c:: with SMTP id bf12-v6mr2005643plb.259.1539271328072; Thu, 11 Oct 2018 08:22:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539271328; cv=none; d=google.com; s=arc-20160816; b=smrGky1JQEnaw193kkdpY0IJAfRQkc/gKmqVSk7eWBb7JBqxs4UoTINnZjgzuxKU2r S0PPYJ2/fF2Kb0V4XB/UILaZiihTSgE0+2fsh7Hiu4duqIC3iDzzvASoqIhYKY5EkIdK IT687ipryps1OH/sYImnCunjYo8eHgmwy5bJzR0pP1NghpqbGfzgHbm5Pk/PF4pvumnj FAebIZebTtpzLc64U5NeRAVAemt9Fi5+vAorqjUD2vwtfXc+ldwt+dF9mb/zm7HpsoDW nde7o8aLYn2WP7iX622rcFoYtdc7l9QbbKVpznm6cpq3xNdiE694XSQ6Si1fNFYYka8S TvFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=1Gs7vOzKcSnO1Z0mJBHrDtF4yXiqvuuOOTyzIpVDKT4=; b=PBgRRjMZGHhfF016IU7Yhn8g9qlHV6AT4Le4LXiL8aJ6FZ8DesOdcMHxBpzQX4ffBK JSYBzDsNLumPXMGkhUPiX2Zs6mkzF9SjuBQBPPd1/dGvTtgaXegeioyJdU8aQILnU6fx v60rSBUz8Rj8J4kybgGP3kbq2CSAP0YguEXRgQwpIfySupjKxb9CXjRHzTG7LtTHuaQ/ /2lxcRns2yFV730ds+xSE6CAIG4sVN3/oN6TZ9QuBEQ9nZ5YdeBtWWRITnQubmFhNP0m 6zFWB3QWhubl5kVlP/RSNonfNtyGhSl9dtbKaFlUPnl9gXfztT+WUr2UpV+GhFZ3Y/8Z 0zog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga14.intel.com (mga14.intel.com. [192.55.52.115]) by mx.google.com with ESMTPS id a28-v6si14382557pfc.106.2018.10.11.08.22.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 08:22:08 -0700 (PDT) Received-SPF: pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.115 as permitted sender) client-ip=192.55.52.115; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2018 08:22:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,368,1534834800"; d="scan'208";a="77271633" Received: from 2b52.sc.intel.com ([143.183.136.147]) by fmsmga007.fm.intel.com with ESMTP; 11 Oct 2018 08:21:44 -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 , 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: [PATCH v5 06/11] x86/cet/ibt: Add arch_prctl functions for IBT Date: Thu, 11 Oct 2018 08:16:49 -0700 Message-Id: <20181011151654.27221-7-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181011151654.27221-1-yu-cheng.yu@intel.com> References: <20181011151654.27221-1-yu-cheng.yu@intel.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP Update ARCH_X86_CET_STATUS and ARCH_X86_CET_DISABLE to include Indirect Branch Tracking features. Introduce: arch_prctl(ARCH_X86_CET_GET_LEGACY_BITMAP, unsigned long *addr) Enable the Indirect Branch Tracking legacy code bitmap. Allocate the bitmap if the task does not have one. The parameter 'addr' is a pointer to a user buffer. On returning to the caller, the kernel fills the following: *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 | 1 + arch/x86/kernel/cet_prctl.c | 35 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/arch/x86/include/uapi/asm/prctl.h b/arch/x86/include/uapi/asm/prctl.h index d962f0ec9ccf..fd4eae92c733 100644 --- a/arch/x86/include/uapi/asm/prctl.h +++ b/arch/x86/include/uapi/asm/prctl.h @@ -18,5 +18,6 @@ #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 #endif /* _ASM_X86_PRCTL_H */ diff --git a/arch/x86/kernel/cet_prctl.c b/arch/x86/kernel/cet_prctl.c index 320dbb620d61..dc7e9785f5e7 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,31 @@ static int handle_alloc_shstk(unsigned long arg2) return 0; } +static int handle_bitmap(unsigned long arg2) +{ + unsigned long addr, size; + + if (current->thread.cet.ibt_enabled) { + int err; + + err = cet_setup_ibt_bitmap(); + if (err) + return err; + + addr = current->thread.cet.ibt_bitmap_addr; + size = current->thread.cet.ibt_bitmap_size; + } else { + addr = 0; + size = 0; + } + + if (put_user(addr, (unsigned long __user *)arg2) || + put_user(size, (unsigned long __user *)arg2 + 1)) + return -EFAULT; + + return 0; +} + int prctl_cet(int option, unsigned long arg2) { if (!cpu_x86_cet_enabled()) @@ -70,6 +97,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 +109,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_GET_LEGACY_BITMAP: + return handle_bitmap(arg2); + default: return -EINVAL; }