LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] drm: Fix possible race conditions while unplugging DRM device
@ 2018-05-22 14:13 Oleksandr Andrushchenko
2018-05-29 6:25 ` Oleksandr Andrushchenko
2018-05-29 7:02 ` Daniel Vetter
0 siblings, 2 replies; 6+ messages in thread
From: Oleksandr Andrushchenko @ 2018-05-22 14:13 UTC (permalink / raw)
To: linux-kernel, dri-devel, airlied, daniel.vetter, seanpaul, gustavo
Cc: andr2000, Oleksandr Andrushchenko, Noralf Trønnes
From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
When unplugging a hotpluggable DRM device we first unregister it
with drm_dev_unregister and then set drm_device.unplugged flag which
is used to mark device critical sections with drm_dev_enter()/
drm_dev_exit() preventing access to device resources that are not
available after the device is gone.
But drm_dev_unregister may lead to hotplug uevent(s) fired to
user-space on card and/or connector removal, thus making it possible
for user-space to try accessing a disconnected device.
Fix this by first making sure device is properly marked as
disconnected and only then unregister it.
Fixes: bee330f3d672 ("drm: Use srcu to protect drm_device.unplugged")
Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Reported-by: Andrii Chepurnyi <andrii_chepurnyi@epam.com>
Cc: "Noralf Trønnes" <noralf@tronnes.org>
---
drivers/gpu/drm/drm_drv.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index b553a6f2ff0e..7af748ed1c58 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -369,13 +369,6 @@ EXPORT_SYMBOL(drm_dev_exit);
*/
void drm_dev_unplug(struct drm_device *dev)
{
- drm_dev_unregister(dev);
-
- mutex_lock(&drm_global_mutex);
- if (dev->open_count == 0)
- drm_dev_put(dev);
- mutex_unlock(&drm_global_mutex);
-
/*
* After synchronizing any critical read section is guaranteed to see
* the new value of ->unplugged, and any critical section which might
@@ -384,6 +377,13 @@ void drm_dev_unplug(struct drm_device *dev)
*/
dev->unplugged = true;
synchronize_srcu(&drm_unplug_srcu);
+
+ drm_dev_unregister(dev);
+
+ mutex_lock(&drm_global_mutex);
+ if (dev->open_count == 0)
+ drm_dev_put(dev);
+ mutex_unlock(&drm_global_mutex);
}
EXPORT_SYMBOL(drm_dev_unplug);
--
2.17.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm: Fix possible race conditions while unplugging DRM device
2018-05-22 14:13 [PATCH] drm: Fix possible race conditions while unplugging DRM device Oleksandr Andrushchenko
@ 2018-05-29 6:25 ` Oleksandr Andrushchenko
2018-05-29 7:02 ` Daniel Vetter
1 sibling, 0 replies; 6+ messages in thread
From: Oleksandr Andrushchenko @ 2018-05-29 6:25 UTC (permalink / raw)
To: linux-kernel, dri-devel, airlied, daniel.vetter, seanpaul, gustavo
Cc: Oleksandr Andrushchenko, Noralf Trønnes
ping
On 05/22/2018 05:13 PM, Oleksandr Andrushchenko wrote:
> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>
> When unplugging a hotpluggable DRM device we first unregister it
> with drm_dev_unregister and then set drm_device.unplugged flag which
> is used to mark device critical sections with drm_dev_enter()/
> drm_dev_exit() preventing access to device resources that are not
> available after the device is gone.
> But drm_dev_unregister may lead to hotplug uevent(s) fired to
> user-space on card and/or connector removal, thus making it possible
> for user-space to try accessing a disconnected device.
>
> Fix this by first making sure device is properly marked as
> disconnected and only then unregister it.
>
> Fixes: bee330f3d672 ("drm: Use srcu to protect drm_device.unplugged")
>
> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> Reported-by: Andrii Chepurnyi <andrii_chepurnyi@epam.com>
> Cc: "Noralf Trønnes" <noralf@tronnes.org>
> ---
> drivers/gpu/drm/drm_drv.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index b553a6f2ff0e..7af748ed1c58 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -369,13 +369,6 @@ EXPORT_SYMBOL(drm_dev_exit);
> */
> void drm_dev_unplug(struct drm_device *dev)
> {
> - drm_dev_unregister(dev);
> -
> - mutex_lock(&drm_global_mutex);
> - if (dev->open_count == 0)
> - drm_dev_put(dev);
> - mutex_unlock(&drm_global_mutex);
> -
> /*
> * After synchronizing any critical read section is guaranteed to see
> * the new value of ->unplugged, and any critical section which might
> @@ -384,6 +377,13 @@ void drm_dev_unplug(struct drm_device *dev)
> */
> dev->unplugged = true;
> synchronize_srcu(&drm_unplug_srcu);
> +
> + drm_dev_unregister(dev);
> +
> + mutex_lock(&drm_global_mutex);
> + if (dev->open_count == 0)
> + drm_dev_put(dev);
> + mutex_unlock(&drm_global_mutex);
> }
> EXPORT_SYMBOL(drm_dev_unplug);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm: Fix possible race conditions while unplugging DRM device
2018-05-22 14:13 [PATCH] drm: Fix possible race conditions while unplugging DRM device Oleksandr Andrushchenko
2018-05-29 6:25 ` Oleksandr Andrushchenko
@ 2018-05-29 7:02 ` Daniel Vetter
2018-05-29 7:09 ` Oleksandr Andrushchenko
1 sibling, 1 reply; 6+ messages in thread
From: Daniel Vetter @ 2018-05-29 7:02 UTC (permalink / raw)
To: Oleksandr Andrushchenko
Cc: linux-kernel, dri-devel, airlied, daniel.vetter, seanpaul,
gustavo, Oleksandr Andrushchenko
On Tue, May 22, 2018 at 05:13:04PM +0300, Oleksandr Andrushchenko wrote:
> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>
> When unplugging a hotpluggable DRM device we first unregister it
> with drm_dev_unregister and then set drm_device.unplugged flag which
> is used to mark device critical sections with drm_dev_enter()/
> drm_dev_exit() preventing access to device resources that are not
> available after the device is gone.
> But drm_dev_unregister may lead to hotplug uevent(s) fired to
> user-space on card and/or connector removal, thus making it possible
> for user-space to try accessing a disconnected device.
>
> Fix this by first making sure device is properly marked as
> disconnected and only then unregister it.
>
> Fixes: bee330f3d672 ("drm: Use srcu to protect drm_device.unplugged")
>
> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> Reported-by: Andrii Chepurnyi <andrii_chepurnyi@epam.com>
> Cc: "Noralf Trønnes" <noralf@tronnes.org>
Nice catch.
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
I think you need to push this to drm-misc-next-fixes to make sure it's on
the 4.17 train.
-Daniel
> ---
> drivers/gpu/drm/drm_drv.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index b553a6f2ff0e..7af748ed1c58 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -369,13 +369,6 @@ EXPORT_SYMBOL(drm_dev_exit);
> */
> void drm_dev_unplug(struct drm_device *dev)
> {
> - drm_dev_unregister(dev);
> -
> - mutex_lock(&drm_global_mutex);
> - if (dev->open_count == 0)
> - drm_dev_put(dev);
> - mutex_unlock(&drm_global_mutex);
> -
> /*
> * After synchronizing any critical read section is guaranteed to see
> * the new value of ->unplugged, and any critical section which might
> @@ -384,6 +377,13 @@ void drm_dev_unplug(struct drm_device *dev)
> */
> dev->unplugged = true;
> synchronize_srcu(&drm_unplug_srcu);
> +
> + drm_dev_unregister(dev);
> +
> + mutex_lock(&drm_global_mutex);
> + if (dev->open_count == 0)
> + drm_dev_put(dev);
> + mutex_unlock(&drm_global_mutex);
> }
> EXPORT_SYMBOL(drm_dev_unplug);
>
> --
> 2.17.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm: Fix possible race conditions while unplugging DRM device
2018-05-29 7:02 ` Daniel Vetter
@ 2018-05-29 7:09 ` Oleksandr Andrushchenko
2018-05-29 7:49 ` Daniel Vetter
0 siblings, 1 reply; 6+ messages in thread
From: Oleksandr Andrushchenko @ 2018-05-29 7:09 UTC (permalink / raw)
To: Oleksandr_Andrushchenko, linux-kernel, dri-devel, airlied,
daniel.vetter, seanpaul, gustavo, Noralf Trønnes
On 05/29/2018 10:02 AM, Daniel Vetter wrote:
> On Tue, May 22, 2018 at 05:13:04PM +0300, Oleksandr Andrushchenko wrote:
>> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>>
>> When unplugging a hotpluggable DRM device we first unregister it
>> with drm_dev_unregister and then set drm_device.unplugged flag which
>> is used to mark device critical sections with drm_dev_enter()/
>> drm_dev_exit() preventing access to device resources that are not
>> available after the device is gone.
>> But drm_dev_unregister may lead to hotplug uevent(s) fired to
>> user-space on card and/or connector removal, thus making it possible
>> for user-space to try accessing a disconnected device.
>>
>> Fix this by first making sure device is properly marked as
>> disconnected and only then unregister it.
>>
>> Fixes: bee330f3d672 ("drm: Use srcu to protect drm_device.unplugged")
>>
>> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>> Reported-by: Andrii Chepurnyi <andrii_chepurnyi@epam.com>
>> Cc: "Noralf Trønnes" <noralf@tronnes.org>
> Nice catch.
>
> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
>
> I think you need to push this to drm-misc-next-fixes to make sure it's on
> the 4.17 train.
Sure, after I have r-b from Noralf
> -Daniel
>
>> ---
>> drivers/gpu/drm/drm_drv.c | 14 +++++++-------
>> 1 file changed, 7 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
>> index b553a6f2ff0e..7af748ed1c58 100644
>> --- a/drivers/gpu/drm/drm_drv.c
>> +++ b/drivers/gpu/drm/drm_drv.c
>> @@ -369,13 +369,6 @@ EXPORT_SYMBOL(drm_dev_exit);
>> */
>> void drm_dev_unplug(struct drm_device *dev)
>> {
>> - drm_dev_unregister(dev);
>> -
>> - mutex_lock(&drm_global_mutex);
>> - if (dev->open_count == 0)
>> - drm_dev_put(dev);
>> - mutex_unlock(&drm_global_mutex);
>> -
>> /*
>> * After synchronizing any critical read section is guaranteed to see
>> * the new value of ->unplugged, and any critical section which might
>> @@ -384,6 +377,13 @@ void drm_dev_unplug(struct drm_device *dev)
>> */
>> dev->unplugged = true;
>> synchronize_srcu(&drm_unplug_srcu);
>> +
>> + drm_dev_unregister(dev);
>> +
>> + mutex_lock(&drm_global_mutex);
>> + if (dev->open_count == 0)
>> + drm_dev_put(dev);
>> + mutex_unlock(&drm_global_mutex);
>> }
>> EXPORT_SYMBOL(drm_dev_unplug);
>>
>> --
>> 2.17.0
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm: Fix possible race conditions while unplugging DRM device
2018-05-29 7:09 ` Oleksandr Andrushchenko
@ 2018-05-29 7:49 ` Daniel Vetter
2018-05-31 7:48 ` Oleksandr Andrushchenko
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Vetter @ 2018-05-29 7:49 UTC (permalink / raw)
To: Oleksandr Andrushchenko
Cc: Oleksandr_Andrushchenko, linux-kernel, dri-devel, airlied,
daniel.vetter, seanpaul, gustavo, Noralf Trønnes
On Tue, May 29, 2018 at 10:09:57AM +0300, Oleksandr Andrushchenko wrote:
> On 05/29/2018 10:02 AM, Daniel Vetter wrote:
> > On Tue, May 22, 2018 at 05:13:04PM +0300, Oleksandr Andrushchenko wrote:
> > > From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> > >
> > > When unplugging a hotpluggable DRM device we first unregister it
> > > with drm_dev_unregister and then set drm_device.unplugged flag which
> > > is used to mark device critical sections with drm_dev_enter()/
> > > drm_dev_exit() preventing access to device resources that are not
> > > available after the device is gone.
> > > But drm_dev_unregister may lead to hotplug uevent(s) fired to
> > > user-space on card and/or connector removal, thus making it possible
> > > for user-space to try accessing a disconnected device.
> > >
> > > Fix this by first making sure device is properly marked as
> > > disconnected and only then unregister it.
> > >
> > > Fixes: bee330f3d672 ("drm: Use srcu to protect drm_device.unplugged")
> > >
> > > Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> > > Reported-by: Andrii Chepurnyi <andrii_chepurnyi@epam.com>
> > > Cc: "Noralf Trønnes" <noralf@tronnes.org>
> > Nice catch.
> >
> > Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> >
> > I think you need to push this to drm-misc-next-fixes to make sure it's on
> > the 4.17 train.
> Sure, after I have r-b from Noralf
Noralf's occasionally occupied with other things and doesn't have time to
look at patches. I think it's ok to just push after a few more days, even
if he doesn't respond. Same holds for other people really.
-Daniel
> > -Daniel
> >
> > > ---
> > > drivers/gpu/drm/drm_drv.c | 14 +++++++-------
> > > 1 file changed, 7 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> > > index b553a6f2ff0e..7af748ed1c58 100644
> > > --- a/drivers/gpu/drm/drm_drv.c
> > > +++ b/drivers/gpu/drm/drm_drv.c
> > > @@ -369,13 +369,6 @@ EXPORT_SYMBOL(drm_dev_exit);
> > > */
> > > void drm_dev_unplug(struct drm_device *dev)
> > > {
> > > - drm_dev_unregister(dev);
> > > -
> > > - mutex_lock(&drm_global_mutex);
> > > - if (dev->open_count == 0)
> > > - drm_dev_put(dev);
> > > - mutex_unlock(&drm_global_mutex);
> > > -
> > > /*
> > > * After synchronizing any critical read section is guaranteed to see
> > > * the new value of ->unplugged, and any critical section which might
> > > @@ -384,6 +377,13 @@ void drm_dev_unplug(struct drm_device *dev)
> > > */
> > > dev->unplugged = true;
> > > synchronize_srcu(&drm_unplug_srcu);
> > > +
> > > + drm_dev_unregister(dev);
> > > +
> > > + mutex_lock(&drm_global_mutex);
> > > + if (dev->open_count == 0)
> > > + drm_dev_put(dev);
> > > + mutex_unlock(&drm_global_mutex);
> > > }
> > > EXPORT_SYMBOL(drm_dev_unplug);
> > > --
> > > 2.17.0
> > >
> > > _______________________________________________
> > > dri-devel mailing list
> > > dri-devel@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm: Fix possible race conditions while unplugging DRM device
2018-05-29 7:49 ` Daniel Vetter
@ 2018-05-31 7:48 ` Oleksandr Andrushchenko
0 siblings, 0 replies; 6+ messages in thread
From: Oleksandr Andrushchenko @ 2018-05-31 7:48 UTC (permalink / raw)
To: Oleksandr_Andrushchenko, linux-kernel, dri-devel, airlied,
daniel.vetter, seanpaul, gustavo, Noralf Trønnes
On 05/29/2018 10:49 AM, Daniel Vetter wrote:
> On Tue, May 29, 2018 at 10:09:57AM +0300, Oleksandr Andrushchenko wrote:
>> On 05/29/2018 10:02 AM, Daniel Vetter wrote:
>>> On Tue, May 22, 2018 at 05:13:04PM +0300, Oleksandr Andrushchenko wrote:
>>>> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>>>>
>>>> When unplugging a hotpluggable DRM device we first unregister it
>>>> with drm_dev_unregister and then set drm_device.unplugged flag which
>>>> is used to mark device critical sections with drm_dev_enter()/
>>>> drm_dev_exit() preventing access to device resources that are not
>>>> available after the device is gone.
>>>> But drm_dev_unregister may lead to hotplug uevent(s) fired to
>>>> user-space on card and/or connector removal, thus making it possible
>>>> for user-space to try accessing a disconnected device.
>>>>
>>>> Fix this by first making sure device is properly marked as
>>>> disconnected and only then unregister it.
>>>>
>>>> Fixes: bee330f3d672 ("drm: Use srcu to protect drm_device.unplugged")
>>>>
>>>> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>>>> Reported-by: Andrii Chepurnyi <andrii_chepurnyi@epam.com>
>>>> Cc: "Noralf Trønnes" <noralf@tronnes.org>
>>> Nice catch.
>>>
>>> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
>>>
>>> I think you need to push this to drm-misc-next-fixes to make sure it's on
>>> the 4.17 train.
>> Sure, after I have r-b from Noralf
> Noralf's occasionally occupied with other things and doesn't have time to
> look at patches. I think it's ok to just push after a few more days, even
> if he doesn't respond. Same holds for other people really.
> -Daniel
>
Applied to drm-misc-next-fixes
>>> -Daniel
>>>
>>>> ---
>>>> drivers/gpu/drm/drm_drv.c | 14 +++++++-------
>>>> 1 file changed, 7 insertions(+), 7 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
>>>> index b553a6f2ff0e..7af748ed1c58 100644
>>>> --- a/drivers/gpu/drm/drm_drv.c
>>>> +++ b/drivers/gpu/drm/drm_drv.c
>>>> @@ -369,13 +369,6 @@ EXPORT_SYMBOL(drm_dev_exit);
>>>> */
>>>> void drm_dev_unplug(struct drm_device *dev)
>>>> {
>>>> - drm_dev_unregister(dev);
>>>> -
>>>> - mutex_lock(&drm_global_mutex);
>>>> - if (dev->open_count == 0)
>>>> - drm_dev_put(dev);
>>>> - mutex_unlock(&drm_global_mutex);
>>>> -
>>>> /*
>>>> * After synchronizing any critical read section is guaranteed to see
>>>> * the new value of ->unplugged, and any critical section which might
>>>> @@ -384,6 +377,13 @@ void drm_dev_unplug(struct drm_device *dev)
>>>> */
>>>> dev->unplugged = true;
>>>> synchronize_srcu(&drm_unplug_srcu);
>>>> +
>>>> + drm_dev_unregister(dev);
>>>> +
>>>> + mutex_lock(&drm_global_mutex);
>>>> + if (dev->open_count == 0)
>>>> + drm_dev_put(dev);
>>>> + mutex_unlock(&drm_global_mutex);
>>>> }
>>>> EXPORT_SYMBOL(drm_dev_unplug);
>>>> --
>>>> 2.17.0
>>>>
>>>> _______________________________________________
>>>> dri-devel mailing list
>>>> dri-devel@lists.freedesktop.org
>>>> https://lists.freedesktop.org/mailman/listinfo/dri-devel
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-05-31 7:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-22 14:13 [PATCH] drm: Fix possible race conditions while unplugging DRM device Oleksandr Andrushchenko
2018-05-29 6:25 ` Oleksandr Andrushchenko
2018-05-29 7:02 ` Daniel Vetter
2018-05-29 7:09 ` Oleksandr Andrushchenko
2018-05-29 7:49 ` Daniel Vetter
2018-05-31 7:48 ` Oleksandr Andrushchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).