Commit a2901083 authored by Jakub Kicinski's avatar Jakub Kicinski

tcp_metrics: use netlink policy for IPv6 addr len validation

Use the netlink policy to validate IPv6 address length.
Destination address currently has policy for max len set,
and source has no policy validation. In both cases
the code does the real check. With correct policy
check the code can be removed.
Reviewed-by: default avatarStephen Hemminger <stephen@networkplumber.org>
Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
Link: https://patch.msgid.link/20240816212245.467745-1-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 1bf8e07c
...@@ -617,9 +617,13 @@ static struct genl_family tcp_metrics_nl_family; ...@@ -617,9 +617,13 @@ static struct genl_family tcp_metrics_nl_family;
static const struct nla_policy tcp_metrics_nl_policy[TCP_METRICS_ATTR_MAX + 1] = { static const struct nla_policy tcp_metrics_nl_policy[TCP_METRICS_ATTR_MAX + 1] = {
[TCP_METRICS_ATTR_ADDR_IPV4] = { .type = NLA_U32, }, [TCP_METRICS_ATTR_ADDR_IPV4] = { .type = NLA_U32, },
[TCP_METRICS_ATTR_ADDR_IPV6] = { .type = NLA_BINARY, [TCP_METRICS_ATTR_ADDR_IPV6] =
.len = sizeof(struct in6_addr), }, NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)),
[TCP_METRICS_ATTR_SADDR_IPV4] = { .type = NLA_U32, }, [TCP_METRICS_ATTR_SADDR_IPV4] = { .type = NLA_U32, },
[TCP_METRICS_ATTR_SADDR_IPV6] =
NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)),
/* Following attributes are not received for GET/DEL, /* Following attributes are not received for GET/DEL,
* we keep them for reference * we keep them for reference
*/ */
...@@ -811,8 +815,6 @@ static int __parse_nl_addr(struct genl_info *info, struct inetpeer_addr *addr, ...@@ -811,8 +815,6 @@ static int __parse_nl_addr(struct genl_info *info, struct inetpeer_addr *addr,
if (a) { if (a) {
struct in6_addr in6; struct in6_addr in6;
if (nla_len(a) != sizeof(struct in6_addr))
return -EINVAL;
in6 = nla_get_in6_addr(a); in6 = nla_get_in6_addr(a);
inetpeer_set_addr_v6(addr, &in6); inetpeer_set_addr_v6(addr, &in6);
if (hash) if (hash)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment