tcp: fix inet6_csk_route_req() for link-local addresses
Subsystems (3)
Neal Cardwell
maintainerPATCH 1/4 tcp: fix inet6_csk_route_req() for link-local addresses
Fix inet6_csk_route_req() to use as the flowi6_oif the treq->iif, which is correctly fixed up in tcp_v6_conn_request() to handle the case of link-local addresses. This brings it in line with the tcp_v6_send_synack() code, which is already correctly using the treq->iif in this way.
--- net/ipv6/inet6_connection_sock.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net/ipv6/inet6_connection_sock.c +1 -1
@@ -68,7 +68,7 @@ struct dst_entry *inet6_csk_route_req(struct sock *sk, fl6.daddr = treq->rmt_addr; final_p =fl6_update_dst (&fl6, np->opt, &final); fl6.saddr = treq->loc_addr; - fl6.flowi6_oif = sk->sk_bound_dev_if; + fl6.flowi6_oif = treq->iif; fl6.flowi6_mark = sk->sk_mark; fl6.fl6_dport =inet_rsk (req)->rmt_port; fl6.fl6_sport =inet_rsk (req)->loc_port;
Signature · 1 line
1.7.4.1
Neal Cardwell
maintainerPATCH 2/4 tcp: pass fl6 to inet6_csk_route_req()
This commit changes inet_csk_route_req() so that it uses a pointer to a struct flowi6, rather than allocating its own on the stack. This brings its behavior in line with its IPv4 cousin, inet_csk_route_req(), and allows a follow-on patch to fix a dst leak.
--- include/net/inet6_connection_sock.h | 1 + net/ipv6/inet6_connection_sock.c | 24 ++++++++++++------------ net/ipv6/tcp_ipv6.c | 9 ++++++--- 3 files changed, 19 insertions(+), 15 deletions(-)
include/net/inet6_connection_sock.h +1 -0
@@ -26,6 +26,7 @@ extern int inet6_csk_bind_conflict(const struct sock *sk, const struct inet_bind_bucket *tb, bool relax);extern struct dst_entry *inet6_csk_route_req (struct sock *sk, +struct flowi6 *fl6,const struct request_sock *req); extern struct request_sock *inet6_csk_search_req(const struct sock *sk,
net/ipv6/inet6_connection_sock.c +13 -13
@@ -55,26 +55,26 @@ int inet6_csk_bind_conflict(const struct sock *sk,EXPORT_SYMBOL_GPL (inet6_csk_bind_conflict);struct dst_entry *inet6_csk_route_req (struct sock *sk, +struct flowi6 *fl6,const struct request_sock *req) {struct inet6_request_sock *treq =inet6_rsk (req);struct ipv6_pinfo *np =inet6_sk (sk);struct in6_addr *final_p, final;struct dst_entry *dst; -struct flowi6 fl6; - -memset (&fl6,0 ,sizeof (fl6)); - fl6.flowi6_proto =IPPROTO_TCP ; - fl6.daddr = treq->rmt_addr; - final_p =fl6_update_dst (&fl6, np->opt, &final); - fl6.saddr = treq->loc_addr; - fl6.flowi6_oif = treq->iif; - fl6.flowi6_mark = sk->sk_mark; - fl6.fl6_dport =inet_rsk (req)->rmt_port; - fl6.fl6_sport =inet_rsk (req)->loc_port; -security_req_classify_flow (req,flowi6_to_flowi (&fl6)); - dst =ip6_dst_lookup_flow (sk, &fl6, final_p, false); +memset (fl6,0 ,sizeof (*fl6)); + fl6->flowi6_proto =IPPROTO_TCP ; + fl6->daddr = treq->rmt_addr; + final_p =fl6_update_dst (fl6, np->opt, &final); + fl6->saddr = treq->loc_addr; + fl6->flowi6_oif = treq->iif; + fl6->flowi6_mark = sk->sk_mark; + fl6->fl6_dport =inet_rsk (req)->rmt_port; + fl6->fl6_sport =inet_rsk (req)->loc_port; +security_req_classify_flow (req,flowi6_to_flowi (fl6)); + + dst =ip6_dst_lookup_flow (sk, fl6, final_p, false);if (IS_ERR (dst))return NULL ;
net/ipv6/tcp_ipv6.c +6 -3
@@ -477,7 +477,8 @@ out: } -static int tcp_v6_send_synack (struct sock *sk,struct request_sock *req, +static int tcp_v6_send_synack (struct sock *sk, +struct request_sock *req,struct request_values *rvp,u16 queue_mapping) {
@@ -1058,6 +1059,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)struct tcp_sock *tp =tcp_sk (sk);__u32 isn =TCP_SKB_CB (skb)->when;struct dst_entry *dst =NULL ; +struct flowi6 fl6;bool want_cookie = false;if (skb->protocol ==htons (ETH_P_IP ))
@@ -1177,7 +1179,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)*/ if (tmp_opt.saw_tstamp && tcp_death_row.sysctl_tw_recycle && - (dst =inet6_csk_route_req (sk, req)) !=NULL && + (dst =inet6_csk_route_req (sk, &fl6, req)) !=NULL && (peer =rt6_get_peer ((struct rt6_info *)dst)) !=NULL &&ipv6_addr_equal ((struct in6_addr *)peer->daddr.addr.a6, &treq->rmt_addr)) {
@@ -1246,6 +1248,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,#ifdef CONFIG_TCP_MD5SIG struct tcp_md5sig_key *key;#endif +struct flowi6 fl6;if (skb->protocol ==htons (ETH_P_IP )) {/*
@@ -1308,7 +1311,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb, goto out_overflow;if (!dst) { - dst =inet6_csk_route_req (sk, req); + dst =inet6_csk_route_req (sk, &fl6, req);if (!dst) goto out; }
Signature · 1 line
1.7.4.1
Re: [PATCH net-next 2/4] tcp: pass fl6 to inet6_csk_route_req()
From: Neal Cardwell <[email protected]>
Date: Thu, 28 Jun 2012 15:34:19 -0700
Quoted 6 lines
This commit changes
inet_csk_route_req()so that it uses a pointer to a struct flowi6, rather than allocating its own on the stack. This brings its behavior in line with its IPv4 cousin,inet_csk_route_req(), and allows a follow-on patch to fix a dst leak.Signed-off-by Neal Cardwell <[email protected]>
Applied.
Neal Cardwell
maintainerPATCH 3/4 tcp: use inet6_csk_route_req() in tcp_v6_send_synack()
In reply to Neal CardwellWith the recent change (earlier in this patch series) to set flowi6_oif to treq->iif in inet6_csk_route_req(), the dst lookup in these two functions is now identical, so tcp_v6_send_synack() can now just call inet6_csk_route_req(), to reduce code duplication and keep things closer to the IPv4 side, which is structured this way.
--- net/ipv6/tcp_ipv6.c | 29 ++++++----------------------- 1 files changed, 6 insertions(+), 23 deletions(-)
net/ipv6/tcp_ipv6.c +6 -23
@@ -485,34 +485,17 @@ static int tcp_v6_send_synack(struct sock *sk,struct inet6_request_sock *treq =inet6_rsk (req);struct ipv6_pinfo *np =inet6_sk (sk);struct sk_buff * skb; -struct ipv6_txoptions *opt =NULL ; -struct in6_addr * final_p, final; +struct ipv6_txoptions *opt = np->opt;struct flowi6 fl6;struct dst_entry *dst; -int err; - -memset (&fl6,0 ,sizeof (fl6)); - fl6.flowi6_proto =IPPROTO_TCP ; - fl6.daddr = treq->rmt_addr; - fl6.saddr = treq->loc_addr; - fl6.flowlabel =0 ; - fl6.flowi6_oif = treq->iif; - fl6.flowi6_mark = sk->sk_mark; - fl6.fl6_dport =inet_rsk (req)->rmt_port; - fl6.fl6_sport =inet_rsk (req)->loc_port; -security_req_classify_flow (req,flowi6_to_flowi (&fl6)); - - opt = np->opt; - final_p =fl6_update_dst (&fl6, opt, &final); +int err = -ENOMEM ; - dst =ip6_dst_lookup_flow (sk, &fl6, final_p, false); -if (IS_ERR (dst)) { - err =PTR_ERR (dst); - dst =NULL ; + dst =inet6_csk_route_req (sk, &fl6, req); +if (!dst) goto done; - } + skb =tcp_make_synack (sk, dst, req, rvp); - err = -ENOMEM ; +if (skb) {__tcp_v6_send_check (skb, &treq->loc_addr, &treq->rmt_addr);
Signature · 1 line
1.7.4.1
Re: [PATCH net-next 3/4] tcp: use inet6_csk_route_req() in tcp_v6_send_synack()
From: Neal Cardwell <[email protected]>
Date: Thu, 28 Jun 2012 15:34:20 -0700
Quoted 7 lines
With the recent change (earlier in this patch series) to set
flowi6_oiftotreq->iifininet6_csk_route_req(), the dst lookup in these two functions is now identical, sotcp_v6_send_synack()can now just callinet6_csk_route_req(), to reduce code duplication and keep things closer to the IPv4 side, which is structured this way.Signed-off-by Neal Cardwell <[email protected]>
Applied.
Neal Cardwell
maintainerPATCH 4/4 tcp: plug dst leak in tcp_v6_conn_request()
In reply to Neal CardwellThe code in tcp_v6_conn_request() was implicitly assuming that tcp_v6_send_synack() would take care of dst_release(), much as tcp_v4_send_synack() already does. This resulted in tcp_v6_conn_request() leaking a dst if sysctl_tw_recycle is enabled.
This commit restructures tcp_v6_send_synack() so that it accepts a dst pointer and takes care of releasing the dst that is passed in, to plug the leak and avoid future surprises by bringing the IPv6 behavior in line with the IPv4 side.
--- net/ipv6/tcp_ipv6.c | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 deletions(-)
net/ipv6/tcp_ipv6.c +10 -9
@@ -477,7 +477,8 @@ out: } -static int tcp_v6_send_synack (struct sock *sk, +static int tcp_v6_send_synack (struct sock *sk,struct dst_entry *dst, +struct flowi6 *fl6,struct request_sock *req,struct request_values *rvp,u16 queue_mapping)
@@ -486,12 +487,10 @@ static int tcp_v6_send_synack(struct sock *sk,struct ipv6_pinfo *np =inet6_sk (sk);struct sk_buff * skb;struct ipv6_txoptions *opt = np->opt; -struct flowi6 fl6; -struct dst_entry *dst;int err = -ENOMEM ; - dst =inet6_csk_route_req (sk, &fl6, req); -if (!dst) +/* First, grab a route. */ +if (!dst && (dst =inet6_csk_route_req (sk, fl6, req)) ==NULL ) goto done; skb =tcp_make_synack (sk, dst, req, rvp);
@@ -499,9 +498,9 @@ static int tcp_v6_send_synack(struct sock *sk,if (skb) {__tcp_v6_send_check (skb, &treq->loc_addr, &treq->rmt_addr); - fl6.daddr = treq->rmt_addr; + fl6->daddr = treq->rmt_addr;skb_set_queue_mapping (skb, queue_mapping); - err =ip6_xmit (sk, skb, &fl6, opt, np->tclass); + err =ip6_xmit (sk, skb, fl6, opt, np->tclass); err =net_xmit_eval (err); }
@@ -514,8 +513,10 @@ done:static int tcp_v6_rtx_synack (struct sock *sk,struct request_sock *req,struct request_values *rvp) { +struct flowi6 fl6; +TCP_INC_STATS_BH (sock_net (sk),TCP_MIB_RETRANSSEGS ); -return tcp_v6_send_synack (sk, req, rvp,0 ); +return tcp_v6_send_synack (sk,NULL , &fl6, req, rvp,0 ); }static void tcp_v6_reqsk_destructor (struct request_sock *req)
@@ -1200,7 +1201,7 @@ have_isn:security_inet_conn_request (sk, skb, req); -if (tcp_v6_send_synack (sk, req, +if (tcp_v6_send_synack (sk, dst, &fl6, req, (struct request_values *)&tmp_ext,skb_get_queue_mapping (skb)) || want_cookie)
Signature · 1 line
1.7.4.1
Re: [PATCH net-next 4/4] tcp: plug dst leak in tcp_v6_conn_request()
From: Neal Cardwell <[email protected]>
Date: Thu, 28 Jun 2012 15:34:21 -0700
Quoted 11 lines
The code in
tcp_v6_conn_request()was implicitly assuming thattcp_v6_send_synack()would take care ofdst_release(), much astcp_v4_send_synack()already does. This resulted intcp_v6_conn_request()leaking a dst ifsysctl_tw_recycleis enabled.This commit restructures
tcp_v6_send_synack()so that it accepts a dst pointer and takes care of releasing the dst that is passed in, to plug the leak and avoid future surprises by bringing the IPv6 behavior in line with the IPv4 side.Signed-off-by Neal Cardwell <[email protected]>
Applied.
From: Neal Cardwell <[email protected]>
Date: Thu, 28 Jun 2012 15:34:18 -0700
Quoted 7 lines
Fix
inet6_csk_route_req()to use as theflowi6_oifthetreq->iif, which is correctly fixed up intcp_v6_conn_request()to handle the case of link-local addresses. This brings it in line with thetcp_v6_send_synack()code, which is already correctly using thetreq->iifin this way.Signed-off-by Neal Cardwell <[email protected]>
Applied.