Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3490809pxf; Mon, 29 Mar 2021 03:51:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxA0CrzyL+g3Wmel0uauwbYud6aEtfNe1snKRfGh7zPgb95Ob2vZqMQl0grxG6N/Yvq1E0f X-Received: by 2002:aa7:d492:: with SMTP id b18mr27670170edr.381.1617015085183; Mon, 29 Mar 2021 03:51:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617015085; cv=none; d=google.com; s=arc-20160816; b=oBrzFzLpD8rXAS6Q5h/YxqUMgA606DN8mcfwHiL+ghWVj9Y3z0uzC0pD2g+MOWAfP2 SSAMRy6S4DTXEW7y+uIYXZdNcNBzqwo/s06jJ3WWekNAailNayUqvxvWFcIkzFMqzaqC 9n9h56B8Zyz+YYmvGaTzRZlq9gGthy4r5mUzrWSqhDAGQR+6UsszMqqnVS8hmkDCuRF4 I+vCsPapTMMf/0NF0cFad5ldKB1BNkjrJ62SYDWlhM4/Q/hfzA6TEKK3oHZ29bFw8gwk nRXlNc1Gj9lAvZqLx9ryTL9zuQ0VAWVm0OwNNKneAsPfuGZO0kn1NswHqqO/yr6eNzUd 25jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9cXD7wgxw5jcmaDmcxlLnGgY5dHIppkchcfA4v8zaSk=; b=twbzGBCnApM89NAHHbKPrJ27Z1iut3oz/FS4iOGd/LO43JHspk7RkkbnPd+NLiM/qb BzqJo9n6kUOlqsH3kianISOQ1V2V523NLNiJsf9psseccx89bB68WyzVtHgMwzAnZr3+ R55UIU1MAYB8ZHqUoENFWvrEmbiD0To02Hqf3mnohEpeSolvJk6LcuE7+0AfJP7TOxIB zNCwoY0f5IimaMEyazmADkDOneXO4cNQjjJr/wZL3kWJ5r0JsANTgPnVWAbPlkRnsGOT Ylaf/yIIzBGXo76RTYJmcusP0TELyRWSgSMJR9jejBI3uKkTTjspmnRX0yPsYSbXigDi ysZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="m2SE8ff/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jp24si11966838ejb.512.2021.03.29.03.51.02; Mon, 29 Mar 2021 03:51:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="m2SE8ff/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232078AbhC2IjX (ORCPT + 99 others); Mon, 29 Mar 2021 04:39:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:40608 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233106AbhC2IXX (ORCPT ); Mon, 29 Mar 2021 04:23:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5451861554; Mon, 29 Mar 2021 08:23:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617006202; bh=OccUCev7wftWWMxIJL7xbKd2olf2arqmEU/Kp+ISNkU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m2SE8ff/tFXqL95yhWzcUn07B5YSoHj3Bs2DZDogO11g/Dtp3Pp+NaHsoLHsXYKXM QMxeq7WNGBUt26jz1Av15i2OSNyNTl9DrCEQi7084LO9s2pLj0gIesbirgqmOGlL/T 49wqdetH0z6bgs4F4puV92ZEyejSAmbB8QrtnjgE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Bohac , Jiri Pirko , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 156/221] net: check all name nodes in __dev_alloc_name Date: Mon, 29 Mar 2021 09:58:07 +0200 Message-Id: <20210329075634.365237903@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Bohac [ 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 Fixes: ff92741270bf ("net: introduce name_node struct to be used in hashlist") Reviewed-by: Jiri Pirko Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/core/dev.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/core/dev.c b/net/core/dev.c index 75ca6c6d01d6..dbc286fd2047 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1195,6 +1195,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) -- 2.30.1