Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1527764ybm; Sat, 30 May 2020 11:44:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6TqWAriKNuXgUEVH0J6VacTsyzzN2yB5bUwgLrGbg7qrHNmRDky+4xb79WvT1yS7u7mPa X-Received: by 2002:aa7:d98c:: with SMTP id u12mr14093515eds.85.1590864264266; Sat, 30 May 2020 11:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590864264; cv=none; d=google.com; s=arc-20160816; b=WYBuAyDhxArX1CDNzyNZ5eRGzmCr2WfhfWGJ4ql9F3OIE+ojpwhJqibOiFeb8w7JZB UizHQvFTkGRoUtjSD5xE+V9x+oHlwSZKyt63FGdUip4s+TO95lbiawAN2StqElIVGcYr Ic+DmRAjgN1jpVe1Mw10pBLgReChO33wtyNFNOzKMdB35eLxsOOs2065W0CnOewgBrFz X0grjTjzCwQ8pG5IeR1rfITqOfWA30KOgFHlYDDNGTlUQFMjCCh2WsdQgFyqUZqy6gYy bqO17RQ6VhG93xAVv3HgeEK8UD3kbUp6YpBV8zbqZyU87/R/ua0j6Z933UNAP6Eygnxo 2qtg== 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=6ArZnlwEw1ZmYG4SV6GqsezvC0B/txWQeTH7p5xDbV8=; b=Ia1JvdqokGAMRyhP7GDs3zOZ/aHDVq4+grC2ySa4pJY6kKHIDNC5JiRYM7BRuxBzcw 6ty3TbIaFemyV9Qsy8V5+9ZiPllcc0+SJmhbS1jumgMHYV2wDnp2bvz3dMPJfcTuF7E3 hntMYHbMSBsNhHhCjlLPGlpDa0xwPLYZMcjh3zY00T+UlgrZxrnvEsuGssnEWs9bo2/f F9YZJCzQLHfSWZr584AnTLDwe1qFGqPEJ/vsvK21fw3OQVA/fJ1bUTf50p9x+4mQnJSf hSpO8RzoBTLPYIZxD1k9Im2HhbxKzddKQBCWRc7s1csTH330VnbcOAT8F9OTFb422mfW Kdvg== 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 ds7si3697378ejc.717.2020.05.30.11.43.25; Sat, 30 May 2020 11:44:24 -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 S1729296AbgE3SjF (ORCPT + 99 others); Sat, 30 May 2020 14:39:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729149AbgE3SjE (ORCPT ); Sat, 30 May 2020 14:39:04 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D386C03E969; Sat, 30 May 2020 11:39:04 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.93 #3 (Red Hat Linux)) id 1jf6Nh-000XsX-Rs; Sat, 30 May 2020 18:38:53 +0000 Date: Sat, 30 May 2020 19:38:53 +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: <20200530183853.GQ23230@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> 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 10:57:24AM -0700, Linus Torvalds wrote: > So no. I disagree. There is absolutely nothing "obviously ok" about > any of that kvm code. Quite the reverse. > > I'd argue that it's very much obviously *NOT* ok, even while it might > just happen to work. Actually, it's somewhat less brittle than you think (on non-mips, at least) and not due to those long-ago access_ok(). > That double underscore needs to go away. It's either actively buggy > right now and I see no proof it isn't, or it's a bug just waiting to > happen in the future. 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; [x86] FNAME(walk_addr_generic), very hot: arch/x86/kvm/mmu/paging_tmpl.h:403: if (unlikely(__get_user(pte, ptep_user))) index = PT_INDEX(addr, walker->level); ... offset = index * sizeof(pt_element_t); ... host_addr = kvm_vcpu_gfn_to_hva_prot(vcpu, real_gfn, &walker->pte_writable[walker->level - 1]); if (unlikely(kvm_is_error_hva(host_addr))) goto error; ptep_user = (pt_element_t __user *)((void *)host_addr + offset); __kvm_read_guest_page(): virt/kvm/kvm_main.c:2252: r = __copy_from_user(data, (void __user *)addr + offset, len); addr = gfn_to_hva_memslot_prot(slot, gfn, NULL); if (kvm_is_error_hva(addr)) return -EFAULT; __kvm_read_guest_atomic(): virt/kvm/kvm_main.c:2326: r = __copy_from_user_inatomic(data, (void __user *)addr + offset, len); addr = gfn_to_hva_memslot_prot(slot, gfn, NULL); if (kvm_is_error_hva(addr)) return -EFAULT; __kvm_write_guest_page(): virt/kvm/kvm_main.c:2353: r = __copy_to_user((void __user *)addr + offset, data, len); addr = gfn_to_hva_memslot(memslot, gfn); if (kvm_is_error_hva(addr)) return -EFAULT; kvm_write_guest_offset_cached(): virt/kvm/kvm_main.c:2490: r = __copy_to_user((void __user *)ghc->hva + offset, data, len); if (kvm_is_error_hva(ghc->hva)) return -EFAULT; kvm_read_guest_cached(): virt/kvm/kvm_main.c:2525: r = __copy_from_user(data, (void __user *)ghc->hva, len); if (kvm_is_error_hva(ghc->hva)) return -EFAULT; default kvm_is_error_hva() is addr >= PAGE_OFFSET; however, on mips and s390 it's IS_ERR_VALUE(). Sure, we can use non-__ variants, but is access_ok() the right primitive here? We want userland memory, set_fs() be damned.