tcp: take care of SYN_RECV sockets in tcp_v4_send_ack() and tcp_v6_send_response()
Subsystems (3)
PATCH 1/1 tcp: take care of SYN_RECV sockets in tcp_v4_send_ack() and tcp_v6_send_response()
TCP can send ACK packets on behalf of SYN_RECV sockets.
tcp_v4_send_ack() and tcp_v6_send_response() incorrectly dereference sk->sk_mark for non TIME_WAIT sockets.
This field is not defined for SYN_RECV sockets.
Using sk_to_full_sk() should get back to the listener socket.
Note that this also provides a socket pointer to sock_net_uid() calls.
--- net/ipv4/tcp_ipv4.c | 6 ++++-- net/ipv6/tcp_ipv6.c | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
net/ipv4/tcp_ipv4.c +4 -2
@@ -856,12 +856,14 @@ static void tcp_v4_send_ack(const struct sock *sk,if (oif) arg.bound_dev_if = oif; arg.tos = tos; - arg.uid =sock_net_uid (net,sk_fullsock (sk) ? sk :NULL );local_bh_disable (); ctl_sk =this_cpu_read (*net->ipv4.tcp_sk); -if (sk) +if (sk) { + sk =sk_to_full_sk (sk); ctl_sk->sk_mark = (sk->sk_state ==TCP_TIME_WAIT ) ?inet_twsk (sk)->tw_mark : sk->sk_mark; + } + arg.uid =sock_net_uid (net,sk_fullsock (sk) ? sk :NULL ); ip_send_unicast_reply(ctl_sk, skb, &TCP_SKB_CB(skb)->header.h4.opt, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,
net/ipv6/tcp_ipv6.c +1 -0
@@ -884,6 +884,7 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32 }if (sk) { + sk =sk_to_full_sk (sk);if (sk->sk_state ==TCP_TIME_WAIT ) { mark =inet_twsk (sk)->tw_mark;/* autoflowlabel relies on buff->hash */
Signature · 1 line
2.22.0.rc2.383.gf4fbbf30c2-goog
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Mon, 10 Jun 2019 14:45:43 -0700
Quoted 1 line
Using
sk_to_full_sk()should get back to the listener socket.
net/ipv6/tcp_ipv6.c: In function ‘tcp_v6_send_response’:net/ipv6/tcp_ipv6.c:887:22: warning: passing argument 1 of ‘sk_to_full_sk’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
Quoted 8 lines · David Miller
From: Eric Dumazet <[email protected]>
Date: Mon, 10 Jun 2019 14:45:43 -0700Quoted 1 line
Using
sk_to_full_sk()should get back to the listener socket.
net/ipv6/tcp_ipv6.c: In function ‘tcp_v6_send_response’:net/ipv6/tcp_ipv6.c:887:22: warning: passing argument 1 of ‘sk_to_full_sk’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
I was about to ask you to drop this patch.
Apparently the only case we can have SYN_RECV sockets here are for fastopen, and in this case sk->sk_mark defined.
This only leaves the chance to get better sock_net_uid() reach, and my upcoming patch adding per-tcp-socket arbitrary tx delay.
Thanks for fixing that Eric.
Quoted 56 lines · Eric Dumazet
TCP can send ACK packets on behalf of
SYN_RECVsockets.
tcp_v4_send_ack()andtcp_v6_send_response()incorrectly dereferencesk->sk_markfor nonTIME_WAITsockets.This field is not defined for
SYN_RECVsockets.Using
sk_to_full_sk()should get back to the listener socket.Note that this also provides a socket pointer to
sock_net_uid()calls.Fixes 00483690552c ("tcp: Add mark for TIMEWAIT sockets")Signed-off-by Eric Dumazet <[email protected]>Cc Jon Maxwell <[email protected]>--- net/ipv4/tcp_ipv4.c | 6 ++++-- net/ipv6/tcp_ipv6.c | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)net/ipv4/tcp_ipv4.c +4
-2@@ -856,12 +856,14 @@ static void tcp_v4_send_ack(const struct sock *sk,if (oif) arg.bound_dev_if = oif; arg.tos = tos; - arg.uid =sock_net_uid (net,sk_fullsock (sk) ? sk :NULL );local_bh_disable (); ctl_sk =this_cpu_read (*net->ipv4.tcp_sk); -if (sk) +if (sk) { + sk =sk_to_full_sk (sk); ctl_sk->sk_mark = (sk->sk_state ==TCP_TIME_WAIT ) ?inet_twsk (sk)->tw_mark : sk->sk_mark; + } + arg.uid =sock_net_uid (net,sk_fullsock (sk) ? sk :NULL ); ip_send_unicast_reply(ctl_sk, skb, &TCP_SKB_CB(skb)->header.h4.opt, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,net/ipv6/tcp_ipv6.c +1
-1@@ -884,6 +884,7 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32 }if (sk) { + sk =sk_to_full_sk (sk);if (sk->sk_state ==TCP_TIME_WAIT ) { mark =inet_twsk (sk)->tw_mark;/* autoflowlabel relies on buff->hash */ --2.22.0.rc2.383.gf4fbbf30c2-goog
Quoted 2 lines · Jonathan Maxwell
Thanks for fixing that Eric.
Hi Jonathan.
There is no bug actually, at least not on sk->sk_mark part.
I will send a simpler patch so that sock_net_uid() correctly fetches sk->sk_uid for FASTOPEN socket.
Thanks !
Quoted 58 lines · Eric Dumazet
Quoted 56 lines
TCP can send ACK packets on behalf of
SYN_RECVsockets.
tcp_v4_send_ack()andtcp_v6_send_response()incorrectly dereferencesk->sk_markfor nonTIME_WAITsockets.This field is not defined for
SYN_RECVsockets.Using
sk_to_full_sk()should get back to the listener socket.Note that this also provides a socket pointer to
sock_net_uid()calls.Fixes 00483690552c ("tcp: Add mark for TIMEWAIT sockets")Signed-off-by Eric Dumazet <[email protected]>Cc Jon Maxwell <[email protected]>--- net/ipv4/tcp_ipv4.c | 6 ++++-- net/ipv6/tcp_ipv6.c | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)net/ipv4/tcp_ipv4.c +4
-2@@ -856,12 +856,14 @@ static void tcp_v4_send_ack(const struct sock *sk,if (oif) arg.bound_dev_if = oif; arg.tos = tos; - arg.uid =sock_net_uid (net,sk_fullsock (sk) ? sk :NULL );local_bh_disable (); ctl_sk =this_cpu_read (*net->ipv4.tcp_sk); -if (sk) +if (sk) { + sk =sk_to_full_sk (sk); ctl_sk->sk_mark = (sk->sk_state ==TCP_TIME_WAIT ) ?inet_twsk (sk)->tw_mark : sk->sk_mark; + } + arg.uid =sock_net_uid (net,sk_fullsock (sk) ? sk :NULL ); ip_send_unicast_reply(ctl_sk, skb, &TCP_SKB_CB(skb)->header.h4.opt, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,net/ipv6/tcp_ipv6.c +1
-1@@ -884,6 +884,7 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32 }if (sk) { + sk =sk_to_full_sk (sk);if (sk->sk_state ==TCP_TIME_WAIT ) { mark =inet_twsk (sk)->tw_mark;/* autoflowlabel relies on buff->hash */ --2.22.0.rc2.383.gf4fbbf30c2-goog
Sounds good Eric. Thanks
Quoted 74 lines · Eric Dumazet
Quoted 2 lines · Jonathan Maxwell
Thanks for fixing that Eric.
Hi Jonathan.
There is no bug actually, at least not on
sk->sk_markpart.I will send a simpler patch so that
sock_net_uid()correctly fetchessk->sk_uidfor FASTOPEN socket.Thanks !
Quoted 58 lines · Eric Dumazet
Quoted 56 lines
TCP can send ACK packets on behalf of
SYN_RECVsockets.
tcp_v4_send_ack()andtcp_v6_send_response()incorrectly dereferencesk->sk_markfor nonTIME_WAITsockets.This field is not defined for
SYN_RECVsockets.Using
sk_to_full_sk()should get back to the listener socket.Note that this also provides a socket pointer to
sock_net_uid()calls.Fixes 00483690552c ("tcp: Add mark for TIMEWAIT sockets")Signed-off-by Eric Dumazet <[email protected]>Cc Jon Maxwell <[email protected]>--- net/ipv4/tcp_ipv4.c | 6 ++++-- net/ipv6/tcp_ipv6.c | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)net/ipv4/tcp_ipv4.c +4
-2@@ -856,12 +856,14 @@ static void tcp_v4_send_ack(const struct sock *sk,if (oif) arg.bound_dev_if = oif; arg.tos = tos; - arg.uid =sock_net_uid (net,sk_fullsock (sk) ? sk :NULL );local_bh_disable (); ctl_sk =this_cpu_read (*net->ipv4.tcp_sk); -if (sk) +if (sk) { + sk =sk_to_full_sk (sk); ctl_sk->sk_mark = (sk->sk_state ==TCP_TIME_WAIT ) ?inet_twsk (sk)->tw_mark : sk->sk_mark; + } + arg.uid =sock_net_uid (net,sk_fullsock (sk) ? sk :NULL ); ip_send_unicast_reply(ctl_sk, skb, &TCP_SKB_CB(skb)->header.h4.opt, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr,net/ipv6/tcp_ipv6.c +1
-1@@ -884,6 +884,7 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32 }if (sk) { + sk =sk_to_full_sk (sk);if (sk->sk_state ==TCP_TIME_WAIT ) { mark =inet_twsk (sk)->tw_mark;/* autoflowlabel relies on buff->hash */ --2.22.0.rc2.383.gf4fbbf30c2-goog