All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] tcp/dccp: fix lockdep issue when SYN is backlogged
@ 2018-10-01 22:02 Eric Dumazet
  2018-10-01 22:43 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2018-10-01 22:02 UTC (permalink / raw)
  To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet

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>
---
 include/net/inet_sock.h | 3 +--
 net/dccp/input.c        | 4 +++-
 net/ipv4/tcp_input.c    | 4 +++-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
index e03b93360f332b3e3232873ac1cbd0ee7478fabb..a8cd5cf9ff5b6ddc50bd2e70d3f9103afa32a3b5 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,
 
 static inline struct ip_options_rcu *ireq_opt_deref(const struct inet_request_sock *ireq)
 {
-	return rcu_dereference_check(ireq->ireq_opt,
-				     refcount_read(&ireq->req.rsk_refcnt) > 0);
+	return rcu_dereference(ireq->ireq_opt);
 }
 
 struct inet_cork {
diff --git a/net/dccp/input.c b/net/dccp/input.c
index d28d46bff6ab43441f34284ec975c1e052a774d0..85d6c879383da8994c6b20cd1e49e0f667a07482 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,
 	if (sk->sk_state == DCCP_LISTEN) {
 		if (dh->dccph_type == DCCP_PKT_REQUEST) {
 			/* It is possible that we process SYN packets from backlog,
-			 * so we need to make sure to disable BH right there.
+			 * so we need to make sure to disable BH and RCU right there.
 			 */
+			rcu_read_lock();
 			local_bh_disable();
 			acceptable = inet_csk(sk)->icsk_af_ops->conn_request(sk, skb) >= 0;
 			local_bh_enable();
+			rcu_read_unlock();
 			if (!acceptable)
 				return 1;
 			consume_skb(skb);
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 4cf2f7bb2802ad4ae968b5a6dfb9d005ed619c76..47e08c1b5bc3e14e6ae2851b7ec8de91a3eb4a35 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)
 			if (th->fin)
 				goto discard;
 			/* It is possible that we process SYN packets from backlog,
-			 * so we need to make sure to disable BH right there.
+			 * so we need to make sure to disable BH and RCU right there.
 			 */
+			rcu_read_lock();
 			local_bh_disable();
 			acceptable = icsk->icsk_af_ops->conn_request(sk, skb) >= 0;
 			local_bh_enable();
+			rcu_read_unlock();
 
 			if (!acceptable)
 				return 1;
-- 
2.19.0.605.g01d371f741-goog

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] tcp/dccp: fix lockdep issue when SYN is backlogged
  2018-10-01 22:02 [PATCH net] tcp/dccp: fix lockdep issue when SYN is backlogged Eric Dumazet
@ 2018-10-01 22:43 ` David Miller
  2018-10-02 18:25   ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2018-10-01 22:43 UTC (permalink / raw)
  To: edumazet; +Cc: netdev, eric.dumazet

From: Eric Dumazet <edumazet@google.com>
Date: Mon,  1 Oct 2018 15:02:26 -0700

> 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>

Applied and queued up for -stable, thanks Eric.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] tcp/dccp: fix lockdep issue when SYN is backlogged
  2018-10-01 22:43 ` David Miller
@ 2018-10-02 18:25   ` Eric Dumazet
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2018-10-02 18:25 UTC (permalink / raw)
  To: David Miller, edumazet; +Cc: netdev, eric.dumazet



On 10/01/2018 03:43 PM, David Miller wrote:
> From: Eric Dumazet <edumazet@google.com>
> Date: Mon,  1 Oct 2018 15:02:26 -0700

>> 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>
> 
> Applied and queued up for -stable, thanks Eric.
> 

This needs a followup, timers do not imply rcu_read_lock() :/

I will send a patch, sorry for not having caught this earlier.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-10-03  1:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-01 22:02 [PATCH net] tcp/dccp: fix lockdep issue when SYN is backlogged Eric Dumazet
2018-10-01 22:43 ` David Miller
2018-10-02 18:25   ` Eric Dumazet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.