Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2529188imu; Thu, 29 Nov 2018 06:27:43 -0800 (PST) X-Google-Smtp-Source: AFSGD/WyT483OW1B+Z+G3vuWX3RO+kMhayvVmUcro5ePcYqFhS5otjgbAwYV+4yhv7LwUlfxig/e X-Received: by 2002:a65:564b:: with SMTP id m11mr1387228pgs.216.1543501663033; Thu, 29 Nov 2018 06:27:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501662; cv=none; d=google.com; s=arc-20160816; b=VSWvqCVbrsPDoPb60z6LllpKVv1d5t7KmPTcDQ/9gsn5AxFd5b+NMnOLJIVg1sYfUx ljvuUQyecxhlS4+ePO3ayzxYWHexLHT9wGxyp5GdbOe6WXs3aeoW3GoobD/NvhPCNUtj +MOANIWVkTxAZUTAyjEeKeZiMFYUlhN3x/WpdYOBV0ku3ftZukZeS05rDCADRJSBTUah LI6CRCTX825eVEKzc4RwNa55zxDuJ/w70DapX+4XX+Bi5bYeQA4aQPaWDF4XHZM/7uVA j/e9lo8XSo5h3NYsGgKCEj6CweEoUJiPrf5T7FINwWgokBJnecCNE21/6lfUXQR//i5b ZD5Q== 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=TXyZpMAJVmbsehxAwWisbQdpFastYXnfFaBEApIy08M=; b=i6BV79Ub/U4MfvFYYoz3phqWx4BCwBgUyWm3zWWbk6JfHG15VEiRI3gg1NwlkJCSH0 pDr6qNDgr8gjF59G3uMkwyUVdIdx+JI+RduH43F1SZXnqagQPzGNd28Z2EuISPcAXRS5 gRpNdzwPOGMhZH1ZZuaQS3lp3gxoyyFoiaCFybRZMK9RNpfO3pgdRvEDGj0ZdEbneTEt pb82DxMkdvYJGAmc+9qf0qmeTD1mGMU4xeeJ+ZFjFA8IMN5q3n39EbtJZO/6xMQAjf9Y ugDVGWPH4bBCyTajmKAYzvhXY/GpwKzWdkE5sCTwoExzc8HiHkAXOCqYkR5fMtYHDyDT gLFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1Z55EPXh; 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 69si1744830pgd.290.2018.11.29.06.27.27; Thu, 29 Nov 2018 06:27:42 -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; dkim=pass header.i=@kernel.org header.s=default header.b=1Z55EPXh; 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 S1732946AbeK3Bau (ORCPT + 99 others); Thu, 29 Nov 2018 20:30:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:58104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732932AbeK3Bau (ORCPT ); Thu, 29 Nov 2018 20:30:50 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 04344213A2; Thu, 29 Nov 2018 14:25:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501518; bh=JEgnDnKFeGbOvuO36kJoGdd+DhjhK6ivSMpwMP1FBlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Z55EPXhatx5L/lFQnEx3W1vS9RWUuYuU2F3aapmWdrUxYhAgT6/FPazljfpPdZPh GfZsdsQrtdpS9wd468h24ESu/e4H9eewAEzvNRbn2sI0NktmtQZgS/zTmTmplvLnY2 rbiSuOGwmp3+jPU0QiTKTMAZ/BV3LWODF3EuKcLE= 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.14 030/100] tcp: do not release socket ownership in tcp_close() Date: Thu, 29 Nov 2018 15:12:00 +0100 Message-Id: <20181129140101.383355615@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140058.768942700@linuxfoundation.org> References: <20181129140058.768942700@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet commit 8873c064d1de579ea23412a6d3eee972593f142b upstream. syzkaller was able to hit the WARN_ON(sock_owned_by_user(sk)); in tcp_close() While a socket is being closed, it is very possible other threads find it in rtnetlink dump. tcp_get_info() will acquire the socket lock for a short amount of time (slow = lock_sock_fast(sk)/unlock_sock_fast(sk, slow);), enough to trigger the warning. Fixes: 67db3e4bfbc9 ("tcp: no longer hold ehash lock while calling tcp_get_info()") Signed-off-by: Eric Dumazet Reported-by: syzbot Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/sock.h | 1 + net/core/sock.c | 2 +- net/ipv4/tcp.c | 11 +++-------- 3 files changed, 5 insertions(+), 9 deletions(-) --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1452,6 +1452,7 @@ static inline void lock_sock(struct sock lock_sock_nested(sk, 0); } +void __release_sock(struct sock *sk); void release_sock(struct sock *sk); /* BH context may only use the following locking interface. */ --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2242,7 +2242,7 @@ static void __lock_sock(struct sock *sk) finish_wait(&sk->sk_lock.wq, &wait); } -static void __release_sock(struct sock *sk) +void __release_sock(struct sock *sk) __releases(&sk->sk_lock.slock) __acquires(&sk->sk_lock.slock) { --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2217,16 +2217,10 @@ adjudge_to_death: sock_hold(sk); sock_orphan(sk); - /* It is the last release_sock in its life. It will remove backlog. */ - release_sock(sk); - - - /* Now socket is owned by kernel and we acquire BH lock - * to finish close. No need to check for user refs. - */ local_bh_disable(); bh_lock_sock(sk); - WARN_ON(sock_owned_by_user(sk)); + /* remove backlog if any, without releasing ownership. */ + __release_sock(sk); percpu_counter_inc(sk->sk_prot->orphan_count); @@ -2295,6 +2289,7 @@ adjudge_to_death: out: bh_unlock_sock(sk); local_bh_enable(); + release_sock(sk); sock_put(sk); } EXPORT_SYMBOL(tcp_close);