Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2404052pxk; Mon, 14 Sep 2020 12:23:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQ5zkWbkMO3v2JBreqIVARfoge1wfKcdTN7R+hTln3Bh3Yjk/j7L5NgAfNT/0iPHUbATgD X-Received: by 2002:aa7:c053:: with SMTP id k19mr18531247edo.326.1600111387619; Mon, 14 Sep 2020 12:23:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600111387; cv=none; d=google.com; s=arc-20160816; b=w42vvfOtGvYstr1rDMSzDikkJMWqKzFK96246/4tHwPvo5Ju69+izFKh4qbT7XW7Jj pZj306+tSSFVDoaNEG4PODV5sNKzjm1qb+TkjVFAq5natcj/pFE9G6wThgqjnBJIBEjO ESx4PXFgbyckfUR8d7oNHo6RlvKc1MKSZHHSm5Yd+usy93qNuy+0EMSZblHKTXdLRsJW URNOFWJk67LXi5ZphyQ+24Dgo+Wad8appr01wldkmZ5tvzKDpp79gyr23/8cxvAVgSwy wGe0sq6JekkA9veO+jIxV2UX7kogSX4jqx3oSwGamO2yk+k07FpHQnpbg3Gj52XhYqhQ ROCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=8jSEFTyJ+w6ij2V9TokmUN4inhCXKie+z9VF4m//R0w=; b=PqdHRKnXgPmX3pupq+G51/DUYzc+wIjdwnx729adygCYe9j295PlraYl+zFggcNj3G r1rVsxU7/smWQWq1PNwh5K8yQf/SynUyoHamvkJPKQTWUOXumord/sUY5TfRT9wdbvfL HFb6fdR3JBxnVJ+rJEvMvapE9AwG5t/rESOMZ1bSUIKKhUfwACXHwK+09on6HYOQRREP ydHo5I4yrGij3B5XyhbCEQ2+41gBY4fMLbT42UPaGqE96ZQCIMGzkVuABlr3o1GXFDLD 5VWEpi65iStQpqjCq484kBZCfB36Z/3F+OPc3Il0fIfbZ5xKV29MAZBLa+mAchk58J8i LLMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=aZATmy0G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce12si7580248ejb.719.2020.09.14.12.22.44; Mon, 14 Sep 2020 12:23:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=aZATmy0G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726011AbgINTWF (ORCPT + 99 others); Mon, 14 Sep 2020 15:22:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbgINTWE (ORCPT ); Mon, 14 Sep 2020 15:22:04 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0BD9C06174A for ; Mon, 14 Sep 2020 12:22:04 -0700 (PDT) Received: from zn.tnic (p200300ec2f09260089ebb5f4b84dd95c.dip0.t-ipconnect.de [IPv6:2003:ec:2f09:2600:89eb:b5f4:b84d:d95c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 2E31E1EC0593; Mon, 14 Sep 2020 21:22:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1600111322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=8jSEFTyJ+w6ij2V9TokmUN4inhCXKie+z9VF4m//R0w=; b=aZATmy0G8FAmk4SF5MlHub1oa8Ze29oUuaPascdcShxSfcRpoMNf/N0qFawp6lEmyk8oHE ELYTNbQOfMJitZlQLmtttM+/6MErfCq4vwsjmzmqeJhJZKgm9p2yiRi8JjFrtpbLVfPDy4 XZS/3UHMdUm4nNi7wW37IBIYYJurQ2o= Date: Mon, 14 Sep 2020 21:21:56 +0200 From: Borislav Petkov To: Dan Williams Cc: Josh Poimboeuf , X86 ML , Al Viro , Linux Kernel Mailing List , Linus Torvalds , Will Deacon , Andrea Arcangeli , Waiman Long , Peter Zijlstra , Thomas Gleixner , Andrew Cooper , Andy Lutomirski , Christoph Hellwig , David Laight , Mark Rutland Subject: Re: [PATCH v3] x86/uaccess: Use pointer masking to limit uaccess speculation Message-ID: <20200914192156.GG680@zn.tnic> References: <1d06ed6485b66b9f674900368b63d7ef79f666ca.1599756789.git.jpoimboe@redhat.com> <20200914175604.GF680@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 14, 2020 at 11:48:55AM -0700, Dan Williams wrote: > > Err, stupid question: can this macro then be folded into access_ok() so > > that you don't have to touch so many places and the check can happen > > automatically? > > I think that ends up with more changes because it changes the flow of > access_ok() from returning a boolean to returning a modified user > address that can be used in the speculative path. I mean something like the totally untested, only to show intent hunk below? (It is late here so I could very well be missing an aspect): diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index 2bffba2a1b23..c94e1589682c 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -92,8 +93,15 @@ static inline bool pagefault_disabled(void); */ #define access_ok(addr, size) \ ({ \ + bool range; \ + typeof(addr) a = addr, b; \ + \ WARN_ON_IN_IRQ(); \ - likely(!__range_not_ok(addr, size, user_addr_max())); \ + \ + range = __range_not_ok(addr, size, user_addr_max()); \ + b = (typeof(addr)) array_index_nospec((__force unsigned long)addr, TASK_SIZE_MAX); \ + \ + likely(!range && a == b); \ }) /* -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette