Skip to content

Commit c20121a

Browse files
Daniel Lezcanodavem330
authored andcommitted
[NETNS][IPV6] route6 - pass always a valid socket to ip6_dst_lookup
The ip6_dst_lookup receive a socket as parameter. In some part of the code it is called with a NULL socket parameter. We want to rely on the socket to retrieve the network namespace, so we always pass a valid socket in all cases. Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4591db4 commit c20121a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

net/ipv6/ip6_output.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ static int ip6_dst_lookup_tail(struct sock *sk,
913913
int err;
914914

915915
if (*dst == NULL)
916-
*dst = ip6_route_output(&init_net, sk, fl);
916+
*dst = ip6_route_output(sk->sk_net, sk, fl);
917917

918918
if ((err = (*dst)->error))
919919
goto out_err_release;
@@ -954,7 +954,7 @@ static int ip6_dst_lookup_tail(struct sock *sk,
954954
dst_release(*dst);
955955
memcpy(&fl_gw, fl, sizeof(struct flowi));
956956
memset(&fl_gw.fl6_dst, 0, sizeof(struct in6_addr));
957-
*dst = ip6_route_output(&init_net, sk, &fl_gw);
957+
*dst = ip6_route_output(sk->sk_net, sk, &fl_gw);
958958
if ((err = (*dst)->error))
959959
goto out_err_release;
960960
}

net/ipv6/tcp_ipv6.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,11 @@ static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb)
10711071
fl.fl_ip_sport = t1->source;
10721072
security_skb_classify_flow(skb, &fl);
10731073

1074-
/* sk = NULL, but it is safe for now. RST socket required. */
1075-
if (!ip6_dst_lookup(NULL, &buff->dst, &fl)) {
1074+
/* Pass a socket to ip6_dst_lookup either it is for RST
1075+
* Underlying function will use this to retrieve the network
1076+
* namespace
1077+
*/
1078+
if (!ip6_dst_lookup(tcp6_socket->sk, &buff->dst, &fl)) {
10761079

10771080
if (xfrm_lookup(&buff->dst, &fl, NULL, 0) >= 0) {
10781081
ip6_xmit(tcp6_socket->sk, buff, &fl, NULL, 0);
@@ -1172,7 +1175,7 @@ static void tcp_v6_send_ack(struct tcp_timewait_sock *tw,
11721175
fl.fl_ip_sport = t1->source;
11731176
security_skb_classify_flow(skb, &fl);
11741177

1175-
if (!ip6_dst_lookup(NULL, &buff->dst, &fl)) {
1178+
if (!ip6_dst_lookup(tcp6_socket->sk, &buff->dst, &fl)) {
11761179
if (xfrm_lookup(&buff->dst, &fl, NULL, 0) >= 0) {
11771180
ip6_xmit(tcp6_socket->sk, buff, &fl, NULL, 0);
11781181
TCP_INC_STATS_BH(TCP_MIB_OUTSEGS);

0 commit comments

Comments
 (0)