net/tcp-ao: fix reset key lookup for IPv4 segments on IPv6 listeners
Subsystems (3)
PATCH v2 1/1 net/tcp-ao: fix reset key lookup for IPv4 segments on IPv6 listeners
tcp_ao_prepare_reset() looks up the key for a reset that is sent on behalf of a listener by the address of the peer. It takes that address from the IPv6 header whenever the listener is an AF_INET6 socket, also when the segment is an IPv4 one that arrived on a dual-stack listener. The address is then read from the middle of the IPv4 header, the key of the peer is not found and the reset is not sent.
The v4-mapped check that follows does not help: it looks at sk->sk_v6_daddr, which is the unspecified address for a listener, and it runs after the address has been picked.
Take the family and the address from the protocol of the segment instead of the family of the socket.
---
v2:
- Take the family from skb->protocol only, do not read sk->sk_family (Kuniyuki).
v1: https://lore.kernel.org/all/[email protected]/
net/ipv4/tcp_ao.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
net/ipv4/tcp_ao.c +7 -7
@@ -799,8 +799,8 @@ int tcp_ao_prepare_reset(const struct sock *sk, struct sk_buff *skb,return -ENOTCONN ;if ((1 << sk->sk_state) & (TCPF_LISTEN |TCPF_NEW_SYN_RECV )) { -unsigned int family =READ_ONCE (sk->sk_family);union tcp_ao_addr *addr; +unsigned int family;__be32 disn, sisn;if (sk->sk_state ==TCP_NEW_SYN_RECV ) {
@@ -813,14 +813,14 @@ int tcp_ao_prepare_reset(const struct sock *sk, struct sk_buff *skb, sisn = th->seq; disn =0 ; } -if (IS_ENABLED (CONFIG_IPV6 ) && family ==AF_INET6 ) +if (IS_ENABLED (CONFIG_IPV6 ) && + skb->protocol ==htons (ETH_P_IPV6 )) { + family =AF_INET6 ; addr = (union tcp_md5_addr *)&ipv6_hdr (skb)->saddr; -else - addr = (union tcp_md5_addr *)&ip_hdr (skb)->saddr; -#if IS_ENABLED (CONFIG_IPV6 ) -if (family ==AF_INET6 &&ipv6_addr_v4mapped (&sk->sk_v6_daddr)) + }else { family =AF_INET ; -#endif + addr = (union tcp_md5_addr *)&ip_hdr (skb)->saddr; + } sk =sk_const_to_full_sk (sk); ao_info =rcu_dereference (tcp_sk (sk)->ao_info);
Signature · 1 line
2.43.0
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Quoted 15 lines · Hungyu Lin
tcp_ao_prepare_reset()looks up the key for a reset that is sent on behalf of a listener by the address of the peer. It takes that address from the IPv6 header whenever the listener is anAF_INET6socket, also when the segment is an IPv4 one that arrived on a dual-stack listener. The address is then read from the middle of the IPv4 header, the key of the peer is not found and the reset is not sent.The v4-mapped check that follows does not help: it looks at
sk->sk_v6_daddr, which is the unspecified address for a listener, and it runs after the address has been picked.Take the family and the address from the protocol of the segment instead of the family of the socket.
Quoted 9 lines
Fixes 06b22ef29591 ("net/tcp: Wire TCP-AO to request sockets")Signed-off-by Hungyu Lin <[email protected]>---
v2:
- Take the family fromskb->protocolonly, do not readsk->sk_family(Kuniyuki).
v1: https://lore.kernel.org/all/[email protected]/
Please reply to the netdev-bot question: how was this found, and did you trigger it at runtime or is it from code inspection only?
A follow-up for net-next adding a v4-mapped peer on a dual-stack listener case to tools/testing/selftests/net/tcp_ao/rst.c would be nice.
Thanks.
Quoted 12 lines · Hungyu Lin
tcp_ao_prepare_reset()looks up the key for a reset that is sent on behalf of a listener by the address of the peer. It takes that address from the IPv6 header whenever the listener is anAF_INET6socket, also when the segment is an IPv4 one that arrived on a dual-stack listener. The address is then read from the middle of the IPv4 header, the key of the peer is not found and the reset is not sent.The v4-mapped check that follows does not help: it looks at
sk->sk_v6_daddr, which is the unspecified address for a listener, and it runs after the address has been picked.
Quoted 6 lines
Take the family and the address from the protocol of the segment instead of the family of the socket.
Fixes 06b22ef29591 ("net/tcp: Wire TCP-AO to request sockets")Signed-off-by Hungyu Lin <[email protected]>
Thanks! IPv4 on dual-stack sockets historically got less test coverage, unfortunately. Eric's proposal to cover it with selftests in net-next would be ideal, unsure how easy it would be to add not only IPv6- and IPv4-centered tests, but also the mixed ones.
Thanks,
Dmitry