From nobody Mon Jun 8 04:15:27 2026 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5296228CF4A for ; Sun, 7 Jun 2026 12:48:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780836536; cv=none; b=QCwmcz/yH3I8wTzgLiLLpKvTYt1ETnkOC432a1YIH00p3Md3bCqN25zjHW9Uivbp/la+zFsUTj7FcF4si1He+Ui2O6DMWsS52+jM0zdkSW+SJDpRWxxFu42Td/u4d3ybyLlt57TdOt836qDJr9m4NKzxooDats9AD/5eCmFq04s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780836536; c=relaxed/simple; bh=BV6AJGuw/xsMgOxl9SY8FG8RrXLJqtI4CTPX962LxYk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=g7GzGu27gWSFofC5sERHT812ZxK3h2pE3Rg8T3us6Rmatq2C7Cj0Uz8wntfqAST+2SWcu3t+H5QG5oO/Jv+mmqMH0nagNRrQ9BNPpHr2RszPmYapN93UnaT0XHyP0Pkc5E3tmE9tVv6812Cx5TfVkoqc0eR5pIuRfZy+ZP1TCYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=H+Rm8057; arc=none smtp.client-ip=209.85.222.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H+Rm8057" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-91588056619so230499685a.2 for ; Sun, 07 Jun 2026 05:48:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780836534; x=1781441334; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=R/ItvRwkdkhyOcV5EUqgABZkU2mcEZg+Gfh/gQJ+RwE=; b=H+Rm80577V2mT7liD/GW7V4S4nALbuDogXu1A3Z+7tEY8cz+zKzCRa/Rn6n7Vu8dHI 16o5y52rbkuwE+96g7ouii5oVrD9KgufeysqXGbtagbJZS3ASOWlbqfea4Rf/78iFrGN ViE+zJcNETsUcto/d956/e/SIfYt6lVLiayxD+qiJ8iz5iJXBBRgoWu2mePMV3XaU4S5 D9zZfNYDEA+TXmKezkK0cRhoiPtc57LZnQoJfBFs+XETot/d7V2I0SlkrwvuTbM36vCY vxOjOEwsqXlFqk5xhTFB5R0nWsvM1BAOLu4WqCo0YOcWjmeZLzPxTIVjsCiw5Sth5CnA FaFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780836534; x=1781441334; 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; bh=R/ItvRwkdkhyOcV5EUqgABZkU2mcEZg+Gfh/gQJ+RwE=; b=KE5dpp43VTtY0wUeWl0+QJTmyTpj303/ZOJrjqRN3by9tVRAZHTDt5OaWbug/lUfAF HshVififRrKA8YlJymARzPlA87vffwpsl4nW0bdmoIrLFa0Y4p5+HboX5LCRyFHlX6RO +AZ+MgJAUjADQA7HjN83Qep122yxBNrHxYNZadxJ98OFM40rFjm5m7k6bTFLN1CX7Jwd NL5V69oCIvhr5zNwRKBqUV2deasuH3bCnTluvgtZCimlPSM7UcxH6qeviEy5nw33rdzD TtZPqBs1Cr1CuRchSvrQO45mVAZOx7y11X79pZdLxHBVIbhtJo6Qb4WdKbd8PmR40W/X JmJA== X-Forwarded-Encrypted: i=1; AFNElJ8x8OtMhyyw7gRmRVYJW5t7NbxoTNp4opucmrpCJBtN1kU1YTIIgHE+7xVJuhcyidxE75WUJJ359mOXCrY=@vger.kernel.org X-Gm-Message-State: AOJu0YzbEbR8qH0kUj8mGsB36csQ6NXOy0ROJBjXdUW8ZGNTeljk1FNR AmjMrTSws+iJ2oGyoYYObLdRZez+gfRdT0OkMDJtDHMwh5s8Djv71KZC X-Gm-Gg: Acq92OHK9xCWcWxf1JGRsXNBwheAaUje0PxgX2DDCsIfzfs0fldx1ThKGFYsdU+IPwz zpiD45yn8vwIY2eWkFBJYkVlEG9NPeYQ18InP5/SA0FEKOBtyUU2Z/rtlaA5WTv0/4O7xEci2hm 1VIhfU6Th1eI57FHAjyDxjrBXOIHGstKxxBtFJ9gRZU1YIH+me/+3fNE79E9JBd7J8StlU8FjRP n5uLA/5Hxg43oAU2sM7344VYHMZhrB1ugB62TlY++cho/LbAyBbAL1XTjb+OfzEMkYwdyBZLjDs HipzYp2ODM2ul6X5mp4BfClSIsXNbseO8OHepAOeIThfvlDWRBv4S4wa9yL9W5pDq2R/LGpIAK6 pL4sVdHOaAEyHb4MUvO12wlsoJTnclMaPjgqN1kawEKMlrbODDUAeQDPOMuCOvgzy34m5hMYOZ7 BsowW+WxhJpjyb+UVdheL6Znf+0y2bl7Pg/GnxOFgzIafzqIkS4JQa1b0wjMY/ho2gDAm9NV619 BAsWaztx1y4Yn6sAhMeJu7NLIPtJ2E= X-Received: by 2002:a05:620a:1d01:b0:914:bb8e:915c with SMTP id af79cd13be357-915a9cac9afmr1892160485a.22.1780836534090; Sun, 07 Jun 2026 05:48:54 -0700 (PDT) Received: from server0 (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9158a37cae4sm1419467485a.29.2026.06.07.05.48.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jun 2026 05:48:53 -0700 (PDT) From: Michael Bommarito To: "Michael S . Tsirkin" , Jason Wang , Stefan Hajnoczi , Jens Axboe Cc: Xuan Zhuo , virtualization@lists.linux.dev, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] virtio-blk: clamp zone report to the report buffer capacity Date: Sun, 7 Jun 2026 08:48:34 -0400 Message-ID: <20260607124834.3059944-1-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" virtblk_report_zones() trusts the device-reported number of zones when walking the report buffer: nz =3D min_t(u64, virtio64_to_cpu(vblk->vdev, report->nr_zones), nr_zones); ... for (i =3D 0; i < nz && zone_idx < nr_zones; i++) { ret =3D virtblk_parse_zone(vblk, &report->zones[i], ...); The buffer is allocated by virtblk_alloc_report_buffer(), whose size is capped by the queue's max hardware sectors and max segments and can therefore hold fewer descriptors than nr_zones. nz is bounded only by the device-supplied report->nr_zones and the requested nr_zones, never by the buffer's descriptor capacity. At probe time the request count is unbounded (blk_revalidate_disk_zones() calls report_zones() with nr_zones =3D=3D UINT_MAX), so the device-supplied report->nr_zones is the sole gate: a device that reports more zones than fit in the buffer drives the loop to read report->zones[i] past the end of the allocation. A malicious or buggy virtio-blk device that reports an inflated nr_zones triggers this during zone revalidation at probe. KASAN reports a vmalloc-out-of-bounds read in virtblk_report_zones() against the report buffer allocated a few lines earlier. Clamp nz to the number of descriptors that actually fit in the report buffer. Fixes: 95bfec41bd3d ("virtio-blk: add support for zoned block devices") Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito --- v2: drop the explanatory comment per Michael S. Tsirkin's review; the clamp itself is unchanged. drivers/block/virtio_blk.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index b1c9a27..32bf3ba 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -689,6 +689,8 @@ static int virtblk_report_zones(struct gendisk *disk, s= ector_t sector, =20 nz =3D min_t(u64, virtio64_to_cpu(vblk->vdev, report->nr_zones), nr_zones); + nz =3D min_t(u64, nz, + (buflen - sizeof(*report)) / sizeof(report->zones[0])); if (!nz) break; =20 base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8 --=20 2.53.0