Received: by 10.223.176.46 with SMTP id f43csp516667wra; Fri, 19 Jan 2018 23:00:16 -0800 (PST) X-Google-Smtp-Source: AH8x226loWXS2L338umzRdU+Yhe4yyFNbV1gN3pAIh8WmfIrIapTlH+VwIaKKfYWtKAJ/eAQh4Cy X-Received: by 10.98.17.21 with SMTP id z21mr1293648pfi.86.1516431616109; Fri, 19 Jan 2018 23:00:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516431616; cv=none; d=google.com; s=arc-20160816; b=K4dU8sCmgx38o0I84yj0pD20GfBXoUeB9QHEcCsK8qmoHs7+CquaoovlLbnPxzJnak vy8hJssiM27q7FV98yRDMRgeQ+GUsRcGxYkrAB7Mmx6mwjbbvOdLoMGBPU5dvvtwQMfT AEqQfhp3MFtJ49EsJaEF6PkrlWshCcp9/0cpfJaR440fi5fyg4jkuo1TPXlnHB8lGzRe H36xJ2JmUK01hp311Aly/0YlKVd1nGOttYNtUYkvc1qb37NhfjT8FkPFABNT72Ge6Kgp KLnxmX6qEpzdYLVKObR9gCFoXQFA56qC2MY2DetsFXyazcoMWEoHZJPCM3sKBcEVs8wr nLXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=5duuZthlYGtXdNk0ZxfpuxdlQ4qplnUXYm42b0sAres=; b=ANRkev/qyBcVaGpEx0qOFt/tjG2MchQyn+KjKy3BLy0nt0wIKhIoC9hQikxdqpWnHj XIpFl9COQbjQ9vbJBpY5cGHNkWPRVwxsTPQjMDX1fH8kaY5EOCNKhB1I5aA2iHyPg7Kc 1afwh/lznOjpSUzylXCe/fbNUF5x5ijuuy3wCbMlgL4ylcxx07/d+HVHmnJAyaevyVvX xSxpCAJMtaCqqmwtb4+tSzqpel98yFFQSynYjvIH3FRqD/6WlxnW9wYXHI2usJLM2wLT 4aaZ05Hzqn64hd76OjEJf506c4uQ4nKeqHO4sTBd9CH7uPcrzOvTYIDd/UhnimV/6kEf 2T5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=03zLxkwo; 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 j14si2103174pgf.585.2018.01.19.23.00.02; Fri, 19 Jan 2018 23:00:16 -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; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=03zLxkwo; 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 S1754545AbeATG6w (ORCPT + 99 others); Sat, 20 Jan 2018 01:58:52 -0500 Received: from mail-oi0-f66.google.com ([209.85.218.66]:32804 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751156AbeATG6p (ORCPT ); Sat, 20 Jan 2018 01:58:45 -0500 Received: by mail-oi0-f66.google.com with SMTP id y141so2679442oia.0 for ; Fri, 19 Jan 2018 22:58:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=5duuZthlYGtXdNk0ZxfpuxdlQ4qplnUXYm42b0sAres=; b=03zLxkwoVJUuZGcxHrAbNztNO2YVYAP1Th7jLQnMgpgNsGCF+iNMF8Do37pDBJun1o y4cdm+E6DbmjYegf5jwGxX7jyF6E7EItdM91TC0oS7JNC1wsDmlr9vTdiDavoHmOrGol tf9nwfwHLvsDcYaDVsvn3mJlg4SWL9MJWAOKu+4XVCvWeLrSv3a15D0jZ5ztan3vfv1O EZwMQ7Ktx+To6cpQS+b28ubVtxWaeMfdiExJnswhDlixIdSmhCDCsaE1WvFNQOKl/vvx hyO8N7WxHy7zoOvj1b5JUMwptJdh81Jqu0BIGEbelYhppIYZ/2b7LPjNndQhUK/BOslw GwSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=5duuZthlYGtXdNk0ZxfpuxdlQ4qplnUXYm42b0sAres=; b=VMSTWcAlDdZvhQzKsbwqTKHVraZO3pqW93OWr5+9aexDIQ6mvHDE5OR98ocXzAG0Bn 71pgm1OZ1NVTCuBKyZzZ5JsD9/usvYHRbUWpAHZvwLA+qsgfHHYUTDpAsN4rzNGvYjpB GEQekR9ZyzQ4qfnR9dtd0pfFx0/p+6nkDW+85HAFhD6iu2FHVLSwOxJGNg5yFxQLkFas UDThRWO9SW7KCUuJaWcBpyIWrNTKAFu0aRmQ8po8qAG94BhaEZM2D9vEtamH5+ulyvJW 1XBqfJ9WGIXDZyQhlBujvDWdtZjucGSCEbBFvbiki/5Io7S8S4oU7FSyG4pe/ofiSDcM G3GA== X-Gm-Message-State: AKwxyte9Dwr9NyG1NTN+cWf1R9/BoeJ81uvkZqEbsJ052rjKI1yjb79q OthaTOhe1CKs7g1INasjPdmgLGH/pcKC9skWynfndRNu X-Received: by 10.202.171.14 with SMTP id u14mr475117oie.187.1516431524595; Fri, 19 Jan 2018 22:58:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.62.72 with HTTP; Fri, 19 Jan 2018 22:58:44 -0800 (PST) In-Reply-To: <151632009605.21271.11304291057104672116.stgit@dwillia2-desk3.amr.corp.intel.com> References: <151632009605.21271.11304291057104672116.stgit@dwillia2-desk3.amr.corp.intel.com> From: Dan Williams Date: Fri, 19 Jan 2018 22:58:44 -0800 Message-ID: Subject: Re: [PATCH v4 00/10] prevent bounds-check bypass via speculative execution To: Linux Kernel Mailing List Cc: Mark Rutland , Kernel Hardening , Peter Zijlstra , Catalin Marinas , Will Deacon , "H. Peter Anvin" , Elena Reshetova , linux-arch , Andi Kleen , Jonathan Corbet , X86 ML , Russell King , Ingo Molnar , Andrew Honig , Alan Cox , Tom Lendacky , Kees Cook , Al Viro , Andy Lutomirski , Thomas Gleixner , Andrew Morton , Jim Mattson , Christian Lamparter , Greg KH , Linux Wireless List , stable@vger.kernel.org, Paolo Bonzini , Johannes Berg , Linus Torvalds , "David S. Miller" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 18, 2018 at 4:01 PM, Dan Williams wrote: > Changes since v3 [1] > * Drop 'ifence_array_ptr' and associated compile-time + run-time > switching and just use the masking approach all the time. > > * Convert 'get_user' to use pointer sanitization via masking rather than > lfence. '__get_user' and associated paths still rely on > lfence. (Linus) > > "Basically, the rule is trivial: find all 'stac' users, and use > address masking if those users already integrate the limit > check, and lfence they don't." > > * At syscall entry sanitize the syscall number under speculation > to remove a user controlled pointer de-reference in kernel > space. (Linus) > > * Fix a raw lfence in the kvm code (added for v4.15-rc8) to use > 'array_ptr'. > > * Propose 'array_idx' as a way to sanitize user input that is > later used as an array index, but where the validation is > happening in a different code block than the array reference. > (Christian). > > * Fix grammar in speculation.txt (Kees) > > --- > > Quoting Mark's original RFC: > > "Recently, Google Project Zero discovered several classes of attack > against speculative execution. One of these, known as variant-1, allows > explicit bounds checks to be bypassed under speculation, providing an > arbitrary read gadget. Further details can be found on the GPZ blog [2] > and the Documentation patch in this series." > > A precondition of using this attack on the kernel is to get a user > controlled pointer de-referenced (under speculation) in privileged code. > The primary source of user controlled pointers in the kernel is the > arguments passed to 'get_user' and '__get_user'. An example of other > user controlled pointers are user-controlled array / pointer offsets. > > Better tooling is needed to find more arrays / pointers with user > controlled indices / offsets that can be converted to use 'array_ptr' or > 'array_idx'. A few are included in this set, and these are not expected > to be complete. That said, the 'get_user' protections raise the bar on > finding a vulnerable gadget in the kernel. > > These patches are also available via the 'nospec-v4' git branch here: > > git://git.kernel.org/pub/scm/linux/kernel/git/djbw/linux nospec-v4 I've pushed out a nospec-v4.1 with the below minor cleanup, a fixup of the changelog for "kvm, x86: fix spectre-v1 mitigation", and added Paolo's ack. git://git.kernel.org/pub/scm/linux/kernel/git/djbw/linux nospec-v4.1 diff --git a/include/linux/nospec.h b/include/linux/nospec.h index 8af35be1869e..b8a9222e34d1 100644 --- a/include/linux/nospec.h +++ b/include/linux/nospec.h @@ -37,7 +37,7 @@ static inline unsigned long array_ptr_mask(unsigned long idx, unsigned long sz) unsigned long _i = (idx); \ unsigned long _mask = array_ptr_mask(_i, (sz)); \ \ - __u._ptr = _arr + (_i & _mask); \ + __u._ptr = _arr + _i; \ __u._bit &= _mask; \ __u._ptr; \ })