Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp959187ybm; Fri, 29 May 2020 16:55:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwy3UYlZoNFhTS+3cmUsQL1Y1Pz7Id8OB3lC1WTb4Zq/grJ/KnKzXNdYLQiw7xwaVo/j/rq X-Received: by 2002:a17:906:ece4:: with SMTP id qt4mr9569424ejb.162.1590796549512; Fri, 29 May 2020 16:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590796549; cv=none; d=google.com; s=arc-20160816; b=YQ/JpogEiy7sGiiWBQowamqMaVrRs4TsGxKgx3rJ5J4Hi7AylXZAZtCjtY7FqflOPY f9rw1VfTai1OyM2vse7Okq8JwfzK2QNTBSFohRudAEGfl/V9vd41uDpnFYaGyf495dhS ZNQ5UtimL5BGoIom3QtH4z7dAFsWyN500q45oTPsFMNENXDtFVASjp0HuPhLQBRvGBz5 zI/L/7jPhc0ugAPSJ0CQVjxja+DUpilUwYykGSqVfAJk/3wgNzqPCvruC5bPbh0GRWQR 7/aPIiuFGH3EesOhcteVGPFe55FgSIeWCJz8F89DKy2Oe7BfYsrYn+xAM1qW2GxO+yxh jn8Q== 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 :in-reply-to:references:mime-version:dkim-signature; bh=ICQtGJtrHJozomkdHTEOkutnUdLdZAowcRpo4XmM9/g=; b=WIfQFSSmwAWWWesDhsD9o2IHBK0SOAVS0LcdHu1vUlNFxjSpAueDPi+bUf7PXKZwIs rroVKJdZ3tBoW+1V/o0tXRE8KDbe2w4STYsIeZ8E7FiadngzWpMeD1OLYd+y/R6BOtms 1qDHUyDKdzaK7/8O/l8D9COQo65PJA291gCErJKa3tuIWRm9uc/dw4/Qvgp5wb/Yzhf+ i5XuVC01fS0V168JdmGPaz3ezuZPO2U4ynLDSiGR3AH+zT8TcZTra014MrV1b93SmvYB 4ulRYj8CWs9BR6jT/I17/PaZZIz/mCkJV/SMNNAUNanyZSIdKF2d+lua6nUxzkf1Tp2d /LkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=BKeekuZS; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s23si6509330edr.581.2020.05.29.16.55.26; Fri, 29 May 2020 16:55:49 -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=@linux-foundation.org header.s=google header.b=BKeekuZS; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728596AbgE2XxV (ORCPT + 99 others); Fri, 29 May 2020 19:53:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728293AbgE2XxU (ORCPT ); Fri, 29 May 2020 19:53:20 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF1C9C08C5C9 for ; Fri, 29 May 2020 16:53:19 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id z206so698442lfc.6 for ; Fri, 29 May 2020 16:53:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ICQtGJtrHJozomkdHTEOkutnUdLdZAowcRpo4XmM9/g=; b=BKeekuZS2zieYlq8mdCl6fz+pBpw9xzAhVyL+t5zKZaRWVqur00axzXw7v4sCNC5hv /1qWi5dvtrM55OwtMCQDzQrBrRFVZyYWsemIazEDWdf1hT4pNTGgP4ShCOvtAVfGGELX 29aIJ+f8wXXFr8dj738yQ8rtoM6Aj7PLxA5II= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ICQtGJtrHJozomkdHTEOkutnUdLdZAowcRpo4XmM9/g=; b=Q7pNGMIeSD5ULgFJjaepTxvZLRNmbj9V8oj36Tld7OevHerOXGOTGRPctuzH0GQevg 5iJXxl3pbr2i5VaDhka4nZv0TDJ0IlrgqaGO9C8MTLsDV8MIADgS82OP+nD9gOZ6YWS8 sBMbIRADFQ5YvbjZtvQH/UKkETLBYm8il9EDIvelHIquqS7ZVlRyLNez0AMqx+QxhpyW BHjvRtGTOCXn5tgQbl6g9KbiJWnX0LaJrkI+xWkLIofDL0uw92QSMYuUz12Ysq4PcRhO yJN/LV5DlEekjqyLWwlVcwoyxT327S/qk5ugka1Tlb7oKYUhYqKePHHcygrUA9E9Qxr0 VGQA== X-Gm-Message-State: AOAM530HSW5n3l+9SgW9zCB+/f1CITwYAj6qOVBltudMPjn7PiXRQHJ4 lGqjgOdWH+ctOwcYtAPT12ueLUjcdbo= X-Received: by 2002:a19:987:: with SMTP id 129mr5674951lfj.8.1590796396874; Fri, 29 May 2020 16:53:16 -0700 (PDT) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com. [209.85.208.182]) by smtp.gmail.com with ESMTPSA id f18sm2584075lfh.49.2020.05.29.16.53.15 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 29 May 2020 16:53:16 -0700 (PDT) Received: by mail-lj1-f182.google.com with SMTP id k5so1285150lji.11 for ; Fri, 29 May 2020 16:53:15 -0700 (PDT) X-Received: by 2002:a2e:8090:: with SMTP id i16mr4658232ljg.421.1590796395104; Fri, 29 May 2020 16:53:15 -0700 (PDT) MIME-Version: 1.0 References: <20200528234025.GT23230@ZenIV.linux.org.uk> <20200529232723.44942-1-viro@ZenIV.linux.org.uk> <20200529232723.44942-8-viro@ZenIV.linux.org.uk> In-Reply-To: <20200529232723.44942-8-viro@ZenIV.linux.org.uk> From: Linus Torvalds Date: Fri, 29 May 2020 16:52:59 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 8/9] x86: kvm_hv_set_msr(): use __put_user() instead of 32bit __clear_user() To: Al Viro , Paolo Bonzini Cc: Linux Kernel Mailing List , linux-fsdevel , KVM list 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 Fri, May 29, 2020 at 4:27 PM Al Viro wrote: > a/arch/x86/kvm/hyperv.c > - if (__clear_user((void __user *)addr, sizeof(u32))) > + if (__put_user(0, (u32 __user *)addr)) I'm not doubting that this is a correct transformation and an improvement, but why is it using that double-underscore version in the first place? There's a __copy_to_user() in kvm_hv_set_msr_pw() in addition to this one in kvm_hv_set_msr(). Both go back to 2011 and commit 8b0cedff040b ("KVM: use __copy_to_user/__clear_user to write guest page") and both look purely like "pointlessly avoid the access_ok". All these KVM "optimizations" seem entirely pointless, since access_ok() isn't the problem. And the address _claims_ to be verified, but I'm not seeing it. There is not a single 'access_ok()' anywhere in arch/x86/kvm/ that I can see. It looks like the argument for the address being validated is that it comes from "gfn_to_hva()", which should only return host-virtual-addresses. That may be true. But "should" is not "does", and honestly, the cost of gfn_to_hva() is high enough that then using that as an argument for removing "access_ok()" smells. So I would suggest just removing all these completely bogus double-underscore versions. It's pointless, it's wrong, and it's unsafe. This isn't even some critical path, but even if it was, that user address check isn't where the problems are. Linus