lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 15 Jun 2023 03:55:43 +0000
From: Dexuan Cui <decui@...rosoft.com>
To: Lorenzo Pieralisi <lpieralisi@...nel.org>
CC: "bhelgaas@...gle.com" <bhelgaas@...gle.com>, "davem@...emloft.net"
	<davem@...emloft.net>, "edumazet@...gle.com" <edumazet@...gle.com>, Haiyang
 Zhang <haiyangz@...rosoft.com>, Jake Oshins <jakeo@...rosoft.com>,
	"kuba@...nel.org" <kuba@...nel.org>, "kw@...ux.com" <kw@...ux.com>, KY
 Srinivasan <kys@...rosoft.com>, "leon@...nel.org" <leon@...nel.org>,
	"linux-pci@...r.kernel.org" <linux-pci@...r.kernel.org>, "Michael Kelley
 (LINUX)" <mikelley@...rosoft.com>, "pabeni@...hat.com" <pabeni@...hat.com>,
	"robh@...nel.org" <robh@...nel.org>, "saeedm@...dia.com" <saeedm@...dia.com>,
	"wei.liu@...nel.org" <wei.liu@...nel.org>, Long Li <longli@...rosoft.com>,
	"boqun.feng@...il.com" <boqun.feng@...il.com>, Saurabh Singh Sengar
	<ssengar@...rosoft.com>, "helgaas@...nel.org" <helgaas@...nel.org>,
	"linux-hyperv@...r.kernel.org" <linux-hyperv@...r.kernel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"linux-rdma@...r.kernel.org" <linux-rdma@...r.kernel.org>,
	"netdev@...r.kernel.org" <netdev@...r.kernel.org>, Jose Teuttli Carranco
	<josete@...rosoft.com>, "stable@...r.kernel.org" <stable@...r.kernel.org>
Subject: RE: [PATCH v3 1/6] PCI: hv: Fix a race condition bug in
 hv_pci_query_relations()

> From: Lorenzo Pieralisi <lpieralisi@...nel.org>
> Sent: Thursday, May 25, 2023 1:14 AM
> To: Dexuan Cui <decui@...rosoft.com>
> 
> On Wed, Apr 19, 2023 at 07:40:32PM -0700, Dexuan Cui wrote:
> > Fix the longstanding race between hv_pci_query_relations() and
> > survey_child_resources() by flushing the workqueue before we exit from
> > hv_pci_query_relations().
> 
> "Fix the longstanding race" is vague. Please describe the race
> succinctly at least to give an idea of what the problem is.
Hi Lozenzo, I'm sorry for the late response -- finally I'm back on the patchset...

I'll use the below commit message in v4:
 
 Since day 1 of the driver, there has been a race between
 hv_pci_query_relations() and survey_child_resources(): during fast
 device hotplug, hv_pci_query_relations() may error out due to
 device-remove and the stack variable 'comp' is no longer valid;
 however, pci_devices_present_work() -> survey_child_resources() ->
 complete() may be running on another CPU and accessing the no-longer-valid
 'comp'. Fix the race by flushing the workqueue before we exit from
 hv_pci_query_relations().

I'll also update the comment to share more details of the race:

--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -3401,6 +3401,24 @@ static int hv_pci_query_relations(struct hv_device *hdev)
        if (!ret)
                ret = wait_for_response(hdev, &comp);

+       /*
+        * In the case of fast device addition/removal, it's possible that
+        * vmbus_sendpacket() or wait_for_response() returns -ENODEV but we
+        * already got a PCI_BUS_RELATIONS* message from the host and the
+        * channel callback already scheduled a work to hbus->wq, which can be
+        * running pci_devices_present_work() -> survey_child_resources() ->
+        * complete(&hbus->survey_event), even after hv_pci_query_relations()
+        * exits and the stack variable 'comp' is no longer valid; as a result,
+        * a hang or a page fault may happen when the complete() calls
+        * raw_spin_lock_irqsave(). Flush hbus->wq before we exit from
+        * hv_pci_query_relations() to avoid the issues. Note: if 'ret' is
+        * -ENODEV, there can't be any more work item scheduled to hbus->wq
+        * after the flush_workqueue(): see vmbus_onoffer_rescind() ->
+        * vmbus_reset_channel_cb(), vmbus_rescind_cleanup() ->
+        * channel->rescind = true.
+        */
+       flush_workqueue(hbus->wq);
+
        return ret;
 }

> > +	 * In the case of fast device addition/removal, it's possible that
> > +	 * vmbus_sendpacket() or wait_for_response() returns -ENODEV but we
> > +	 * already got a PCI_BUS_RELATIONS* message from the host and the
> > +	 * channel callback already scheduled a work to hbus->wq, which can
> >  be
> > +	 * running survey_child_resources() -> complete(&hbus->survey_event),
> > +	 * even after hv_pci_query_relations() exits and the stack variable
> > +	 * 'comp' is no longer valid. This can cause a strange hang issue
> 
> "A strange hang" sounds like we don't understand what's happening, it
> does not feel like it is a solid understanding of the issue.
> 
> I would remove it - given that you already explain that comp is no
> longer valid - that is already a bug that needs fixing.
I share more details in the comment (see the above).
 
> Acked-by: Lorenzo Pieralisi <lpieralisi@...nel.org>
Thanks!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ