Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5452580imm; Tue, 16 Oct 2018 10:26:08 -0700 (PDT) X-Google-Smtp-Source: ACcGV60+UM2e9oRqOcBY24RCGHVxvZ2uif0qw0ONubgpbrtBDpjx96O6o9oodq0Lgwzq3O0rHTLG X-Received: by 2002:a62:1c06:: with SMTP id c6-v6mr23263440pfc.41.1539710768021; Tue, 16 Oct 2018 10:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539710767; cv=none; d=google.com; s=arc-20160816; b=yfgi0ZkQpKpft4RNXPSmbDt8gh5BCpbB1Rt1XxgyNAhseGt0skbumLSQIRUzxgU5p4 XxebkAUeRGLbrkvItIBqaYZQBH7mLUfXuGQNLWpuC1fRGxmZ4zEquZj+njdc+NBZu59e IqKFmro61QrkaKn32QG3b/zrZbNn+QdHTHX7/gXHzniZ2AyIUGVbY1b0i8UWbXy15b50 6oBwuDJw/RLtHsvWHrb3k7gjSKJdwgTMQGquJ8RV/FrrXKEUu56bE8V8qh7cK2TAMyCQ uoEoO+09xnXPLAs2+xWuCUvDn0KeWu9Cx78L8SRKzTBOjDUzBl493HXWwtfqEEWOO6o3 mdNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7X6i/Dh3V3pNOQtCmEIARitp+SfvIA5V/Ub7/z9s5Gg=; b=UAY/yWlnl5fsDe4XkrkXK8NJygrkxonNnI74RYdhtDc+V40xJPxtxKAWrzMQTMS6sH TN5FhPcGf/4nMt4h2jEdmmvTVf9KpBk7XY8vhIAb0StXJ1+a8S0AaciXrtUyNLfa4L5w c0ReOL0uTe+Wg8JEvWrBwsOUKle22g5GVz2vnrfUqNEz5G7FKfE7FIM6/aUCKj91Jy6s QEbh0OMxJNA3IR+8BGEUF7Wb1zjLjDUyXuqM85VAWgTD02HhVHNTa6mDcqflOCVrHJGc W6Pyv5rnLLSWjb6UhHcNWWzpzR72JWikUITlrEyRShrSa6EGwYvEHo+igDttMYbghmI7 u4Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Xez4IxU6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z68-v6si15909488pfb.280.2018.10.16.10.25.52; Tue, 16 Oct 2018 10:26:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Xez4IxU6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731621AbeJQBPl (ORCPT + 99 others); Tue, 16 Oct 2018 21:15:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:34306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730396AbeJQBPk (ORCPT ); Tue, 16 Oct 2018 21:15:40 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9CBE820866; Tue, 16 Oct 2018 17:24:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539710654; bh=Kyh2juH6oCMOnimIbhG+Bbfw2sQrFN8mhDFTP44IVOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xez4IxU6DbT7OZy6Vz5XH9m+AmTpHPTjbVRfTrzGTIM3MO60vCr3/B6KZMoxIYLJj zGZOquA1k3MNIHmqYbaeZ8lrDnnILSY+Bd/isi2s+uAPN9CVtZUT/o7JZVIinIt/EP chEv2HJrMPRm+K0MyXUvCiUy6isuA6UirQ5Xvidc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , "David S. Miller" Subject: [PATCH 4.9 41/71] tcp/dccp: fix lockdep issue when SYN is backlogged Date: Tue, 16 Oct 2018 19:09:38 +0200 Message-Id: <20181016170541.435801460@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181016170539.315587743@linuxfoundation.org> References: <20181016170539.315587743@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 1ad98e9d1bdf4724c0a8532fabd84bf3c457c2bc ] 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 Reported-by: syzbot Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/inet_sock.h | 3 +-- net/dccp/input.c | 4 +++- net/ipv4/tcp_input.c | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -134,8 +134,7 @@ static inline int inet_request_bound_dev static inline struct ip_options_rcu *ireq_opt_deref(const struct inet_request_sock *ireq) { - return rcu_dereference_check(ireq->ireq_opt, - atomic_read(&ireq->req.rsk_refcnt) > 0); + return rcu_dereference(ireq->ireq_opt); } struct inet_cork { --- a/net/dccp/input.c +++ b/net/dccp/input.c @@ -605,11 +605,13 @@ int dccp_rcv_state_process(struct sock * 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); --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -5978,11 +5978,13 @@ int tcp_rcv_state_process(struct sock *s 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;