Re: [PATCH] driver core: check 'start' argument in bus iterators

From: Kay Sievers
Date: Mon Apr 16 2012 - 07:52:08 EST


On Mon, Apr 16, 2012 at 12:48, Hannes Reinecke <hare@xxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/