From nobody Wed Nov 5 11:01:10 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534256069378945.4627417191588; Tue, 14 Aug 2018 07:14:29 -0700 (PDT) Received: from localhost ([::1]:44538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpa5R-00072k-09 for importer@patchew.org; Tue, 14 Aug 2018 10:14:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42402) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpa4X-0006iT-6u for qemu-devel@nongnu.org; Tue, 14 Aug 2018 10:13:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fpa4N-0000ey-NX for qemu-devel@nongnu.org; Tue, 14 Aug 2018 10:13:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41392 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fpa4H-0000cd-EY; Tue, 14 Aug 2018 10:13:05 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6CF7681663C7; Tue, 14 Aug 2018 14:13:04 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A63E1018CA1; Tue, 14 Aug 2018 14:13:00 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 14 Aug 2018 16:12:46 +0200 Message-Id: <20180814141247.32336-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 14 Aug 2018 14:13:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 14 Aug 2018 14:13:04 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2] megasas: fix sglist leak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Hannes Reinecke , Fam Zheng , "open list:megasas" , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" tests/cdrom-test -p /x86_64/cdrom/boot/megasas Produces the following ASAN leak. =3D=3D25700=3D=3DERROR: LeakSanitizer: detected memory leaks Direct leak of 16 byte(s) in 1 object(s) allocated from: #0 0x7f06f8faac48 in malloc (/lib64/libasan.so.5+0xeec48) #1 0x7f06f87a73c5 in g_malloc (/lib64/libglib-2.0.so.0+0x523c5) #2 0x55a729f17738 in pci_dma_sglist_init /home/elmarco/src/qq/include/h= w/pci/pci.h:818 #3 0x55a729f2a706 in megasas_map_dcmd /home/elmarco/src/qq/hw/scsi/mega= sas.c:698 #4 0x55a729f39421 in megasas_handle_dcmd /home/elmarco/src/qq/hw/scsi/m= egasas.c:1574 #5 0x55a729f3f70d in megasas_handle_frame /home/elmarco/src/qq/hw/scsi/= megasas.c:1955 #6 0x55a729f40939 in megasas_mmio_write /home/elmarco/src/qq/hw/scsi/me= gasas.c:2119 #7 0x55a729f41102 in megasas_port_write /home/elmarco/src/qq/hw/scsi/me= gasas.c:2170 #8 0x55a729220e60 in memory_region_write_accessor /home/elmarco/src/qq/= memory.c:527 #9 0x55a7292212b3 in access_with_adjusted_size /home/elmarco/src/qq/mem= ory.c:594 #10 0x55a72922cf70 in memory_region_dispatch_write /home/elmarco/src/qq= /memory.c:1473 #11 0x55a7290f5907 in flatview_write_continue /home/elmarco/src/qq/exec= .c:3255 #12 0x55a7290f5ceb in flatview_write /home/elmarco/src/qq/exec.c:3294 #13 0x55a7290f6457 in address_space_write /home/elmarco/src/qq/exec.c:3= 384 #14 0x55a7290f64a8 in address_space_rw /home/elmarco/src/qq/exec.c:3395 #15 0x55a72929ecb0 in kvm_handle_io /home/elmarco/src/qq/accel/kvm/kvm-= all.c:1729 #16 0x55a7292a0db5 in kvm_cpu_exec /home/elmarco/src/qq/accel/kvm/kvm-a= ll.c:1969 #17 0x55a7291c4212 in qemu_kvm_cpu_thread_fn /home/elmarco/src/qq/cpus.= c:1215 #18 0x55a72a966a6c in qemu_thread_start /home/elmarco/src/qq/util/qemu-= thread-posix.c:504 #19 0x7f06ed486593 in start_thread (/lib64/libpthread.so.0+0x7593) Move the qemu_sglist_destroy() from megasas_complete_command() to megasas_unmap_frame(), so map/unmap are balanced. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/scsi/megasas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index ba1afa3c1e..7bee734718 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -465,6 +465,7 @@ static void megasas_unmap_frame(MegasasState *s, Megasa= sCmd *cmd) cmd->pa =3D 0; cmd->pa_size =3D 0; clear_bit(cmd->index, s->frame_map); + qemu_sglist_destroy(&cmd->qsg); } =20 /* @@ -580,7 +581,6 @@ static void megasas_complete_frame(MegasasState *s, uin= t64_t context) =20 static void megasas_complete_command(MegasasCmd *cmd) { - qemu_sglist_destroy(&cmd->qsg); cmd->iov_size =3D 0; cmd->iov_offset =3D 0; =20 --=20 2.18.0.547.g1d89318c48