Skip to content

Commit

Permalink
hsr: check protocol version in hsr_newlink()
Browse files Browse the repository at this point in the history
In the current hsr code, only 0 and 1 protocol versions are valid.
But current hsr code doesn't check the version, which is received by
userspace.

Test commands:
    ip link add dummy0 type dummy
    ip link add dummy1 type dummy
    ip link add hsr0 type hsr slave1 dummy0 slave2 dummy1 version 4

In the test commands, version 4 is invalid.
So, the command should be failed.

After this patch, following error will occur.
"Error: hsr: Only versions 0..1 are supported."

Fixes: ee1c279 ("net/hsr: Added support for HSR v1")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
TaeheeYoo authored and davem330 committed Apr 8, 2020
1 parent ab74110 commit 4faab8c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions net/hsr/hsr_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,16 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
else
multicast_spec = nla_get_u8(data[IFLA_HSR_MULTICAST_SPEC]);

if (!data[IFLA_HSR_VERSION])
if (!data[IFLA_HSR_VERSION]) {
hsr_version = 0;
else
} else {
hsr_version = nla_get_u8(data[IFLA_HSR_VERSION]);
if (hsr_version > 1) {
NL_SET_ERR_MSG_MOD(extack,
"Only versions 0..1 are supported");
return -EINVAL;
}
}

return hsr_dev_finalize(dev, link, multicast_spec, hsr_version, extack);
}
Expand Down

0 comments on commit 4faab8c

Please sign in to comment.