Merge branch 'net-control-the-length-of-the-altname-list'

Jakub Kicinski says:

====================
net: control the length of the altname list

Count the memory used for altnames and don't let user
overflow the property nlattr. This was reported by George:
https://lore.kernel.org/all/3e564baf-a1dd-122e-2882-ff143f7eb578@gmail.com/
====================

Link: https://lore.kernel.org/r/20220309182914.423834-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2022-03-10 20:15:29 -08:00
commit 4622485361

View File

@ -3652,13 +3652,24 @@ static int rtnl_alt_ifname(int cmd, struct net_device *dev, struct nlattr *attr,
bool *changed, struct netlink_ext_ack *extack)
{
char *alt_ifname;
size_t size;
int err;
err = nla_validate(attr, attr->nla_len, IFLA_MAX, ifla_policy, extack);
if (err)
return err;
alt_ifname = nla_strdup(attr, GFP_KERNEL);
if (cmd == RTM_NEWLINKPROP) {
size = rtnl_prop_list_size(dev);
size += nla_total_size(ALTIFNAMSIZ);
if (size >= U16_MAX) {
NL_SET_ERR_MSG(extack,
"effective property list too long");
return -EINVAL;
}
}
alt_ifname = nla_strdup(attr, GFP_KERNEL_ACCOUNT);
if (!alt_ifname)
return -ENOMEM;