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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 DD675C07E95 for ; Tue, 13 Jul 2021 10:37:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 22ED360698 for ; Tue, 13 Jul 2021 10:37:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22ED360698 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=irrelevant.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3FnZ-000135-VG for qemu-devel@archiver.kernel.org; Tue, 13 Jul 2021 06:37:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Fk2-0008HA-H5; Tue, 13 Jul 2021 06:34:18 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:34779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Fk0-0004Dn-EE; Tue, 13 Jul 2021 06:34:18 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id D2A663200933; Tue, 13 Jul 2021 06:34:13 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 13 Jul 2021 06:34:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=s90usuO+THzHso5UX988akMJ+6g G66L/yTH/3iCjOus=; b=bR6F0lGjeqhjcwpJ5kkkA3iN02Yc0UKL+Ps0qGdgCsQ lSBYr9bVo72j8MBkXss5LRc+JTgo7MyU+FKC86W8sSlN28w7G0clyi76M7R9CAkS EkttjuS+fli+MzxnGXYBSxwFkKo9vGAFw1frJoAqFlEtSrPCCSZnuXN3Qa++Talc 2HeRRrMuwynna3UDUqvn1mI1bqU3G0it8q7jVJnpCkZNbpsSH6mkK2iFmi+zgt1f Tm1npOfPZa2FCPvlfl0q877+W4Hb4uxD4J30KdVWBiq4ABerIQsF2ZQrloAHgwoM cZMkyAmOLe02O9HNiEuh0Pxc5g9YV4fhujwVtp+CsbA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=s90usu O+THzHso5UX988akMJ+6gG66L/yTH/3iCjOus=; b=tZi4g/Crkc6oD1LyKNLztW kLbuB7U+rgW4yvuUffsGyDeeoxrIN+bZQ45qA/ReSv2OU3w+oSiF5oSN5suBkY6/ KHErKn3Yc+cSdVz47E7VXEVApQhiI/h3A5CBp0qSNF4C8GZxzlUPklraawRPEAfV 2mMXQmvfzgnJuCG9D8avO9dtNsJc6orVTjS0+C9KoLjQL2s5OuOI5ExdXm7bMNS7 iFqrUOjScsCql8Lja7Ftl6jD4ZLGSvSNaR2O7Jtr+fTWmc/3cI4/j3hK+AIMIQi4 +xchuVzS2jUItCes8P5v7K/suNe1Tbog84K7/7j8WWNCyYpI/83rMjOBAEMKvu1w == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudehgddvudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtjeenucfhrhhomhepmfhlrghushcu lfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrthhtvg hrnhepjeegudffueeiteekieelkedvueelteevjeduieeludfffeejgeffhfduvdduffek necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhtsh esihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Jul 2021 06:34:10 -0400 (EDT) Date: Tue, 13 Jul 2021 12:34:08 +0200 From: Klaus Jensen To: Peter Maydell Subject: Re: [PATCH] hw/nvme: fix mmio read Message-ID: References: <20210713054359.831878-1-its@irrelevant.dk> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="gDYpwGcWLNUrbG5a" Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=64.147.123.19; envelope-from=its@irrelevant.dk; helo=wout3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Keith Busch , Klaus Jensen , Gollu Appalanaidu , QEMU Developers , Qemu-block Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --gDYpwGcWLNUrbG5a Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Jul 13 11:31, Peter Maydell wrote: > On Tue, 13 Jul 2021 at 11:19, Klaus Jensen wrote: > > > > On Jul 13 11:07, Peter Maydell wrote: > > > Looking at the surrounding code, I notice that we guard this "read si= ze bytes > > > from &n->bar + addr" with > > > if (addr < sizeof(n->bar)) { > > > > > > but that doesn't account for 'size', so if the guest asks to read > > > 4 bytes starting at offset sizeof(n->bar)-1 then we'll still read > > > 3 bytes beyond the end of the buffer... > > > > The buffer is at least sizeof(n->bar) + 8 bytes (there are two doorbell > > registers following the controller registers). It is wrong for the host > > to read those, but as per the spec it is undefined behavior. >=20 > I don't know about the doorbell registers, but with this code > (or the old memcpy()) you'll access whatever the next thing after > "NvmeBar bar" in the NvmeCtrl struct is, which looks like it's the > first part of 'struct NvmeParams". >=20 Sorry, you are of course right. I remembered how the bar was allocated incorrectly. --gDYpwGcWLNUrbG5a Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEUigzqnXi3OaiR2bATeGvMW1PDekFAmDtbB4ACgkQTeGvMW1P DemB6wgAsDt8mQTkA8121RbkEubPaMz+cepngL9Git6axQ3hxfI+gmTy1lhvEk0i /xxNH/85oPDVsFOUrIcXnRYNLaE9pqrvl8pKrK4iiDCInAr8FZtMnptkW3WCkcb9 xQxJmQt6Q/X018v5RHGZXWED0afYQQs5oeLkEmss6kyC8rGpK/P6cHiFOg7FtawD chviE3r8DCG5QWPSv2RHedgIwGTrfqNlYnOHAtCYTqA1wPMQQrH3P2UrRRpdu7x4 LyB/niQp1HAB8xYnaIjFkifuDfOvQjI8vyz2xVX+yNo0K9OGMWPdxbxpqZWXlMEL vUpQMG8qj/FB32UWM5V4qgrL+nvlDQ== =hpA4 -----END PGP SIGNATURE----- --gDYpwGcWLNUrbG5a--