Skip to content

Commit fef5b22

Browse files
lxinkuba-moo
authored andcommitted
rtnetlink: move IFLA_GSO_ tb check to validate_linkmsg
These IFLA_GSO_* tb check should also be done for the new created link, otherwise, they can be set to a huge value when creating links: # ip link add dummy1 gso_max_size 4294967295 type dummy # ip -d link show dummy1 dummy addrgenmode eui64 ... gso_max_size 4294967295 Fixes: 46e6b99 ("rtnetlink: allow GSO maximums to be set on device creation") Fixes: 9eefedd ("net: add gso_ipv4_max_size and gro_ipv4_max_size per device") Signed-off-by: Xin Long <lucien.xin@gmail.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent b0ad3c1 commit fef5b22

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

net/core/rtnetlink.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,25 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[],
23852385
if (tb[IFLA_BROADCAST] &&
23862386
nla_len(tb[IFLA_BROADCAST]) < dev->addr_len)
23872387
return -EINVAL;
2388+
2389+
if (tb[IFLA_GSO_MAX_SIZE] &&
2390+
nla_get_u32(tb[IFLA_GSO_MAX_SIZE]) > dev->tso_max_size) {
2391+
NL_SET_ERR_MSG(extack, "too big gso_max_size");
2392+
return -EINVAL;
2393+
}
2394+
2395+
if (tb[IFLA_GSO_MAX_SEGS] &&
2396+
(nla_get_u32(tb[IFLA_GSO_MAX_SEGS]) > GSO_MAX_SEGS ||
2397+
nla_get_u32(tb[IFLA_GSO_MAX_SEGS]) > dev->tso_max_segs)) {
2398+
NL_SET_ERR_MSG(extack, "too big gso_max_segs");
2399+
return -EINVAL;
2400+
}
2401+
2402+
if (tb[IFLA_GSO_IPV4_MAX_SIZE] &&
2403+
nla_get_u32(tb[IFLA_GSO_IPV4_MAX_SIZE]) > dev->tso_max_size) {
2404+
NL_SET_ERR_MSG(extack, "too big gso_ipv4_max_size");
2405+
return -EINVAL;
2406+
}
23882407
}
23892408

23902409
if (tb[IFLA_AF_SPEC]) {
@@ -2858,11 +2877,6 @@ static int do_setlink(const struct sk_buff *skb,
28582877
if (tb[IFLA_GSO_MAX_SIZE]) {
28592878
u32 max_size = nla_get_u32(tb[IFLA_GSO_MAX_SIZE]);
28602879

2861-
if (max_size > dev->tso_max_size) {
2862-
err = -EINVAL;
2863-
goto errout;
2864-
}
2865-
28662880
if (dev->gso_max_size ^ max_size) {
28672881
netif_set_gso_max_size(dev, max_size);
28682882
status |= DO_SETLINK_MODIFIED;
@@ -2872,11 +2886,6 @@ static int do_setlink(const struct sk_buff *skb,
28722886
if (tb[IFLA_GSO_MAX_SEGS]) {
28732887
u32 max_segs = nla_get_u32(tb[IFLA_GSO_MAX_SEGS]);
28742888

2875-
if (max_segs > GSO_MAX_SEGS || max_segs > dev->tso_max_segs) {
2876-
err = -EINVAL;
2877-
goto errout;
2878-
}
2879-
28802889
if (dev->gso_max_segs ^ max_segs) {
28812890
netif_set_gso_max_segs(dev, max_segs);
28822891
status |= DO_SETLINK_MODIFIED;
@@ -2895,11 +2904,6 @@ static int do_setlink(const struct sk_buff *skb,
28952904
if (tb[IFLA_GSO_IPV4_MAX_SIZE]) {
28962905
u32 max_size = nla_get_u32(tb[IFLA_GSO_IPV4_MAX_SIZE]);
28972906

2898-
if (max_size > dev->tso_max_size) {
2899-
err = -EINVAL;
2900-
goto errout;
2901-
}
2902-
29032907
if (dev->gso_ipv4_max_size ^ max_size) {
29042908
netif_set_gso_ipv4_max_size(dev, max_size);
29052909
status |= DO_SETLINK_MODIFIED;

0 commit comments

Comments
 (0)