Skip to content

Commit 2ab2ddd

Browse files
edumazetdavem330
authored andcommitted
inet: make sure to grab rcu_read_lock before using ireq->ireq_opt
Timer handlers do not imply rcu_read_lock(), so my recent fix triggered a LOCKDEP warning when SYNACK is retransmit. Lets add rcu_read_lock()/rcu_read_unlock() pairs around ireq->ireq_opt usages instead of guessing what is done by callers, since it is not worth the pain. Get rid of ireq_opt_deref() helper since it hides the logic without real benefit, since it is now a standard rcu_dereference(). Fixes: 1ad98e9 ("tcp/dccp: fix lockdep issue when SYN is backlogged") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ff58e2d commit 2ab2ddd

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎include/net/inet_sock.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ static inline int inet_request_bound_dev_if(const struct sock *sk,
130130
return sk->sk_bound_dev_if;
131131
}
132132

133-
static inline struct ip_options_rcu *ireq_opt_deref(const struct inet_request_sock *ireq)
134-
{
135-
return rcu_dereference(ireq->ireq_opt);
136-
}
137-
138133
struct inet_cork {
139134
unsigned int flags;
140135
__be32 addr;

‎net/dccp/ipv4.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,11 @@ static int dccp_v4_send_response(const struct sock *sk, struct request_sock *req
493493

494494
dh->dccph_checksum = dccp_v4_csum_finish(skb, ireq->ir_loc_addr,
495495
ireq->ir_rmt_addr);
496+
rcu_read_lock();
496497
err = ip_build_and_send_pkt(skb, sk, ireq->ir_loc_addr,
497498
ireq->ir_rmt_addr,
498-
ireq_opt_deref(ireq));
499+
rcu_dereference(ireq->ireq_opt));
500+
rcu_read_unlock();
499501
err = net_xmit_eval(err);
500502
}
501503

‎net/ipv4/inet_connection_sock.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ struct dst_entry *inet_csk_route_req(const struct sock *sk,
544544
struct ip_options_rcu *opt;
545545
struct rtable *rt;
546546

547-
opt = ireq_opt_deref(ireq);
547+
rcu_read_lock();
548+
opt = rcu_dereference(ireq->ireq_opt);
548549

549550
flowi4_init_output(fl4, ireq->ir_iif, ireq->ir_mark,
550551
RT_CONN_FLAGS(sk), RT_SCOPE_UNIVERSE,
@@ -558,11 +559,13 @@ struct dst_entry *inet_csk_route_req(const struct sock *sk,
558559
goto no_route;
559560
if (opt && opt->opt.is_strictroute && rt->rt_uses_gateway)
560561
goto route_err;
562+
rcu_read_unlock();
561563
return &rt->dst;
562564

563565
route_err:
564566
ip_rt_put(rt);
565567
no_route:
568+
rcu_read_unlock();
566569
__IP_INC_STATS(net, IPSTATS_MIB_OUTNOROUTES);
567570
return NULL;
568571
}

‎net/ipv4/tcp_ipv4.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,9 +943,11 @@ static int tcp_v4_send_synack(const struct sock *sk, struct dst_entry *dst,
943943
if (skb) {
944944
__tcp_v4_send_check(skb, ireq->ir_loc_addr, ireq->ir_rmt_addr);
945945

946+
rcu_read_lock();
946947
err = ip_build_and_send_pkt(skb, sk, ireq->ir_loc_addr,
947948
ireq->ir_rmt_addr,
948-
ireq_opt_deref(ireq));
949+
rcu_dereference(ireq->ireq_opt));
950+
rcu_read_unlock();
949951
err = net_xmit_eval(err);
950952
}
951953

0 commit comments

Comments
 (0)