ppp: Fix generating ifname when empty IFLA_IFNAME is specified
authorPali Rohár <pali@kernel.org>
Sat, 7 Aug 2021 13:27:03 +0000 (15:27 +0200)
committerSasha Levin <sashal@kernel.org>
Thu, 26 Aug 2021 12:36:38 +0000 (08:36 -0400)
commit0bc8d39791e65d2812746b6a07df4e1d482b7e08
tree83ef192dc5dc24700aab479a85e769abff708b52
parentf08a3b83463c66509b8a1034e5c416cfade1a5cd
ppp: Fix generating ifname when empty IFLA_IFNAME is specified

[ Upstream commit 2459dcb96bcba94c08d6861f8a050185ff301672 ]

IFLA_IFNAME is nul-term string which means that IFLA_IFNAME buffer can be
larger than length of string which contains.

Function __rtnl_newlink() generates new own ifname if either IFLA_IFNAME
was not specified at all or userspace passed empty nul-term string.

It is expected that if userspace does not specify ifname for new ppp netdev
then kernel generates one in format "ppp<id>" where id matches to the ppp
unit id which can be later obtained by PPPIOCGUNIT ioctl.

And it works in this way if IFLA_IFNAME is not specified at all. But it
does not work when IFLA_IFNAME is specified with empty string.

So fix this logic also for empty IFLA_IFNAME in ppp_nl_newlink() function
and correctly generates ifname based on ppp unit identifier if userspace
did not provided preferred ifname.

Without this patch when IFLA_IFNAME was specified with empty string then
kernel created a new ppp interface in format "ppp<id>" but id did not
match ppp unit id returned by PPPIOCGUNIT ioctl. In this case id was some
number generated by __rtnl_newlink() function.

Signed-off-by: Pali Rohár <pali@kernel.org>
Fixes: bb8082f69138 ("ppp: build ifname using unit identifier for rtnl based devices")
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ppp/ppp_generic.c