Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp520304ybi; Fri, 7 Jun 2019 11:56:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxi/F39oidUlLyMM4wSldH5luyxB3tl0NHaFyA63odbwVY6Y/PJ9neS6MMKg7f+uZ7GuY6 X-Received: by 2002:a17:90a:77c4:: with SMTP id e4mr7626936pjs.86.1559933795087; Fri, 07 Jun 2019 11:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559933795; cv=none; d=google.com; s=arc-20160816; b=fL43E+KOO4QxdrVQvbkbRaItZbZ1OlMioa67F3qPq/c5d0ZqwhiGT+nWlpYR5pZRPn W9iJD5g8pHuCZDSkZvLM2rlIx31s/XVdjJc5pSkKX+DwSWmhl02fFrbnVEdX0vPWVFBG aXnaF56HqMuBkot6RUYL3vTP7HAnrnSNyepTD+HsSEh+tEnWFdgR6zA4SWwIYr+2Vq15 AkUgN+n7NpeaScFZToJ9DohK9jrY1rnpM+1mCbK4wosK4YxTe3nU/xN6HKZdN74tmu8u Ir+0egzTdy2LGDZER9muB/hzfnHV9qgAmT8waFLiwifok2ybQYPRpKr7Bf9vCl+4qKea pObw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=DgtSX/H6NfPgrhihV60ypaHNzH2XLKDDtBMwkkXJEQM=; b=hdCGta/9SziCFv0WGW2UOCYPluwuSzBC8YUjskZnsUxdYX/OpHVJqjXKQlVtESWpow JmJ6HzIMwPuewzCCGRbfIBo+qzzSqOQcDnn7hTmj/kLlto/R2u0G9L1GA9q/BZIM6HG1 GZQ0hkLaO+BuTEwhG9XRJSLlLh6/iwBBUHccIlFC1UfLxUUOnlsTeQrZFIs7rmXHriQE U8EBDv6C7lOfcQPmjLmG/bhGgo5rMxb7Xbrg8JV8PB98JuzLjMZLBdGe/URjzVY2wwsX Umfe6Z+OXUabGULdIDI1bFIc0olXoA+Q+VXNdaSAxTMGt3XzAmoPJcTIbBI5ecBDXyR5 /ImQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=K15lDwrH; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w13si2853980pge.212.2019.06.07.11.56.08; Fri, 07 Jun 2019 11:56:35 -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; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=K15lDwrH; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730014AbfFGRFT (ORCPT + 99 others); Fri, 7 Jun 2019 13:05:19 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40285 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729944AbfFGRFS (ORCPT ); Fri, 7 Jun 2019 13:05:18 -0400 Received: by mail-pg1-f194.google.com with SMTP id d30so1470398pgm.7 for ; Fri, 07 Jun 2019 10:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=DgtSX/H6NfPgrhihV60ypaHNzH2XLKDDtBMwkkXJEQM=; b=K15lDwrHU+QByMLUcGsPxdOnNlJhavwl5vzG6kxYPkx7YmYvZeW1ck5JO0OoObB5Xa bYOzIyKVQ7hz1tKrFJw+d10DsxIcYUogKFKziY6bC49Z4sqMZGz+GKrut1kqgjD9iqnD Iy7yuXdRlEQo1JJypK02SCFJ3fiU6aXucnVYHIUhOl0FC0rrAuLNGfNaBUSjjY0SJP0O g+9/YMoWXJmfYyZUowSn5eE6XZng5m+uDKaxwLeh1WtwbitTB4KCIgvTiJtDprK4A3Nl yGxKspKE+tdnIrdwE1lKLqeXOSavRevLlFIkM3wUJcLjFBoUe06Q+MLv/g4yKH03/nvj qypA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=DgtSX/H6NfPgrhihV60ypaHNzH2XLKDDtBMwkkXJEQM=; b=YTgzAzMeHMrO4rWIwi5GiQ7SHzuDUrUbN7eWepY3219rU+UVUc1/hgfx0wDYcG8ChG QivU5qz8fcfN9x/VTNIQP8Z8xqYdSIveH0mlhsv2NOTet6o8GTFz3/tVxZ82jVw4+C7E ewv/u1do6njRzrX1sykJ5ciqfQE1f9JVIvf4uQA1ykp/kgURpaJDQGtNoXhfCCL1aoJW sjYn7l3gZgofqk5b/0sGL/LXa0mVuOIT2ifEVtZvjN58Q3z185uj/+aueBcUV3uDRBON H0EpRLbHP/eZyVIdXhiyrX75Utg6UCtc+tYrczQbLiMZhl0IS/nL+XI3sVEG8xGRqzUQ XKeQ== X-Gm-Message-State: APjAAAVYXQoHqyHoKzEOAo6+jZJXJCg8AaHOlkOefGX/32HZ0kaAHzC3 4agiSt3xf0SBF8nak/LlGPmTgw== X-Received: by 2002:a17:90a:24e4:: with SMTP id i91mr7053557pje.9.1559927117889; Fri, 07 Jun 2019 10:05:17 -0700 (PDT) Received: from ?IPv6:2600:1012:b044:6f30:60ea:7662:8055:2cca? ([2600:1012:b044:6f30:60ea:7662:8055:2cca]) by smtp.gmail.com with ESMTPSA id b2sm2609638pgk.50.2019.06.07.10.05.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 10:05:15 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: [PATCH v7 03/14] x86/cet/ibt: Add IBT legacy code bitmap setup function From: Andy Lutomirski X-Mailer: iPhone Mail (16F203) In-Reply-To: Date: Fri, 7 Jun 2019 10:05:13 -0700 Cc: Peter Zijlstra , 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 , 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 , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin Content-Transfer-Encoding: quoted-printable Message-Id: References: <20190606200926.4029-1-yu-cheng.yu@intel.com> <20190606200926.4029-4-yu-cheng.yu@intel.com> <20190607080832.GT3419@hirez.programming.kicks-ass.net> <76B7B1AE-3AEA-4162-B539-990EF3CCE2C2@amacapital.net> To: Yu-cheng Yu Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Jun 7, 2019, at 9:45 AM, Yu-cheng Yu wrote: >=20 > On Fri, 2019-06-07 at 09:35 -0700, Andy Lutomirski wrote: >>> On Jun 7, 2019, at 9:23 AM, Yu-cheng Yu wrote: >>>=20 >>>>> On Fri, 2019-06-07 at 10:08 +0200, Peter Zijlstra wrote: >>>>> On Thu, Jun 06, 2019 at 01:09:15PM -0700, Yu-cheng Yu wrote: >>>>> 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. >>>>>=20 >>>>> The bitmap is allocated and setup from the application. >>>>> +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 =3D bitmap; >>>>> + current->thread.cet.ibt_bitmap_size =3D size; >>>>> + >>>>> + /* >>>>> + * Turn on IBT legacy bitmap. >>>>> + */ >>>>> + modify_fpu_regs_begin(); >>>>> + rdmsrl(MSR_IA32_U_CET, r); >>>>> + r |=3D (MSR_IA32_CET_LEG_IW_EN | bitmap); >>>>> + wrmsrl(MSR_IA32_U_CET, r); >>>>> + modify_fpu_regs_end(); >>>>> + >>>>> + return 0; >>>>> +} >>>>=20 >>>> So you just program a random user supplied address into the hardware. >>>> What happens if there's not actually anything at that address or the >>>> user munmap()s the data after doing this? >>>=20 >>> This function checks the bitmap's alignment and size, and anything else i= s >>> the >>> app's responsibility. What else do you think the kernel should check? >>>=20 >>=20 >> One might reasonably wonder why this state is privileged in the first pla= ce >> and, given that, why we=E2=80=99re allowing it to be written like this. >>=20 >> Arguably we should have another prctl to lock these values (until exec) a= s a >> gardening measure. >=20 > We can prevent the bitmap from being set more than once. I will test it. >=20 I think it would be better to make locking an explicit opt-in.=