From nobody Sun Nov 16 01:09:51 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1598529776; cv=none; d=zohomail.com; s=zohoarc; b=Ry4arO3zwouEJPLimfuOhGNdrXsHUslL/pw3H3mA7bjL7fqhlyO7oODcHzEMzjUTAdCQ6z6RqAWqysmCRP+x1aVFkW9Bv2FIGTWClkwt8+aoiRpzZSYk0T/A1629j0KzOye45DxxIS3arFEcWhmoXK969IbIWm2DBAv2pHs1yrE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598529776; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=zE5Z/PVgsTj3IeGXFdZQDTapzomPjiQH8ioVEUKuTf8=; b=jao0jIvwAUN5c7AZ7/xGWIAbEzFBQ02onaDtVi/pQk85+HF2Qq9PNsRHpyThuVAmxXMhbpV5xnifAlVeNQK1Zmf4wVKG0ViIl5arxphVUWYTIbRMlb4GAk+KNIsvzb2tv7uG3XZwmt7QXO1fZx487uJC+7Alf1HuorQ1D64YsHE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598529776790482.2253571125101; Thu, 27 Aug 2020 05:02:56 -0700 (PDT) Received: from localhost ([::1]:40530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kBGcJ-0002PS-Gj for importer@patchew.org; Thu, 27 Aug 2020 08:02:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kBGbD-0001qj-5j for qemu-devel@nongnu.org; Thu, 27 Aug 2020 08:01:47 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:38601 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kBGbB-0000vz-7P for qemu-devel@nongnu.org; Thu, 27 Aug 2020 08:01:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-419-H2Oic-H5NwuXdCzwIkt3kQ-1; Thu, 27 Aug 2020 08:01:39 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 929F21DE10; Thu, 27 Aug 2020 12:01:38 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-91.phx2.redhat.com [10.3.112.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ABC667B9F3; Thu, 27 Aug 2020 12:01:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598529704; 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: content-transfer-encoding:content-transfer-encoding; bh=zE5Z/PVgsTj3IeGXFdZQDTapzomPjiQH8ioVEUKuTf8=; b=CobZojqg4DWDWabXxHr5amEOsMu3KuxPZVHHmAoM+Ahcyt3Qzvg1d1Xw4lTBRurJIrUp31 uaO5yJeosrB0/P3yrXFTf0QKMAZNuumkGE33lO2WK9/iDHhE3qElzfrqcyPQYumAJGj23/ 0TU2C17vlchO5Q/1LieP4PQnGqRqve4= X-MC-Unique: H2Oic-H5NwuXdCzwIkt3kQ-1 From: P J P To: Gerd Hoffmann Subject: [PATCH] xhci: check return value from usb_packet_map Date: Thu, 27 Aug 2020 17:29:33 +0530 Message-Id: <20200827115933.1851563-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ppandit@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com 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=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=ppandit@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/27 02:56:52 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.959, 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_H2=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruhr-University , QEMU Developers , Prasad J Pandit Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit While setting up a packet in xhci_setup_packet() routine, usb_packet_map() may return an error. Check this return value before further processing the packet, to avoid use-after-free issue. -> https://ruhr-uni-bochum.sciebo.de/s/NNWP2GfwzYKeKwE?path=3D%2Fxhci_uaf_2 #0 __interceptor_free (/lib64/libasan.so.6+0xb0307) #1 qemu_vfree ../util/oslib-posix.c:247 #2 address_space_unmap ../exec.c:3635 #3 dma_memory_unmap ../include/sysemu/dma.h:145 #4 usb_packet_unmap ../hw/usb/libhw.c:65 #5 usb_packet_map ../hw/usb/libhw.c:54 #6 xhci_setup_packet ../hw/usb/hcd-xhci.c:1618 #7 xhci_fire_ctl_transfer ../hw/usb/hcd-xhci.c:1722 #8 xhci_kick_epctx ../hw/usb/hcd-xhci.c:1991 #9 xhci_kick_ep ../hw/usb/hcd-xhci.c:1861 #10 xhci_doorbell_write ../hw/usb/hcd-xhci.c:3162 ... Reported-by: Ruhr-University Signed-off-by: Prasad J Pandit --- hw/usb/hcd-xhci.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 67a18fe2b6..848e7e935f 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -1615,7 +1615,14 @@ static int xhci_setup_packet(XHCITransfer *xfer) xhci_xfer_create_sgl(xfer, dir =3D=3D USB_TOKEN_IN); /* Also sets int_= req */ usb_packet_setup(&xfer->packet, dir, ep, xfer->streamid, xfer->trbs[0].addr, false, xfer->int_req); - usb_packet_map(&xfer->packet, &xfer->sgl); + if (usb_packet_map(&xfer->packet, &xfer->sgl) < 0) { + DPRINTF("xhci: setup packet failed: pid: 0x%x addr %d ep %d\n", + xfer->packet.pid, ep->dev->addr, ep->nr); + usb_packet_cleanup(&xfer->packet); + qemu_sglist_destroy(&xfer->sgl); + return -1; + } + DPRINTF("xhci: setup packet pid 0x%x addr %d ep %d\n", xfer->packet.pid, ep->dev->addr, ep->nr); return 0; --=20 2.26.2