From nobody Sun Dec 6 20:46:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1796298559; cv=none; d=zohomail.com; s=zohoarc; b=TceGaYPVK7xCjyR7wzpJ2inEmGBfv3VP9pVXhjQVBXeFHXK+CaOCdf7xUi6wYFO8JFZIi37XqrtboapJmSI195Gc+P17h47MzJQtHMoCEW2asHWqtAmRZzm/WouxbI2rFmPcIR8je5D44iVq+xeipB7hrQAfuiBEEsrZ1vV3F+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796298559; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lFmfj5jzFkkgz46PY5BbexpitaoyyvgVfghV1Y/RPRo=; b=Q2DAgwgs7MrUSAC6dPUJszzNavWLx0W13GFiZZMn6nW+mJQMLxAdV9Jc+u2iUdxgmR1NB9myGkWbV2XLcMLU7qWfJp5Xwj8z3DVuGRC0SPFoXdeFqxKxCKakVwAMu7NqWlWnEELLa5lQ8K7oc29wMdgh3HrTSoTLd4gGSqArEwg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179629855905431.028652269176746; Thu, 3 Dec 2026 03:49:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZ5Ix-0007Ou-F4; Thu, 03 Dec 2026 06:48:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZ5Iw-0007O8-Bj for qemu-devel@nongnu.org; Thu, 03 Dec 2026 06:48:50 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xZ5Iu-00015o-DP for qemu-devel@nongnu.org; Thu, 03 Dec 2026 06:48:50 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4bb64ef5a14so130425805e9.1 for ; Thu, 03 Dec 2026 03:48:47 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb9065744esm692576295e9.1.2026.12.03.03.48.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 03:48:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1796298527; x=1796903327; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=lFmfj5jzFkkgz46PY5BbexpitaoyyvgVfghV1Y/RPRo=; b=UVaXh2ho0b5CvfveUiSN/77aiHb53BNfbaA/g+lZI3kq3r8KHIG/zEYCZO2QOIgCpP /wUW9VCK/+PjnPhQkCecA8EHq8WBQ23LvukpR/qyFHKdRVQcbyjDFTX+0e3pffcPhIbv uotK9SzzXIXAH9z+xWCEE9EjJGfbi6r1WXlFo4xNflgjlUjDK0/A2O5bNOki/eQoU97q FBlNyJ+27Q/15xEBYKU7+lNcSFs3eyyh29VnJn4hN963eQHHa4+7GuzinzWm7oYEgmwz dzc3eVakpgKzQrVGvzwbiS6g/OzcHlagN8vWVP+fbBV5Mk2Yoe/b/IjfOBkWIkSjoz6o MZZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796298527; x=1796903327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lFmfj5jzFkkgz46PY5BbexpitaoyyvgVfghV1Y/RPRo=; b=hJ4lolSvFss1R59bjk6ov10HaS7ESMOCKRSFTGFZcnXEf08cHC3EZjAYj8Wh20h/jf k2/oF+4M0n43dBilpoad5548XkK2OtcRNgNByikEH9Rru+ZLgnTFkWSc5gr5/yEdHTWj Qjsft6ICCp0VOR6OKrDjzeU/6UXP+vhAWqB3JHDMBVznZpNQmm+En6qVT3Rb21kEADFZ nA2Y8PsAH6Z1x6Mw+L+zRN1Toq876/NTG9SilldMgP2coh1WpDSRBpyZg0XAm/wMnC8p Nv6l4seN5VmXOFaCY6dLWuCBKRHFse8pUdEk31ALYyDrfL3u27jRKnNGho05dpB2FQDx lNhg== X-Gm-Message-State: APuU4Z+7Rg+tBs+38F3dEapLEZKZ9fweiOGEA9xDf3gNehHXa2586t44 9lYnsPXF70UTCmcMKm86vfpMPQJd9XOj8TllQ+X5sHN2c9qKK7lQV7aE2TEHKaQTdRvQC61nhk1 FGaSv X-Gm-Gg: AZFdTZe1Rwew7sjTl2UhiAsw/W2qxqaDmnmuoKYU+SdFLlUs8u5RwLrEXFiwObZIPxg 2wWknozv2zKvENpfMtrDZ206ZFlq7JtG2mJvPNVNd87JHL+jn3YBA0LKdmXPBxpxXGqdbXOmL0/ NYj/AvOLbImE+sB2Fv9zeww4hJZjvdpfHEQaU+jY9RmashQEW+C3N6MkipD1BtlV+33hriO6Zny jipp56BXWyOGx5pAsNXlvLQ8Gy0mJt+TUErpiYGfy8ou71Y6xlhl3aZhWcexQ5CKcLzCMK+rkvx QJcYVHVwSPq1XTm0jiiasM5Dl3UfX5Cy5yw+RZh9gcWDdINg9X61xg7VHrj1XSII+2vGzA/Z/j2 SHCMBH85d+R3U5Fp+lTidZ5OuD08GpyS/a/441HT08VkEriL0ngb/t/NYVUma6/zAEyfiQR04AV oKkZa4FJjMuOgJxm2D3p5ZQwi/VLyIJT/osExFGq2AsjkPAAKfCDFbS2YoWAnuLCO7L9UyG3hwi aSYmHhqyf0A0A5LJkHAwbe8VQ5xPDNslRehu7F9p7taL7ZhXsFTZKyViLwZZuYBAqPNqEHt0jSP +UZa5wCdUpqoMcv6o1ekWgF7YqbfdVj2VTfGczCnOzVOGiYil40hztJzq1wRcPYU79eWKCnEivW 9x4GxI4V7EOhoAvCJWqCn4y/lZWkkfyulxg== X-Received: by 2002:a05:600c:4f15:b0:4bb:6861:657d with SMTP id 5b1f17b1804b1-4bb88923954mr1015021115e9.21.1796298526700; Thu, 03 Dec 2026 03:48:46 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Michael S. Tsirkin" , Stefan Hajnoczi , Kevin Wolf , Hanna Reitz Subject: [PATCH] hw/virtio/virtio-blk: Don't allow zoned requests off end of block device Date: Thu, 3 Dec 2026 11:48:45 +0000 Message-ID: <20261203114845.1499898-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1796298561695158500 Content-Type: text/plain; charset="utf-8" When checking a zoned request, we enforce that (offset + length) is not greater than the total block device size. This is the correct check for any request that starts inside the block device, but it accidentally allows through the corner case where the offset is equal to the block device size and the length is zero. This can then fall through into the bdrv_zone_index() call, which returns an index larger than the maximum valid index and so the bdrv_zone_is_conv() call reads off the end of the bs->wps->wp[] array. Check for offsets off the end of the block and fail those with a ZONE_INVALID_CMD error. Since the incorrect zone index is used only for a read, the failure mode seems likely to only be at worst a self-DoS due to a segfault, so this is a hardening patch. Cc: qemu-stable@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3864 Fixes: 4f7366506a9 ("virtio-blk: add zoned storage emulation for zoned devi= ces") Reported-by: Feifan Qian Signed-off-by: Peter Maydell --- hw/block/virtio-blk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index d9c3db3e56f..2255a76de96 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -569,7 +569,8 @@ static bool check_zoned_request(VirtIOBlock *s, int64_t= offset, int64_t len, } =20 if (offset < 0 || len < 0 || len > (bs->total_sectors << BDRV_SECTOR_B= ITS) - || offset > (bs->total_sectors << BDRV_SECTOR_BITS) - len) { + || offset > (bs->total_sectors << BDRV_SECTOR_BITS) - len + || offset >=3D (bs->total_sectors << BDRV_SECTOR_BITS)) { *status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; return false; } --=20 2.43.0