Skip to content

Commit 4619bcf

Browse files
dsaherndavem330
authored andcommitted
ipv6: Check attribute length for RTA_GATEWAY in multipath route
Commit referenced in the Fixes tag used nla_memcpy for RTA_GATEWAY as does the current nla_get_in6_addr. nla_memcpy protects against accessing memory greater than what is in the attribute, but there is no check requiring the attribute to have an IPv6 address. Add it. Fixes: 51ebd31 ("ipv6: add support of equal cost multipath (ECMP)") Signed-off-by: David Ahern <[email protected]> Cc: Nicolas Dichtel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 664b9c4 commit 4619bcf

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

net/ipv6/route.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5224,6 +5224,19 @@ static bool ip6_route_mpath_should_notify(const struct fib6_info *rt)
52245224
return should_notify;
52255225
}
52265226

5227+
static int fib6_gw_from_attr(struct in6_addr *gw, struct nlattr *nla,
5228+
struct netlink_ext_ack *extack)
5229+
{
5230+
if (nla_len(nla) < sizeof(*gw)) {
5231+
NL_SET_ERR_MSG(extack, "Invalid IPv6 address in RTA_GATEWAY");
5232+
return -EINVAL;
5233+
}
5234+
5235+
*gw = nla_get_in6_addr(nla);
5236+
5237+
return 0;
5238+
}
5239+
52275240
static int ip6_route_multipath_add(struct fib6_config *cfg,
52285241
struct netlink_ext_ack *extack)
52295242
{
@@ -5264,7 +5277,13 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
52645277

52655278
nla = nla_find(attrs, attrlen, RTA_GATEWAY);
52665279
if (nla) {
5267-
r_cfg.fc_gateway = nla_get_in6_addr(nla);
5280+
int ret;
5281+
5282+
ret = fib6_gw_from_attr(&r_cfg.fc_gateway, nla,
5283+
extack);
5284+
if (ret)
5285+
return ret;
5286+
52685287
r_cfg.fc_flags |= RTF_GATEWAY;
52695288
}
52705289
r_cfg.fc_encap = nla_find(attrs, attrlen, RTA_ENCAP);

0 commit comments

Comments
 (0)