[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1551983533.5436.8.camel@redhat.com>
Date: Thu, 07 Mar 2019 20:32:13 +0200
From: Mohammed Gamal <mgamal@...hat.com>
To: Michael Kelley <mikelley@...rosoft.com>,
"linux-hyperv@...r.kernel.org" <linux-hyperv@...r.kernel.org>,
kimbrownkd <kimbrownkd@...il.com>
Cc: Sasha Levin <Alexander.Levin@...rosoft.com>,
Dexuan Cui <decui@...rosoft.com>,
Stephen Hemminger <sthemmin@...rosoft.com>,
Long Li <longli@...rosoft.com>,
KY Srinivasan <kys@...rosoft.com>,
Haiyang Zhang <haiyangz@...rosoft.com>,
vkuznets <vkuznets@...hat.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] hyper-v: Check for ring buffer in
hv_get_bytes_to_read/write
On Thu, 2019-03-07 at 17:33 +0000, Michael Kelley wrote:
> From: Mohammed Gamal <mgamal@...hat.com> Sent: Thursday, March 7,
> 2019 8:36 AM
> >
> > This patch adds a check for the presence of the ring buffer in
> > hv_get_bytes_to_read/write() to avoid possible NULL pointer
> > dereferences.
> > If the ring buffer is not yet allocated, return 0 bytes to be
> > read/written.
> >
> > The root cause is that code that accesses the ring buffer including
> > hv_get_bytes_to_read/write() could be vulnerable to the race
> > condition
> > discussed in https://lkml.org/lkml/2018/10/18/779>;
> >
> > This race is being addressed by the patch series by Kimberly Brown
> > in
> > https://lkml.org/lkml/2019/2/21/1236 which is not final yet
> >
> > Signed-off-by: Mohammed Gamal <mgamal@...hat.com>
>
> Could you elaborate on the code paths where
> hv_get_bytes_to_read/write() could be called when the ring buffer
> isn't yet allocated? My sense is that Kim Brown's patch will address
> all of the code paths that involved sysfs access from outside the
> driver. And within a driver, the ring buffer should never be
> accessed
> unless it is already allocated. Is there another code path we're not
> aware of? I'm wondering if these changes are really needed once
> Kim Brown's patch is finished.
>
> Michael
I've seen one instance of the race in the netvsc driver when running
traffic through it with iperf3 while continuously changing the channel
settings.
The following code path deallocates the ring buffer:
netvsc_set_channels() -> netvsc_detach() ->
rndis_filter_device_remove() -> netvsc_device_remove() -> vmbus_close()
-> vmbus_free_ring() -> hv_ringbuffer_cleanup().
netvsc_send_pkt() -> hv_get_bytes_to_write() might get called
concurrently after vmbus_close() and before vmbus_open() returns and
sets up the new ring buffer.
The race is fairly hard to reproduce on recent upstream kernels, but I
still managed to reproduce it.
Powered by blists - more mailing lists