Skip to content

Commit 943e158

Browse files
jiribohacgregkh
authored andcommitted
net: check all name nodes in __dev_alloc_name
[ Upstream commit 6c015a2 ] __dev_alloc_name(), when supplied with a name containing '%d', will search for the first available device number to generate a unique device name. Since commit ff92741 ("net: introduce name_node struct to be used in hashlist") network devices may have alternate names. __dev_alloc_name() does take these alternate names into account, possibly generating a name that is already taken and failing with -ENFILE as a result. This demonstrates the bug: # rmmod dummy 2>/dev/null # ip link property add dev lo altname dummy0 # modprobe dummy numdummies=1 modprobe: ERROR: could not insert 'dummy': Too many open files in system Instead of creating a device named dummy1, modprobe fails. Fix this by checking all the names in the d->name_node list, not just d->name. Signed-off-by: Jiri Bohac <jbohac@suse.cz> Fixes: ff92741 ("net: introduce name_node struct to be used in hashlist") Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 748a158 commit 943e158

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎net/core/dev.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,18 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
11951195
return -ENOMEM;
11961196

11971197
for_each_netdev(net, d) {
1198+
struct netdev_name_node *name_node;
1199+
list_for_each_entry(name_node, &d->name_node->list, list) {
1200+
if (!sscanf(name_node->name, name, &i))
1201+
continue;
1202+
if (i < 0 || i >= max_netdevices)
1203+
continue;
1204+
1205+
/* avoid cases where sscanf is not exact inverse of printf */
1206+
snprintf(buf, IFNAMSIZ, name, i);
1207+
if (!strncmp(buf, name_node->name, IFNAMSIZ))
1208+
set_bit(i, inuse);
1209+
}
11981210
if (!sscanf(d->name, name, &i))
11991211
continue;
12001212
if (i < 0 || i >= max_netdevices)

0 commit comments

Comments
 (0)