aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2018-10-01 18:02:26 -0400
committerDavid S. Miller <davem@davemloft.net>2018-10-01 18:42:13 -0400
commit1ad98e9d1bdf4724c0a8532fabd84bf3c457c2bc (patch)
treefe345cf7a2ca53907e70b4522ba10b00d2e721bf
parentc8424ddd9715bf1200392a677a8a0e819c99a726 (diff)
tcp/dccp: fix lockdep issue when SYN is backlogged
In normal SYN processing, packets are handled without listener lock and in RCU protected ingress path. But syzkaller is known to be able to trick us and SYN packets might be processed in process context, after being queued into socket backlog. In commit 06f877d613be ("tcp/dccp: fix other lockdep splats accessing ireq_opt") I made a very stupid fix, that happened to work mostly because of the regular path being RCU protected. Really the thing protecting ireq->ireq_opt is RCU read lock, and the pseudo request refcnt is not relevant. This patch extends what I did in commit 449809a66c1d ("tcp/dccp: block BH for SYN processing") by adding an extra rcu_read_{lock|unlock} pair in the paths that might be taken when processing SYN from socket backlog (thus possibly in process context) Fixes: 06f877d613be ("tcp/dccp: fix other lockdep splats accessing ireq_opt") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: syzbot <syzkaller@googlegroups.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/inet_sock.h3
-rw-r--r--net/dccp/input.c4
-rw-r--r--net/ipv4/tcp_input.c4
3 files changed, 7 insertions, 4 deletions
diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index e03b93360f33..a8cd5cf9ff5b 100644
--- a/include/net/inet_sock.h
+++ b/include/net/inet_sock.h
@@ -132,8 +132,7 @@ static inline int inet_request_bound_dev_if(const struct sock *sk,
132 132
133static inline struct ip_options_rcu *ireq_opt_deref(const struct inet_request_sock *ireq) 133static inline struct ip_options_rcu *ireq_opt_deref(const struct inet_request_sock *ireq)
134{ 134{
135 return rcu_dereference_check(ireq->ireq_opt, 135 return rcu_dereference(ireq->ireq_opt);
136 refcount_read(&ireq->req.rsk_refcnt) > 0);
137} 136}
138 137
139struct inet_cork { 138struct inet_cork {
diff --git a/net/dccp/input.c b/net/dccp/input.c
index d28d46bff6ab..85d6c879383d 100644
--- a/net/dccp/input.c
+++ b/net/dccp/input.c
@@ -606,11 +606,13 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
606 if (sk->sk_state == DCCP_LISTEN) { 606 if (sk->sk_state == DCCP_LISTEN) {
607 if (dh->dccph_type == DCCP_PKT_REQUEST) { 607 if (dh->dccph_type == DCCP_PKT_REQUEST) {
608 /* It is possible that we process SYN packets from backlog, 608 /* It is possible that we process SYN packets from backlog,
609 * so we need to make sure to disable BH right there. 609 * so we need to make sure to disable BH and RCU right there.
610 */ 610 */
611 rcu_read_lock();
611 local_bh_disable(); 612 local_bh_disable();
612 acceptable = inet_csk(sk)->icsk_af_ops->conn_request(sk, skb) >= 0; 613 acceptable = inet_csk(sk)->icsk_af_ops->conn_request(sk, skb) >= 0;
613 local_bh_enable(); 614 local_bh_enable();
615 rcu_read_unlock();
614 if (!acceptable) 616 if (!acceptable)
615 return 1; 617 return 1;
616 consume_skb(skb); 618 consume_skb(skb);
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 4cf2f7bb2802..47e08c1b5bc3 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -6009,11 +6009,13 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
6009 if (th->fin) 6009 if (th->fin)
6010 goto discard; 6010 goto discard;
6011 /* It is possible that we process SYN packets from backlog, 6011 /* It is possible that we process SYN packets from backlog,
6012 * so we need to make sure to disable BH right there. 6012 * so we need to make sure to disable BH and RCU right there.
6013 */ 6013 */
6014 rcu_read_lock();
6014 local_bh_disable(); 6015 local_bh_disable();
6015 acceptable = icsk->icsk_af_ops->conn_request(sk, skb) >= 0; 6016 acceptable = icsk->icsk_af_ops->conn_request(sk, skb) >= 0;
6016 local_bh_enable(); 6017 local_bh_enable();
6018 rcu_read_unlock();
6017 6019
6018 if (!acceptable) 6020 if (!acceptable)
6019 return 1; 6021 return 1;