From nobody Fri May 17 10:44:20 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1712239150; cv=none; d=zohomail.com; s=zohoarc; b=mSWiq3+jovYpvNgbQyIevNgF7JI+NEWGmNiJ2zKxhjW+19yXJhcKsNPcIwuo8a+GNRcekHZWmBtUrnJiMs1TjRlGQ17q3CV6Yr4LM8qxAY497tgSlDBSv8pZFRan7ZGrR6eQooHHGyfOjFiw/NA+j+iCFDvyFVYOVlhDL6hCB1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1712239150; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=U78P+c+Y09VAuZb+FNDJxWeD52AjyEYHQTDsJZ90EII=; b=DyBd6LPApQU8SoXU11/Sw5iOigIQX9zpM+IfCc5r85FC2OMT5fYgLW/s2ezsvqdNJ01J+i1Qlw2IRsRiz/SeEiYbPnuZBHiEF0KC1SBGsLtKkHxfl9Pnyk1y/WKSXCI39jrGs0yktc+77Dqd+ixjSH+mit53aS0B09gaRGb1kz0= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1712239150242196.50330824066634; Thu, 4 Apr 2024 06:59:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rsNc5-0002bY-PE; Thu, 04 Apr 2024 09:58:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rsNc3-0002aI-L2 for qemu-devel@nongnu.org; Thu, 04 Apr 2024 09:58:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rsNc2-0006B6-5Q for qemu-devel@nongnu.org; Thu, 04 Apr 2024 09:58:43 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-ROUZs59QOiO1U9oOeA_cvA-1; Thu, 04 Apr 2024 09:58:37 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF0E885A5B6; Thu, 4 Apr 2024 13:58:36 +0000 (UTC) Received: from localhost (unknown [10.39.195.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA70D492BCA; Thu, 4 Apr 2024 13:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712239121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U78P+c+Y09VAuZb+FNDJxWeD52AjyEYHQTDsJZ90EII=; b=YZ4GWoZHAHQiUnFUEF97sYKmbfRTuDUWAS0QsyCHh87l8Xbn40Gl0O+suAuI9EWSHEyUkM 3LodSO5uUCvImn8WmRETxA6ZWKQQUKC6GAkTHlWpeR0ObP3O9v4cT6UU4PtP+jKPWjFgsd 0cTca6agpOOtjxHP7C0WDtn4vQ77gvw= X-MC-Unique: ROUZs59QOiO1U9oOeA_cvA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Peter Maydell , qemu-block@nongnu.org, Stefan Hajnoczi , Hanna Reitz , Kevin Wolf , Zheyu Ma Subject: [PULL for-9.0 1/1] block/virtio-blk: Fix memory leak from virtio_blk_zone_report Date: Thu, 4 Apr 2024 09:58:23 -0400 Message-ID: <20240404135823.2654261-2-stefanha@redhat.com> In-Reply-To: <20240404135823.2654261-1-stefanha@redhat.com> References: <20240404135823.2654261-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 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 @redhat.com) X-ZM-MESSAGEID: 1712239151916100001 Content-Type: text/plain; charset="utf-8" From: Zheyu Ma This modification ensures that in scenarios where the buffer size is insufficient for a zone report, the function will now properly set an error status and proceed to a cleanup label, instead of merely returning. The following ASAN log reveals it: =3D=3D1767400=3D=3DERROR: LeakSanitizer: detected memory leaks Direct leak of 312 byte(s) in 1 object(s) allocated from: #0 0x64ac7b3280cd in malloc llvm/compiler-rt/lib/asan/asan_malloc_linux= .cpp:129:3 #1 0x735b02fb9738 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0= x5e738) #2 0x64ac7d23be96 in virtqueue_split_pop hw/virtio/virtio.c:1612:12 #3 0x64ac7d23728a in virtqueue_pop hw/virtio/virtio.c:1783:16 #4 0x64ac7cfcaacd in virtio_blk_get_request hw/block/virtio-blk.c:228:27 #5 0x64ac7cfca7c7 in virtio_blk_handle_vq hw/block/virtio-blk.c:1123:23 #6 0x64ac7cfecb95 in virtio_blk_handle_output hw/block/virtio-blk.c:115= 7:5 Signed-off-by: Zheyu Ma Message-id: 20240404120040.1951466-1-zheyuma97@gmail.com Signed-off-by: Stefan Hajnoczi --- 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 92de315f17..bb86e65f65 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -768,7 +768,8 @@ static void virtio_blk_handle_zone_report(VirtIOBlockRe= q *req, sizeof(struct virtio_blk_zone_report) + sizeof(struct virtio_blk_zone_descriptor)) { virtio_error(vdev, "in buffer too small for zone report"); - return; + err_status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; + goto out; } =20 /* start byte offset of the zone report */ --=20 2.44.0