Re: [PATCH net v2 3/3] net: core: avoid warning in dev_change_net_namespace()

From: Greg KH
Date: Sat Apr 04 2020 - 11:52:53 EST


On Sat, Apr 04, 2020 at 02:19:22PM +0000, Taehee Yoo wrote:
> When interface's namespace is being changed, dev_change_net_namespace()
> is called. This removes and re-allocates many resources that include
> sysfs files. The "/net/class/net/<interface name>" is one of them.
> If the sysfs creation routine(device_rename()) found duplicate sysfs
> file name, it warns about it and fails. But unfortunately, at that point,
> dev_change_net_namespace() doesn't return fail because rollback cost
> is too high.
> So, the interface can't have a sysfs file.

Why don't you check for a duplicate namespace before you do anything
like mess with sysfs? Wouldn't that be the correct thing instead of
trying to paper over the issue by having sysfs be the thing to tell you
not to do this or not?

> The approach of this patch is to find the duplicate sysfs file as
> fast as possible. If it found that, dev_change_net_namespace() returns
> fail immediately with zero rollback cost.

Don't rely on sysfs to save you from this race condition, it's not the
way to do it at all.

greg k-h