Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3818936ybi; Mon, 29 Jul 2019 13:14:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzeUBEXwfWpzt4AtCwRoeuYlrrKZ/uGTYrkWSma2k+rY14PWkHZ+Kp5coHICKbO219DZ8BP X-Received: by 2002:a62:fb18:: with SMTP id x24mr37424464pfm.231.1564431255140; Mon, 29 Jul 2019 13:14:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564431255; cv=none; d=google.com; s=arc-20160816; b=TpnXv/Hvi7Dn53onolz3Zv4ASwrNPhxlDa+gvLO8nxUJ3lCGHb5RCypSMxspw15cWw jcdrhFz1QiNZDdwfo8IFMQWEKKni83dUV3ZVP3BisSdcILRMXUlknBzDJCPP3t7c6oip s9OrUkPvQl0BtyGDnmn/8tZGGcZrPI7xTPJYBD/n7mPrZMaK3E2aZ8j/P3BO//FTEgJR iQspGrfli6TmW9bboAeKc4BTgHilOfwBjZE/SIcQq9rUmMBT8zd/Jq9ZfiaWXeuKNxdG QSSkGZYqWpqT7Xpoo6jqeiu3Pj+b1GIVPwkBg2QGeXV+IWApZK7B9L6kfqaZCFp5Wrd9 8p2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=I3PF5ju90VBJHvP0hymbH4HnwTwd5c+Vh7szsxwkZL0=; b=era9+IShBnwr0mYaW6KOqulVciAWUnwTPv6j1OysuautmnRPsJaI1AM4xd24UxBM1f 5rWUFZUXIHM647v8cmKMTWb3i9+zE7kCD5TasBvdRQ09+KhoDGMfBOA6pqBpBrubZEci Q3IbUpJMmOD11IZQADla8PBGV7nuSx5cBbDfYyDNtufIsJh+KcvY9530bJIdjIQp03q8 namSOXdDO4PS7oFJVdTykkuSsam9KCooJlm5ptFFULM4Mxk7AD1lsBkI+Grze/g8ug70 UrDTH/uzphIaov9vntxxonduFKHTqRNQEsd39JEgwYCwm8oertbCshUvzVi82KziWrg1 g95Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VD4bb8yT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f72si29092379pfa.67.2019.07.29.13.14.00; Mon, 29 Jul 2019 13:14:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VD4bb8yT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730244AbfG2UMU (ORCPT + 99 others); Mon, 29 Jul 2019 16:12:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:45164 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729353AbfG2TcB (ORCPT ); Mon, 29 Jul 2019 15:32:01 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7FD2D217F4; Mon, 29 Jul 2019 19:32:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428721; bh=d8Rhx9wi7iBHJQRfIlU9sxJP5KGSpoaz0j5bTOi3UgA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VD4bb8yTmDGiQx05IiWgLkNsQ7ym6a3nDukB5jYDshpPvkd+lWXXbJ1u68AtfL9c7 lyjq0UZdewVOhaOBpqd6VWz2mFqBhat4TQed1SSUey8+bWC5OZ1e9q+7BB+0bhOwQc stoRZd0Ykbc8BWH9vSLkgkRylxwTkh7XqHmpWxJY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dexuan Cui , Lorenzo Pieralisi , Michael Kelley Subject: [PATCH 4.14 165/293] PCI: hv: Fix a use-after-free bug in hv_eject_device_work() Date: Mon, 29 Jul 2019 21:20:56 +0200 Message-Id: <20190729190837.187517038@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dexuan Cui commit 4df591b20b80cb77920953812d894db259d85bd7 upstream. Fix a use-after-free in hv_eject_device_work(). Fixes: 05f151a73ec2 ("PCI: hv: Fix a memory leak in hv_eject_device_work()") Signed-off-by: Dexuan Cui Signed-off-by: Lorenzo Pieralisi Reviewed-by: Michael Kelley Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/pci/host/pci-hyperv.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -1912,6 +1912,7 @@ static void hv_pci_devices_present(struc static void hv_eject_device_work(struct work_struct *work) { struct pci_eject_response *ejct_pkt; + struct hv_pcibus_device *hbus; struct hv_pci_dev *hpdev; struct pci_dev *pdev; unsigned long flags; @@ -1922,6 +1923,7 @@ static void hv_eject_device_work(struct } ctxt; hpdev = container_of(work, struct hv_pci_dev, wrk); + hbus = hpdev->hbus; if (hpdev->state != hv_pcichild_ejecting) { put_pcichild(hpdev, hv_pcidev_ref_pnp); @@ -1935,8 +1937,7 @@ static void hv_eject_device_work(struct * because hbus->pci_bus may not exist yet. */ wslot = wslot_to_devfn(hpdev->desc.win_slot.slot); - pdev = pci_get_domain_bus_and_slot(hpdev->hbus->sysdata.domain, 0, - wslot); + pdev = pci_get_domain_bus_and_slot(hbus->sysdata.domain, 0, wslot); if (pdev) { pci_lock_rescan_remove(); pci_stop_and_remove_bus_device(pdev); @@ -1944,9 +1945,9 @@ static void hv_eject_device_work(struct pci_unlock_rescan_remove(); } - spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags); + spin_lock_irqsave(&hbus->device_list_lock, flags); list_del(&hpdev->list_entry); - spin_unlock_irqrestore(&hpdev->hbus->device_list_lock, flags); + spin_unlock_irqrestore(&hbus->device_list_lock, flags); if (hpdev->pci_slot) pci_destroy_slot(hpdev->pci_slot); @@ -1955,14 +1956,16 @@ static void hv_eject_device_work(struct ejct_pkt = (struct pci_eject_response *)&ctxt.pkt.message; ejct_pkt->message_type.type = PCI_EJECTION_COMPLETE; ejct_pkt->wslot.slot = hpdev->desc.win_slot.slot; - vmbus_sendpacket(hpdev->hbus->hdev->channel, ejct_pkt, + vmbus_sendpacket(hbus->hdev->channel, ejct_pkt, sizeof(*ejct_pkt), (unsigned long)&ctxt.pkt, VM_PKT_DATA_INBAND, 0); put_pcichild(hpdev, hv_pcidev_ref_childlist); put_pcichild(hpdev, hv_pcidev_ref_initial); put_pcichild(hpdev, hv_pcidev_ref_pnp); - put_hvpcibus(hpdev->hbus); + + /* hpdev has been freed. Do not use it any more. */ + put_hvpcibus(hbus); } /**