net: control the length of the altname list
Subsystems (2)
Jakub Kicinski
maintainercover 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/[email protected]/
Targeting net-next because I think we generally don't consider tightening "root controlled" memory accounting to be a fix. There's also some risk of breakage.
Jakub Kicinski (2):
net: account alternate interface name memory
net: limit altnames to 64k total
net/core/rtnetlink.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerPATCH 2/2 net: limit altnames to 64k total
Property list (altname is a link "property") is wrapped in a nlattr. nlattrs length is 16bit so practically speaking the list of properties can't be longer than that, otherwise user space would have to interpret broken netlink messages.
Prevent the problem from occurring by checking the length of the property list before adding new entries.
--- net/core/rtnetlink.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
net/core/rtnetlink.c +11 -0
@@ -3652,12 +3652,23 @@ 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; +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 ;
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerPATCH 1/2 net: account alternate interface name memory
In reply to Jakub KicinskiGeorge reports that altnames can eat up kernel memory. We should charge that memory appropriately.
--- net/core/rtnetlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/rtnetlink.c +1 -1
@@ -3658,7 +3658,7 @@ static int rtnl_alt_ifname(int cmd, struct net_device *dev, struct nlattr *attr,if (err)return err; - alt_ifname =nla_strdup (attr,GFP_KERNEL ); + alt_ifname =nla_strdup (attr,GFP_KERNEL_ACCOUNT );if (!alt_ifname)return -ENOMEM ;
Signature · 1 line
2.34.1
Re: [PATCH net-next 2/2] net: limit altnames to 64k total
In reply to Jakub KicinskiQuoted 18 lines · Jakub Kicinski
net/core/rtnetlink.c +4
-0@@ -3652,12 +3652,23 @@ 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; +if (cmd ==RTM_NEWLINKPROP ) { + size =rtnl_prop_list_size (dev); + size +=nla_total_size (ALTIFNAMSIZ );
net/core/rtnetlink.c static int rtnl_alt_ifname(int cmd, struct net_device *dev, struct nlattr *attr, · line 3674
Quoted 10 lines
net/core/rtnetlink.c +7
-0+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 ;
this tests the existing property size. Don't you want to test the size with the alt_ifname - does it make the list go over 64kB?
Jakub Kicinski
maintainerRe: [PATCH net-next 2/2] net: limit altnames to 64k total
Quoted 16 lines · On Wed, 9 Mar 2022 19:51:07 -0700 David Ahern wrote:
Quoted 15 lines · Jakub Kicinski
net/core/rtnetlink.c +1
-0@@ -3652,12 +3652,23 @@ 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;
Quoted 16 lines
net/core/rtnetlink.c static int rtnl_alt_ifname(int cmd, struct net_device *dev, struct nlattr *attr, · line 3674
Quoted 13 lines
net/core/rtnetlink.c +10
-0+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 ;this tests the existing property size. Don't you want to test the size with the
alt_ifname- does it make the list go over 64kB?
Do you mean counting the exact length of the string?
Or that I'm counting pre-add? That's why I added:
size += nla_total_size(ALTIFNAMSIZ);
I like coding things up as prepare (validate) + commit, granted it doesn't exactly look pretty here so I can recode if you prefer. But there's no bug, right? (other than maybe
Quoted 1 line
= could have been > but whatever).
David Ahern
Reviewed-byRe: [PATCH net-next 2/2] net: limit altnames to 64k total
Quoted 36 lines · Jakub Kicinski
Quoted 16 lines · On Wed, 9 Mar 2022 19:51:07 -0700 David Ahern wrote:
Quoted 15 lines · Jakub Kicinski
net/core/rtnetlink.c +1
-0@@ -3652,12 +3652,23 @@ 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;Quoted 16 lines
net/core/rtnetlink.c static int rtnl_alt_ifname(int cmd, struct net_device *dev, struct nlattr *attr, · line 3674
Quoted 13 lines
net/core/rtnetlink.c +10
-0+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 ;this tests the existing property size. Don't you want to test the size with the
alt_ifname- does it make the list go over 64kB?Do you mean counting the exact length of the string?
Quoted 8 lines
Or that I'm counting pre-add? That's why I added:
size += nla_total_size(ALTIFNAMSIZ);I like coding things up as prepare (validate) + commit, granted it doesn't exactly look pretty here so I can recode if you prefer. But there's no bug, right? (other than maybe
Quoted 1 line
= could have been > but whatever).
right. It's a worst case size estimation versus taking into account the actual space used for the name (rtnl_prop_list_size does that for each name so this is really conservative in space use).
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Wed, 9 Mar 2022 10:29:12 -0800 you wrote:
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/[email protected]/Targeting net-next because I think we generally don't consider tightening "root controlled" memory accounting to be a fix. There's also some risk of breakage.
[...]
Here is the summary with links:
- [net-next,1/2] net: account alternate interface name memory
https://git.kernel.org/netdev/net-next/c/5d26cff5bdbe - [net-next,2/2] net: limit altnames to 64k total https://git.kernel.org/netdev/net-next/c/155fb43b70b5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html