From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 030E8C433DF for ; Sat, 30 May 2020 14:31:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D1AAF20715 for ; Sat, 30 May 2020 14:31:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729109AbgE3Obx (ORCPT ); Sat, 30 May 2020 10:31:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728927AbgE3Obw (ORCPT ); Sat, 30 May 2020 10:31:52 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46D5DC03E969; Sat, 30 May 2020 07:31:52 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.93 #3 (Red Hat Linux)) id 1jf2WZ-000TFN-2S; Sat, 30 May 2020 14:31:47 +0000 Date: Sat, 30 May 2020 15:31:47 +0100 From: Al Viro To: Linus Torvalds Cc: Paolo Bonzini , Linux Kernel Mailing List , linux-fsdevel , KVM list Subject: Re: [PATCH 8/9] x86: kvm_hv_set_msr(): use __put_user() instead of 32bit __clear_user() Message-ID: <20200530143147.GN23230@ZenIV.linux.org.uk> References: <20200528234025.GT23230@ZenIV.linux.org.uk> <20200529232723.44942-1-viro@ZenIV.linux.org.uk> <20200529232723.44942-8-viro@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 Fri, May 29, 2020 at 04:52:59PM -0700, Linus Torvalds wrote: > 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. It's a bit trickier than that, but I want to deal with that at the same time as the rest of kvm/vhost stuff. So for this series I just went for minimal change. There's quite a pile of vhost and kvm stuff, but it's not ready yet - wait for the next cycle.