* [PATCH] driver core: check 'start' argument in bus iterators
@ 2012-04-16 10:48 Hannes Reinecke
2012-04-16 11:51 ` Kay Sievers
0 siblings, 1 reply; 3+ messages in thread
From: Hannes Reinecke @ 2012-04-16 10:48 UTC (permalink / raw)
To: Linux Kernel
Cc: Hannes Reinecke, Greg Kroah-Hartmann, Kay Sievers, Stable Kernel
bus_for_each_dev() and bus_find_device() both take a 'start'
argument to start the iteration at a specific list entry.
However, this list entry might already been detached by
the time these functions are called.
So we need to check if the arguments are still valid.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Cc: Greg Kroah-Hartmann <gregkh@linuxfoundation.org>
Cc: Kay Sievers <ksievers@vrfy.org>
Cc: Stable Kernel <stable@kernel.org>
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 26a06b8..264e498 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -297,6 +297,9 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start,
if (!bus)
return -EINVAL;
+ if (start && !klist_node_attached(&start->p->knode_bus))
+ return -ENODEV;
+
klist_iter_init_node(&bus->p->klist_devices, &i,
(start ? &start->p->knode_bus : NULL));
while ((dev = next_device(&i)) && !error)
@@ -331,6 +334,9 @@ struct device *bus_find_device(struct bus_type *bus,
if (!bus)
return NULL;
+ if (start && !klist_node_attached(&start->p->knode_bus))
+ return NULL;
+
klist_iter_init_node(&bus->p->klist_devices, &i,
(start ? &start->p->knode_bus : NULL));
while ((dev = next_device(&i)))
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] driver core: check 'start' argument in bus iterators
2012-04-16 10:48 [PATCH] driver core: check 'start' argument in bus iterators Hannes Reinecke
@ 2012-04-16 11:51 ` Kay Sievers
2012-04-16 12:10 ` Hannes Reinecke
0 siblings, 1 reply; 3+ messages in thread
From: Kay Sievers @ 2012-04-16 11:51 UTC (permalink / raw)
To: Hannes Reinecke
Cc: Linux Kernel, Greg Kroah-Hartmann, Kay Sievers, Stable Kernel
On Mon, Apr 16, 2012 at 12:48, Hannes Reinecke <hare@suse.de> wrote:
> bus_for_each_dev() and bus_find_device() both take a 'start'
> argument to start the iteration at a specific list entry.
> However, this list entry might already been detached by
> the time these functions are called.
> So we need to check if the arguments are still valid.
> + if (start && !klist_node_attached(&start->p->knode_bus))
> + return -ENODEV;
> +
> klist_iter_init_node(&bus->p->klist_devices, &i,
> (start ? &start->p->knode_bus : NULL));
Shouldn't we do this check in klist_iter_init_node()?
After a kref_get(), and return -ENODEV from there if the node it as
asked to start is gone?
This check otherwise still has the window between the check and the
use of it, only very unlikely to hit now, hasn't it?
Kay
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] driver core: check 'start' argument in bus iterators
2012-04-16 11:51 ` Kay Sievers
@ 2012-04-16 12:10 ` Hannes Reinecke
0 siblings, 0 replies; 3+ messages in thread
From: Hannes Reinecke @ 2012-04-16 12:10 UTC (permalink / raw)
To: Kay Sievers; +Cc: Linux Kernel, Greg Kroah-Hartmann, Stable Kernel
On 04/16/2012 01:51 PM, Kay Sievers wrote:
> On Mon, Apr 16, 2012 at 12:48, Hannes Reinecke <hare@suse.de> wrote:
>> bus_for_each_dev() and bus_find_device() both take a 'start'
>> argument to start the iteration at a specific list entry.
>> However, this list entry might already been detached by
>> the time these functions are called.
>> So we need to check if the arguments are still valid.
>
>> + if (start && !klist_node_attached(&start->p->knode_bus))
>> + return -ENODEV;
>> +
>> klist_iter_init_node(&bus->p->klist_devices, &i,
>> (start ? &start->p->knode_bus : NULL));
>
> Shouldn't we do this check in klist_iter_init_node()?
> After a kref_get(), and return -ENODEV from there if the node it as
> asked to start is gone?
>
Sure, if you prefer.
> This check otherwise still has the window between the check and the
> use of it, only very unlikely to hit now, hasn't it?
>
yeah, very.
The iteration itself could take some time (locks etc), but the race
between those two lines is really tiny.
But yeah, for the sake of correctness, we should.
I'll be sending an updated patch.
Cheers,
Hannes
--
Dr. Hannes Reinecke zSeries & Storage
hare@suse.de +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-04-16 12:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-16 10:48 [PATCH] driver core: check 'start' argument in bus iterators Hannes Reinecke
2012-04-16 11:51 ` Kay Sievers
2012-04-16 12:10 ` Hannes Reinecke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox