Skip to contentSkip to conversation

tcp_metrics: use netlink policy for IPv6 addr len validation

PATCH Applied Jakub Kicinski 4 participants 4 messages Aug 16, 2024 – Aug 20, 2024

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 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.

---
CC: [email protected]

---
 net/ipv4/tcp_metrics.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
net/ipv4/tcp_metrics.c +6 -4
index b01eb6d94413..95669935494e 100644
@@ -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] = {
 	[TCP_METRICS_ATTR_ADDR_IPV4]	= { .type = NLA_U32, },
-	[TCP_METRICS_ATTR_ADDR_IPV6]	= { .type = NLA_BINARY,
-					    .len = sizeof(struct in6_addr), },
+	[TCP_METRICS_ATTR_ADDR_IPV6]	=
+		NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)),
+
 	[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,
 	 * we keep them for reference
 	 */
@@ -811,8 +815,6 @@ static int __parse_nl_addr(struct genl_info *info, struct inetpeer_addr *addr,
 	if (a) {
 		struct in6_addr in6;
 
-		if (nla_len(a) != sizeof(struct in6_addr))
-			return -EINVAL;
 		in6 = nla_get_in6_addr(a);
 		inetpeer_set_addr_v6(addr, &in6);
 		if (hash)
Signature · 1 line
2.46.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Fri, 16 Aug 2024 14:22:44 -0700 Jakub Kicinski <[email protected]> wrote:

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 on v1 1/1
#2 lore raw
In reply to Jakub Kicinski
Quoted 6 lines · Jakub Kicinski

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.

Quoted 7 lines

---
CC: [email protected]

---
 net/ipv4/tcp_metrics.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
#3 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Fri, 16 Aug 2024 14:22:44 -0700 you wrote:

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.

[...]

Here is the summary with links:
- [net-next] tcp_metrics: use netlink policy for IPv6 addr len validation

    https://git.kernel.org/netdev/net-next/c/a2901083b149

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html