Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp1507434ybm; Sat, 30 May 2020 11:03:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO6VqmE/HUaMDnyDHugL8+CRGcB2Ov4mOxg7crlIg309j9gflcqVlp/PGIoDpm5S3zzJA8 X-Received: by 2002:a17:906:3a43:: with SMTP id a3mr12396181ejf.121.1590861831082; Sat, 30 May 2020 11:03:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590861831; cv=none; d=google.com; s=arc-20160816; b=0m7wRW39Jn2veFoJ3gQSyTfC2ULID2ZFDhWqVR7q6ON3S+muy5Il4CMlw2bac16/BV yMRfilw20uYaIxzzmNNbfZhUotb6giHW45ApNvqTTN/69o0eoXvDGW+vsgQDkYajikKj PmPxpWQ4aq4XH9Vzk8EK6UgllZViRWsfziYDY+S+Jv6A6ZQDlWe/Oh7ZTUKiqsZiP0Wp h9UAUAZunfslLjMH0NB1d45LWFFJYC7kI6F9UOt+UTkLuoLJ6Y55pJ89hD9PTy/2Z72E S0a/+zyoZng4QEhPUy2EMc6aZnR2PJMU40l+IqBbn9LVL3YTW0DvbCl2tnPsJocgJ1im EuaA== 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=oSw9tD6N6PkQVpqgffMdls3duXKGoPYgqTcZw/O/Ajs=; b=P2aSg+W/WJsS0lTutyfVAP3GXrHoPbETjDai/FzjG/qiUWRSWRcfJnM2VdGPAGWxvu MYCVZR2aNBc+pqelZCSVT589EAiDJv+U3UHWMZUMn0hVvkKVHdIOWt3JNGP10/SPfgFz fdpeMvvm98EVPWH0jtk1ON5k5fmkvvfqugjoSuDQQZHOmKBOAVi7kQFoxCxnAyxwr+T+ d1aqzyM+PrqC+HTwzqp2QRV0WSYMIPpE0VIc2q/6ridhfUXnvn0g7djuaMXEgW1QbCEI yoCUFk+9KIsULLY3EIokX8R7gJpgTman8I73looTTJwQashgHele5PQATGMnNMmTYKmy PgmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Lrpv+rXN; 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 a15si7872627edl.138.2020.05.30.11.02.52; Sat, 30 May 2020 11:03:51 -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=Lrpv+rXN; 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 S1729139AbgE3R5r (ORCPT + 99 others); Sat, 30 May 2020 13:57:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729026AbgE3R5p (ORCPT ); Sat, 30 May 2020 13:57:45 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C217C08C5C9 for ; Sat, 30 May 2020 10:57:44 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id m18so3171783ljo.5 for ; Sat, 30 May 2020 10:57:43 -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=oSw9tD6N6PkQVpqgffMdls3duXKGoPYgqTcZw/O/Ajs=; b=Lrpv+rXNeI30WFwiZ3vG/HqSBj3X8LK4/226aM9DIBxsp+rGuUknOUrRMAKhbygxl4 2/b72LXeaiKacrNWcsuKU1yFVjfrDuO9n9ZrCDP6XoASr7ATsfi5/BJRKwLKcRRm019Y q0vVl8iWNZpE3VHVrbGLWaJXKDmyB69Ejad/Q= 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=oSw9tD6N6PkQVpqgffMdls3duXKGoPYgqTcZw/O/Ajs=; b=I5te3HhnQnkqLioAvbXEu0YF6kquAlrtvuP74ly6GiFp4gw0Qw8etJ0VBPQ0rLFRj0 nZjPEAo+Sl5m9xjLG0nb4d+Tq9IdS+Gf+qB6dYt/yrwlspZ6JE1JUtGMrYU2oFD3gnt1 aZUrDMQvw2i+qOwn752y0JF9XETTDuRpNxdJ5/L3sOEPEB9CfuAT3IoqLHFMsh2IblgW jl0QFGcJCg38lqNzxCAK4e73X2Cj5ibQ4BQsAbg4KfNKtwL0r3rrYoa58qgX1cuh3syM ykgqbEtsnIVL6OeIvi2QYxH07FPGSgLVycj36+td7mzEOE3OgqgW4eY4Ffgan0NVS3Br u98Q== X-Gm-Message-State: AOAM533qNTNj623US25L+LQ8k/DpVdzBpS0B6sF/XsN2OpWEM2VO86Wz SkdqgwDJO/3WMsGBf+noLsFQTw5gZ80= X-Received: by 2002:a05:651c:54e:: with SMTP id q14mr3939895ljp.279.1590861461869; Sat, 30 May 2020 10:57:41 -0700 (PDT) Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com. [209.85.208.178]) by smtp.gmail.com with ESMTPSA id s8sm3151437lfc.83.2020.05.30.10.57.40 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 30 May 2020 10:57:40 -0700 (PDT) Received: by mail-lj1-f178.google.com with SMTP id u10so1914836ljj.9 for ; Sat, 30 May 2020 10:57:40 -0700 (PDT) X-Received: by 2002:a2e:8897:: with SMTP id k23mr2590713lji.285.1590861460328; Sat, 30 May 2020 10:57:40 -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> <20200530143147.GN23230@ZenIV.linux.org.uk> <81563af6-6ea2-3e21-fe53-9955910e303a@redhat.com> In-Reply-To: <81563af6-6ea2-3e21-fe53-9955910e303a@redhat.com> From: Linus Torvalds Date: Sat, 30 May 2020 10:57:24 -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: Paolo Bonzini Cc: Al Viro , 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 Sat, May 30, 2020 at 9:20 AM Paolo Bonzini wrote: > > Yes, the access_ok is done in __kvm_set_memory_region and gfn_to_hva() > returns a page-aligned address so it's obviously ok for a u32. It's not that it's "obviously ok for an u32". It is _not_ obviously ok for a user address. There's actually no access_ok() done in the lookup path at all, and what gfn_to_hva() actually ends up doing in the end is __gfn_to_hva_memslot(), which has zero overflow protection at all, and just does slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE; without us having _ever_ checked that 'gfn' parameter. Yes, at some point in the very very distant past, __kvm_set_memory_region() has validated mem->{userspace_addr,memory_size}. But even that validation is actually very questionable, since it's not even done for all of the memory slots, only the "user" ones. So if at any point we have a non-user slot, of it at any point the gfn thing was mis-calculated and {over,under}flows, there are no protections what-so-ever. In other words, it really looks like kvm is entirely dependent on magic and luck and a desperate hope that there are no other bugs to keep the end result as a user address. Because if _any_ bug or oversight in that kvm_memory_slot handling ever happens, you end up with random crap. 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. 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. Linus