Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1544712ybm; Sat, 30 May 2020 12:16:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQrGJyJDZQQE718LurTNwkrQBI3jIDi8X4z5YohgWb/jiolVSGjcpL0I25Yeb6naaxTlSI X-Received: by 2002:a17:906:49c7:: with SMTP id w7mr13612491ejv.402.1590866194195; Sat, 30 May 2020 12:16:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590866194; cv=none; d=google.com; s=arc-20160816; b=w+c0/tvZCNcdiLU0GK7/ONrNeO/AWhhVV8vgpj+Tqqj/YnJALPFKXSCN06M1t6o1KU Q8Bj0jnQMVwD6ac2/1YmnEkFi5CT1zdkiNeiYi4UD4+JEY1vjUrjyaZdppqYDdnrFQsW PBep6N5aj64SPOtvRdmqvFXaWjKggQVYCRwZxTm3DSTxxQyZZ6dZr6ZWSlrqrqHyHfbb p0i39zFsqa55aLXr4ll7nYrmNMoMoLb2JHt6wHOuk/pOq0W/jZXjxZNuhfjUaqfUTtPP KyxJvMpaU63JEmDw2ErSfykKqHIWNVQO5SdCZ/lKxXvTBLRMuNS0SDOWKzdNiZlv6Xz0 L4nQ== 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; bh=aC/wwX8yxclIIyI7bF7CAwcHmqAEREGK8Rf50N5b1I0=; b=TYaYuM/0fopLyHb8jjW+fBib2McBPuyg4Erg3/k8oJdw8FvvQOcrG+/Fn0V8vJK0rD q9KCFh740CUjDZzQySkHVn5B1JZJF7v8FnsBGftVGOmZKsiLFssp8EFaB+VrE6s/am5K SWJcQAE43jawPi6hJKk2IAOx0R6s+kJ0GOKwEOjEdbahTM652NjYE7byRJApM0aeXO2s Kf26FxlM+1zo1Pc7/t8Rkw+cvoHFqDlp6oXKJ7Hu9FKsiv7YwOgaLwe2KB+84NsYa+7n xjYY2YUGBxPAIOO453PlPpbHXPcXzoOhbhTps3lxx3B+8npDpc3zJ3whh58abwbOhmeX Gzag== ARC-Authentication-Results: i=1; mx.google.com; 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 ch28si7457922edb.90.2020.05.30.12.16.10; Sat, 30 May 2020 12:16:34 -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; 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 S1729284AbgE3TOa (ORCPT + 99 others); Sat, 30 May 2020 15:14:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728998AbgE3TOa (ORCPT ); Sat, 30 May 2020 15:14:30 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 352F5C03E969; Sat, 30 May 2020 12:14:30 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.93 #3 (Red Hat Linux)) id 1jf6w4-000YbD-9X; Sat, 30 May 2020 19:14:24 +0000 Date: Sat, 30 May 2020 20:14:24 +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: <20200530191424.GR23230@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> <20200530143147.GN23230@ZenIV.linux.org.uk> <81563af6-6ea2-3e21-fe53-9955910e303a@redhat.com> <20200530183853.GQ23230@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 Sat, May 30, 2020 at 11:52:44AM -0700, Linus Torvalds wrote: > > It really isn't. > > Your very first statement shows how broken it is: > > > FWIW, the kvm side of things (vhost is yet another pile of fun) is > > > > [x86] kvm_hv_set_msr_pw(): > > arch/x86/kvm/hyperv.c:1027: if (__copy_to_user((void __user *)addr, instructions, 4)) > > HV_X64_MSR_HYPERCALL > > arch/x86/kvm/hyperv.c:1132: if (__clear_user((void __user *)addr, sizeof(u32))) > > HV_X64_MSR_VP_ASSIST_PAGE > > in both cases addr comes from > > gfn = data >> HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT; > > addr = kvm_vcpu_gfn_to_hva(vcpu, gfn); > > if (kvm_is_error_hva(addr)) > > return 1; > > Just look at that. You have _zero_ indication that 'adds" is a user > space address. It could be a kernel address. > > That kvm_vcpu_gfn_to_hva() function is a complicated mess that first > looks for the right 'memslot', and basically uses a search with a > default slot to try to figure it out. It doesn't even use locking for > any of it, but assumes the arrays are stable, and that it can use > atomics to reliably read and set the last successfully found slot. > > And none of that code verifies that the end result is a user address. kvm_is_error_hva() is return addr >= PAGE_OFFSET;