Skip to content

Commit 8bda81a

Browse files
dsaherndavem330
authored andcommitted
lwtunnel: Validate RTA_ENCAP_TYPE attribute length
lwtunnel_valid_encap_type_attr is used to validate encap attributes within a multipath route. Add length validation checking to the type. lwtunnel_valid_encap_type_attr is called converting attributes to fib{6,}_config struct which means it is used before fib_get_nhs, ip6_route_multipath_add, and ip6_route_multipath_del - other locations that use rtnh_ok and then nla_get_u16 on RTA_ENCAP_TYPE attribute. Fixes: 9ed5959 ("lwtunnel: fix autoload of lwt modules") Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1ff15a7 commit 8bda81a

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

net/core/lwtunnel.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int remaining,
197197
nla_entype = nla_find(attrs, attrlen, RTA_ENCAP_TYPE);
198198

199199
if (nla_entype) {
200+
if (nla_len(nla_entype) < sizeof(u16)) {
201+
NL_SET_ERR_MSG(extack, "Invalid RTA_ENCAP_TYPE");
202+
return -EINVAL;
203+
}
200204
encap_type = nla_get_u16(nla_entype);
201205

202206
if (lwtunnel_valid_encap_type(encap_type,

net/ipv4/fib_semantics.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,9 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
740740
}
741741

742742
fib_cfg.fc_encap = nla_find(attrs, attrlen, RTA_ENCAP);
743+
/* RTA_ENCAP_TYPE length checked in
744+
* lwtunnel_valid_encap_type_attr
745+
*/
743746
nla = nla_find(attrs, attrlen, RTA_ENCAP_TYPE);
744747
if (nla)
745748
fib_cfg.fc_encap_type = nla_get_u16(nla);

net/ipv6/route.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5287,6 +5287,10 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
52875287
r_cfg.fc_flags |= RTF_GATEWAY;
52885288
}
52895289
r_cfg.fc_encap = nla_find(attrs, attrlen, RTA_ENCAP);
5290+
5291+
/* RTA_ENCAP_TYPE length checked in
5292+
* lwtunnel_valid_encap_type_attr
5293+
*/
52905294
nla = nla_find(attrs, attrlen, RTA_ENCAP_TYPE);
52915295
if (nla)
52925296
r_cfg.fc_encap_type = nla_get_u16(nla);

0 commit comments

Comments
 (0)