From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A82B149553D for ; Tue, 9 Jun 2026 15:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781020505; cv=none; b=IPohfj9PJ4j7vCgxeCZws0v8YolJjKs/3o+xvATl23xiRZ4SJy6WsPuPjNRuS+nr5sOhGC5tS+1lkDjtVBMt9S/SpS+bK4velzo0xTEz189c8P7iE6TWbQ90dYB8IxIhhGISklBCJsaL3TyRa7qhTXeiySEnkZIhyAwtGd1sJds= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781020505; c=relaxed/simple; bh=vh4wTHSupJWsPBBHRt4byAg9tmu3n/JJ3JkBimEoRGE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=b8NlNr125WMuRIDSRkXSQ63/NHhIqfLhOOSerLkcxHFvDw+eczh3GpP++ZXowp0vAwB8DIuIsB8kO3sGzDxGDMdurVQO0uGROdjCxHB+nCbgChjPQjYJPDYBGXwfddlA8mkQVu72IptSfEJqJRulMaG3rj0zTbOuQMYMCkcuCeA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cqZ1+/TW; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=tCBrKI2U; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cqZ1+/TW"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="tCBrKI2U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781020502; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=sFekO1yhKAjnCNx4nQmykHHEMqovGJRsN7iwpZ8ZFPs=; b=cqZ1+/TWvCjTnb4dpoOo1sYbWZzJ3k6pNZSw6gQP5+JlAE/L4eH8zdN6hNWfPs92EqfGog TlQyn3UHX7IhV90+a+hWjDplVEuHZlVUhOk717oF8B54ZnDOcAKfzKkSUKKq0yzJUGxkIJ uCI4vrSv1gNDWg2E4iqxYqvwz8/Rf7s= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-492-n6imGuLNMqyNxOSv5HG6fA-1; Tue, 09 Jun 2026 11:55:01 -0400 X-MC-Unique: n6imGuLNMqyNxOSv5HG6fA-1 X-Mimecast-MFC-AGG-ID: n6imGuLNMqyNxOSv5HG6fA_1781020500 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4600c8cb13aso3465060f8f.1 for ; Tue, 09 Jun 2026 08:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1781020500; x=1781625300; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=sFekO1yhKAjnCNx4nQmykHHEMqovGJRsN7iwpZ8ZFPs=; b=tCBrKI2UNRqFwLVXeDZ7khxiDvArEYriYs8HnzuqRLVVt2rVZ42gCwRCzdv4DHdg9r 0xi9VfxVFYyLqxjs56LZyRDOvSmy7cNmKzizUWRMzlBTrc+zYDBJC4rNE2KIRVqpXnc8 1S6wFs2LUiav/cE7XO4cbrVOE9YeW8JTp/LyFu0Ld+OAURsqNrr0rapS2yJ+h7JFcpqT vooDCkTN6uFuPuFA4j2UGhHt0sunZSujVbvsQ6oQwycnD+LrW+XKLQTlBelggo//X1WP JJmIRuCEJszlxNzf6IFM3cy1UbKx8X+l2Qx0x+NYmMh+9tgjnKpBrfFvm6If7YTtjD1C lhxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781020500; x=1781625300; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sFekO1yhKAjnCNx4nQmykHHEMqovGJRsN7iwpZ8ZFPs=; b=jBH8bn5g0UVXScD+DVb0luxIiKGLlSkLJGW8bniv4FRezWk8Ung7BV0sJ+RIc446/Z DaVNjDSekvQAMsNgVn6m2mFqGSgBx3K0GbfJsGgk8uXPCEdK18XuFv2a/heM6KhJ7ymi RmejSmADvNK/oE7Kv3OPnOYvFJ48GYIJ3ZO9nkcDcqMJ4Hyg9KdzmUPdaYIRUARhrsTA eVpIL6m+dSJ+pIGt8njcwGp+7kbFbrt7k6OMUMfv3fnnPQVmUmuVuEInsyuOzLB3phrK FYoK+Oa/+tXG2Qe2Ue2lBdHOLle83W1S6xBoXwoAPCp1TgxLe3/ImWHQmVrrq++dPiTo ycMA== X-Forwarded-Encrypted: i=1; AFNElJ93uL2sAeRM8VeOkPKuNCr/JZLTQR3F7kKuqPKv5F06tn7Ok/LO5XKP/BnvRJWFqIW7A6h53xyfjwR45Ow=@vger.kernel.org X-Gm-Message-State: AOJu0YxV2egkUV8Gn3FDyBp0DNUe78NXFsi6HEZW51fzL53PXd0HTh4A fa6lKYLItYYot+T7OutUWJjEDag7uT7kLBlKejw3uhIDs2/4uowxBE73NMQxBo0+NyUljO1SVS1 UF4Y74kRnif8QW0UY86LY5H+PGnZHsBZ+jrn0CHjaI//OUuP7v0NRfe7Ez/Y+iJdVIA== X-Gm-Gg: Acq92OHn8yfaOhHH7eHq3sTTc9YAOnabcIAWnQVekIz8fo15mdQbzkyNLotbI309Ul0 l4fxEghupMT37l4M1zVHP+7Drr2dj11ZLCAhwMpylMoHwv7YuDEozG27r4AN69JdW10oEsFe10m akYYRX2SMTd14zp7+aiPTvqzme+VXvq1osdyBHBTL5zjIUvQhy4zCPq40/zoctnwiq/H15r/eVT cTmVyI7H/kXGO333t4FDDSOlGL2274MLNcewOAUSx2+MZI0NkjCgPY/mPTmnnslJet7G2+BOX/Y qfuzTzr2XCwc9MoDNsNo+3lpgol5DDITZgMTD8LZ6yA4RxiZCwWWE5bzTD7cvFmRUViuv8qvPLC mt6Ki2dO+PlRofEJ4JS5hcpQY7A6VomiyxqBqk331Vm/ND0EY1SFPGw== X-Received: by 2002:a05:600c:c4a7:b0:490:b58a:dcc1 with SMTP id 5b1f17b1804b1-490c262183cmr324676835e9.29.1781020499575; Tue, 09 Jun 2026 08:54:59 -0700 (PDT) X-Received: by 2002:a05:600c:c4a7:b0:490:b58a:dcc1 with SMTP id 5b1f17b1804b1-490c262183cmr324676385e9.29.1781020499094; Tue, 09 Jun 2026 08:54:59 -0700 (PDT) Received: from redhat.com (IGLD-80-230-85-71.inter.net.il. [80.230.85.71]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3c183asm496291625e9.6.2026.06.09.08.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2026 08:54:58 -0700 (PDT) Date: Tue, 9 Jun 2026 11:54:55 -0400 From: "Michael S. Tsirkin" To: Michael Bommarito Cc: Jason Wang , Stefan Hajnoczi , Jens Axboe , Xuan Zhuo , virtualization@lists.linux.dev, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] virtio-blk: clamp zone report to the report buffer capacity Message-ID: <20260609115437-mutt-send-email-mst@kernel.org> References: <20260607124834.3059944-1-michael.bommarito@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260607124834.3059944-1-michael.bommarito@gmail.com> On Sun, Jun 07, 2026 at 08:48:34AM -0400, Michael Bommarito wrote: > virtblk_report_zones() trusts the device-reported number of zones when > walking the report buffer: > > nz = min_t(u64, virtio64_to_cpu(vblk->vdev, report->nr_zones), > nr_zones); > ... > for (i = 0; i < nz && zone_idx < nr_zones; i++) { > ret = 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 == 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 Acked-by: Michael S. Tsirkin > --- > 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, sector_t sector, > > nz = min_t(u64, virtio64_to_cpu(vblk->vdev, report->nr_zones), > nr_zones); > + nz = min_t(u64, nz, > + (buflen - sizeof(*report)) / sizeof(report->zones[0])); > if (!nz) > break; > > > base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8 > -- > 2.53.0