ip_gre: Reject enabling collect metadata through changelink
Subsystems (3)
PATCH 1/1 ip_gre: Reject enabling collect metadata through changelink
From: Xuanqiang Luo <[email protected]>
ipgre_netlink_parms() can enable collect_md on an existing GRE, GRETAP or ERSPAN device. Unlike newlink, changelink does not enforce metadata tunnel uniqueness. Converting a non-metadata device can therefore replace the metadata receive entry for another device of the same type in the same netns. Deleting either device then clears the shared entry, breaking metadata receive lookup for the surviving device.
If parameter validation fails after collect_md is set, deleting the modified device can also clear an entry it never owned.
Reject enabling metadata mode in both changelink callbacks before any encapsulation or tunnel parameters are modified. Allow requests that repeat the metadata attribute on an existing metadata device.
---
The state change on failure can be reproduced without an existing metadata tunnel (output abbreviated):
# ip link add g1 type gre local 192.0.2.1 remote 192.0.2.2
# ip -d link show g1
link/gre 192.0.2.1 peer 192.0.2.2 ...
gre remote 192.0.2.2 local 192.0.2.1 ...# ip link set g1 type gre external RTNETLINK answers: Invalid argument
# ip -d link show g1
link/none c0:00:02:01 peer c0:00:02:02 ...
gre external remote 192.0.2.2 local 192.0.2.1 ...# ip link del g1
The request fails, but collect_md and the device type have already changed.
If another metadata tunnel exists, deleting this device can clear its collect_md_tun entry. A successful conversion can overwrite that entry.
net/ipv4/ip_gre.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/ipv4/ip_gre.c +6 -0
@@ -1464,6 +1464,9 @@ static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[],if (!rtnl_dev_link_net_capable (dev, t->net))return -EPERM ; +if (data && data[IFLA_GRE_COLLECT_METADATA ] && !t->collect_md) +return -EOPNOTSUPP ; + err =ipgre_newlink_encap_setup (dev, data);if (err)return err;
@@ -1496,6 +1499,9 @@ static int erspan_changelink(struct net_device *dev, struct nlattr *tb[],if (!rtnl_dev_link_net_capable (dev, t->net))return -EPERM ; +if (data && data[IFLA_GRE_COLLECT_METADATA ] && !t->collect_md) +return -EOPNOTSUPP ; + err =ipgre_newlink_encap_setup (dev, data);if (err)return err;
base-commit: c9151088f1674fd29ff26a20f5fc687acf53a2f0
Signature · 1 line
2.43.0
Ido Schimmel
maintainerQuoted 15 lines · Xuanqiang Luo
net/ipv4/ip_gre.c +3
-0@@ -1464,6 +1464,9 @@ static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[],if (!rtnl_dev_link_net_capable (dev, t->net))return -EPERM ; +if (data && data[IFLA_GRE_COLLECT_METADATA ] && !t->collect_md) +return -EOPNOTSUPP ; + err =ipgre_newlink_encap_setup (dev, data);if (err)return err;
net/ipv4/ip_gre.c static int erspan_changelink(struct net_device *dev, struct nlattr *tb[], · line 1503
Quoted 5 lines
net/ipv4/ip_gre.c +2
-0@@ -1496,6 +1499,9 @@ static int erspan_changelink(struct net_device *dev, struct nlattr *tb[],if (!rtnl_dev_link_net_capable (dev, t->net))return -EPERM ; +if (data && data[IFLA_GRE_COLLECT_METADATA ] && !t->collect_md) +return -EOPNOTSUPP ;
Both functions have extack, so please add a rejection message to make it clear to user space. Something like:
"Enabling collect_md on an existing device is not supported"
Also, I assume you audited other tunnels and confirmed that they don't suffer from this problem?
Quoted 8 lines
net/ipv4/ip_gre.c +1
-0+ err =ipgre_newlink_encap_setup (dev, data);if (err)return err;base-commit:
c9151088f1674fd29ff26a20f5fc687acf53a2f0Signature · 1 line
2.43.0
Quoted 19 lines · Ido Schimmel
Quoted 18 lines · Xuanqiang Luo
net/ipv4/ip_gre.c +3
-0@@ -1464,6 +1464,9 @@ static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[],if (!rtnl_dev_link_net_capable (dev, t->net))return -EPERM ; +if (data && data[IFLA_GRE_COLLECT_METADATA ] && !t->collect_md) +return -EOPNOTSUPP ; + err =ipgre_newlink_encap_setup (dev, data);if (err)return err;@@ -1496,6 +1499,9 @@ static int erspan_changelink(struct net_device *dev, struct nlattr *tb[],if (!rtnl_dev_link_net_capable (dev, t->net))return -EPERM ;
Quoted 7 lines
net/ipv4/ip_gre.c static int erspan_changelink(struct net_device *dev, struct nlattr *tb[], · line 1503
Quoted 2 lines
net/ipv4/ip_gre.c +2
-0+if (data && data[IFLA_GRE_COLLECT_METADATA ] && !t->collect_md) +return -EOPNOTSUPP ;Both functions have extack, so please add a rejection message to make it clear to user space. Something like:
"Enabling
collect_mdon an existing device is not supported"
Thanks for the suggestion!
I'll address this in v2.
Quoted 4 lines
Also, I assume you audited other tunnels and confirmed that they don't suffer from this problem?
Yes, I checked the relevant paths in other tunnels and found no similar issues.
Thanks,
Xuanqiang