Patch "net: check all name nodes in __dev_alloc_name" has been added to the 5.11-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    net: check all name nodes in __dev_alloc_name

to the 5.11-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     net-check-all-name-nodes-in-__dev_alloc_name.patch
and it can be found in the queue-5.11 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 7e00f839331938225189e042877d6eaf94f31d84
Author: Jiri Bohac <jbohac@xxxxxxx>
Date:   Thu Mar 18 04:42:53 2021 +0100

    net: check all name nodes in __dev_alloc_name
    
    [ Upstream commit 6c015a2256801597fadcbc11d287774c9c512fa5 ]
    
    __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 ff92741270bf8b6e78aa885f166b68c7a67ab13a ("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@xxxxxxx>
    Fixes: ff92741270bf ("net: introduce name_node struct to be used in hashlist")
    Reviewed-by: Jiri Pirko <jiri@xxxxxxxxxx>
    Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/core/dev.c b/net/core/dev.c
index a5a1dbe66b76..541ee3bc467b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1182,6 +1182,18 @@ static int __dev_alloc_name(struct net *net, const char *name, char *buf)
 			return -ENOMEM;
 
 		for_each_netdev(net, d) {
+			struct netdev_name_node *name_node;
+			list_for_each_entry(name_node, &d->name_node->list, list) {
+				if (!sscanf(name_node->name, name, &i))
+					continue;
+				if (i < 0 || i >= max_netdevices)
+					continue;
+
+				/*  avoid cases where sscanf is not exact inverse of printf */
+				snprintf(buf, IFNAMSIZ, name, i);
+				if (!strncmp(buf, name_node->name, IFNAMSIZ))
+					set_bit(i, inuse);
+			}
 			if (!sscanf(d->name, name, &i))
 				continue;
 			if (i < 0 || i >= max_netdevices)



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux