Received: by 10.223.185.116 with SMTP id b49csp1057132wrg; Fri, 23 Feb 2018 11:07:26 -0800 (PST) X-Google-Smtp-Source: AH8x226y+gnqfRID0+L91aFDTDxo1zOZfA2BxqLCjgmmsqMFSZmXwpqsXeKaH3F1bkSRxo1YNQZO X-Received: by 10.101.98.133 with SMTP id f5mr2163540pgv.357.1519412846643; Fri, 23 Feb 2018 11:07:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519412846; cv=none; d=google.com; s=arc-20160816; b=YezJimF4Uu2sjrX8mBVtdM4oOb6NJ1qMSBEjpOFzteMdFhl3IEw7hMGNUCzirgYzRO AYz2pLF7/YT1cIJ7haVS1+oQvbfAf2xdcIP8sOKiBiBZgfTyfjkMCuyYsXFusQKttVjC pgA2o5sFAsMIZ42Lmk05TOFKeUW7FWhdeAV8NLPzEFJzoGiXkvWraWIlZtb30u5SZyhi R6kgNKey8EB1gI/eX4fBIXjj9QKU8fLFFjRoede1B17eh+CoeLol3PGhirJnagvYsS4R Hjr9A3cBURMmVQJ1IdszSSvUkhGJGJqBhYFmIig503XigckYvuZtFItG+OaheBizhuMc vtGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=gNZx/VKeFMRlLrkxd6ROYuPtdRCqPk27ogQY3hxq8d8=; b=U28J2AT5I82150+lJp66En0COvAVGXJnEVPS9rKT/8+2z1AhjBsvpgIq/Vd5fCxW+f yF/kTH2DtT4qZ8bZOCRIbqJRGwg0xQxmiSQfcQTDdLJvERS/00HcNy0tXKedGT5mFsMj hEa7ECaAmQMlDneqTKaiTOABcwYStata4g7qRKBwKj5fHwgbmM39NA/8dl/+KHkg33ad ZQkztNgoDUuIkrmCxFF37VI8qyN/UnuoYdnD6rdgpJ9WYcxVYhl6z7U0to+tDpXIvvJG AZME2YmXZpTeXLPiIAvPFxHcEXKmDFj3jE61SseECS/LylFoL7DKibWxpF9j/f7v+2MG IFZQ== ARC-Authentication-Results: i=1; mx.google.com; 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 u66si1835407pgc.651.2018.02.23.11.07.11; Fri, 23 Feb 2018 11:07:26 -0800 (PST) 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; 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 S965237AbeBWTGW (ORCPT + 99 others); Fri, 23 Feb 2018 14:06:22 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50278 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965444AbeBWS5k (ORCPT ); Fri, 23 Feb 2018 13:57:40 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A28D2EBD; Fri, 23 Feb 2018 18:57:39 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Sowmini Varadhan , Santosh Shilimkar , "David S. Miller" Subject: [PATCH 4.15 20/45] rds: tcp: atomically purge entries from rds_tcp_conn_list during netns delete Date: Fri, 23 Feb 2018 19:28:59 +0100 Message-Id: <20180223170718.465791414@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170715.197760019@linuxfoundation.org> References: <20180223170715.197760019@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sowmini Varadhan commit f10b4cff98c6977668434fbf5dd58695eeca2897 upstream. The rds_tcp_kill_sock() function parses the rds_tcp_conn_list to find the rds_connection entries marked for deletion as part of the netns deletion under the protection of the rds_tcp_conn_lock. Since the rds_tcp_conn_list tracks rds_tcp_connections (which have a 1:1 mapping with rds_conn_path), multiple tc entries in the rds_tcp_conn_list will map to a single rds_connection, and will be deleted as part of the rds_conn_destroy() operation that is done outside the rds_tcp_conn_lock. The rds_tcp_conn_list traversal done under the protection of rds_tcp_conn_lock should not leave any doomed tc entries in the list after the rds_tcp_conn_lock is released, else another concurrently executiong netns delete (for a differnt netns) thread may trip on these entries. Reported-by: syzbot Signed-off-by: Sowmini Varadhan Acked-by: Santosh Shilimkar Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/rds/tcp.c | 9 +++++++-- net/rds/tcp.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) --- a/net/rds/tcp.c +++ b/net/rds/tcp.c @@ -307,7 +307,8 @@ static void rds_tcp_conn_free(void *arg) rdsdebug("freeing tc %p\n", tc); spin_lock_irqsave(&rds_tcp_conn_lock, flags); - list_del(&tc->t_tcp_node); + if (!tc->t_tcp_node_detached) + list_del(&tc->t_tcp_node); spin_unlock_irqrestore(&rds_tcp_conn_lock, flags); kmem_cache_free(rds_tcp_conn_slab, tc); @@ -532,8 +533,12 @@ static void rds_tcp_kill_sock(struct net if (net != c_net || !tc->t_sock) continue; - if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn)) + if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn)) { list_move_tail(&tc->t_tcp_node, &tmp_list); + } else { + list_del(&tc->t_tcp_node); + tc->t_tcp_node_detached = true; + } } spin_unlock_irq(&rds_tcp_conn_lock); list_for_each_entry_safe(tc, _tc, &tmp_list, t_tcp_node) { --- a/net/rds/tcp.h +++ b/net/rds/tcp.h @@ -12,6 +12,7 @@ struct rds_tcp_incoming { struct rds_tcp_connection { struct list_head t_tcp_node; + bool t_tcp_node_detached; struct rds_conn_path *t_cpath; /* t_conn_path_lock synchronizes the connection establishment between * rds_tcp_accept_one and rds_tcp_conn_path_connect