Skip to content

Commit

Permalink
xfrm interface: avoid corruption on changelink
Browse files Browse the repository at this point in the history
The new parameters must not be stored in the netdev_priv() before
validation, it may corrupt the interface. Note also that if data is NULL,
only a memset() is done.

$ ip link add xfrm1 type xfrm dev lo if_id 1
$ ip link add xfrm2 type xfrm dev lo if_id 2
$ ip link set xfrm1 type xfrm dev lo if_id 2
RTNETLINK answers: File exists
$ ip -d link list dev xfrm1
5: xfrm1@lo: <NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/none 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 minmtu 68 maxmtu 1500
    xfrm if_id 0x2 addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535

=> "if_id 0x2"

Fixes: f203b76 ("xfrm: Add virtual xfrm interfaces")
Signed-off-by: Nicolas Dichtel <[email protected]>
Tested-by: Julien Floret <[email protected]>
Signed-off-by: Steffen Klassert <[email protected]>
  • Loading branch information
NicolasDichtel authored and klassert committed Jul 17, 2019
1 parent 114a5c3 commit e9e7e85
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions net/xfrm/xfrm_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,20 +671,20 @@ static int xfrmi_changelink(struct net_device *dev, struct nlattr *tb[],
struct nlattr *data[],
struct netlink_ext_ack *extack)
{
struct xfrm_if *xi = netdev_priv(dev);
struct net *net = dev_net(dev);
struct xfrm_if_parms p;
struct xfrm_if *xi;

xfrmi_netlink_parms(data, &xi->p);

xi = xfrmi_locate(net, &xi->p);
xfrmi_netlink_parms(data, &p);
xi = xfrmi_locate(net, &p);
if (!xi) {
xi = netdev_priv(dev);
} else {
if (xi->dev != dev)
return -EEXIST;
}

return xfrmi_update(xi, &xi->p);
return xfrmi_update(xi, &p);
}

static size_t xfrmi_get_size(const struct net_device *dev)
Expand Down

0 comments on commit e9e7e85

Please sign in to comment.