From patchwork Sat Oct 22 07:22:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7285 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1092268wrr; Sat, 22 Oct 2022 00:53:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM67zHwiQ3N1Q1MdIEumfoqBvobchRahgVKBshs9okAXEbP6qxxH/1Unm3sPztJBj6QC1WVa X-Received: by 2002:a17:902:ed4d:b0:183:ee9e:5578 with SMTP id y13-20020a170902ed4d00b00183ee9e5578mr22815139plb.23.1666425215677; Sat, 22 Oct 2022 00:53:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425215; cv=none; d=google.com; s=arc-20160816; b=UWbaJOP/YRRPJljQd/QWw1oqDy02GrEaYeKlXqRq2c81DTCOet9+rGxP+NnBgb5ot2 XZ2lxuboYPp+mNaRXl3VbTGt9NTb87OnLqcy6HvSXzRI6jENSrS8Pa6dRxVe6nmndVd3 q21kRygQw854qNNxeyORdYVicAagkMl+aGNCs8/5+EjKWo9P+ztNLphfcbi3EvE59AET 1f/u7b9pZo3AMMYZy/0haF3tv8WIJ4aaKvqgMlzaILqV+zwXLVYMDicIGnWM8aHXllR1 7uIVzttvedj7H72i+YhsuoQhacaWq7BVnMyJs6mHoPh4qW0gBf2Ym0VtYtFKRwnmhJml yo+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JpdVq4gNkwurGSmqYH9Aof38YZcYgwm7+YigtH/JSMI=; b=fRz//DyYnkedc3X18SNUjac3LC+Ak7H1gMyUnUOoeZWsdaWO0nnTZ+bOXHqMKCU1qy 2gIVpl0xp0NeOZ+8Vi4cvVA8E1yyZu1V4v3BqCAfb+p0SiMsbis3ef7Lhtbf8v+/qeh1 ammKwtI7sPm5H5vxrMuuvnp/j9RHFEacaU5tiNNxwVwRGkx0oor7WCAs+npJ1F/z00dE v4V+q3N+k5e07unmvJrKLEgkRvOfRH70FiOUDy3RQDaWMMeh8LK8AdSRi++q2ZVGWD4c XA6qh2xUZTxaadKRg+et91exU9cktYhSHeGGmqvQer4cnnmC0ErjFxsaSKvf2K2oBWbw SUPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gjj5a3sp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y28-20020a63495c000000b0045a73a1790asi28276265pgk.613.2022.10.22.00.53.23; Sat, 22 Oct 2022 00:53:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gjj5a3sp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231944AbiJVHxG (ORCPT + 99 others); Sat, 22 Oct 2022 03:53:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231667AbiJVHuO (ORCPT ); Sat, 22 Oct 2022 03:50:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 283C02C2AD0; Sat, 22 Oct 2022 00:46:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D178FB82E18; Sat, 22 Oct 2022 07:45:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4028BC433D6; Sat, 22 Oct 2022 07:45:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424721; bh=C6CwbD+x4Djmkf1hfONC+CIP9Mm3gn2aJ3WQUw0pJs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gjj5a3spyEsV/HXUtOe6l7DGX96lk2QvSf7B7wCR/KR1csSaIMaK5LuHGHzkAVfJ1 gGp0S4qNpyPtXD9ermSl459OvJfI10KuSA50gKx1h2Pclbpm8MOkrBaVmrE5QgnYoY p4FceeT6sU5o0AQKbStqmbiHfvLcL9ZgcLYZXOi8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 5.19 251/717] Bluetooth: RFCOMM: Fix possible deadlock on socket shutdown/release Date: Sat, 22 Oct 2022 09:22:10 +0200 Message-Id: <20221022072459.267678236@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747373487231864433?= X-GMAIL-MSGID: =?utf-8?q?1747373487231864433?= From: Luiz Augusto von Dentz [ Upstream commit 812e92b824c1db16c9519f8624d48a9901a0d38f ] Due to change to switch to use lock_sock inside rfcomm_sk_state_change the socket shutdown/release procedure can cause a deadlock: rfcomm_sock_shutdown(): lock_sock(); __rfcomm_sock_close(): rfcomm_dlc_close(): __rfcomm_dlc_close(): rfcomm_dlc_lock(); rfcomm_sk_state_change(): lock_sock(); To fix this when the call __rfcomm_sock_close is now done without holding the lock_sock since rfcomm_dlc_lock exists to protect the dlc data there is no need to use lock_sock in that code path. Link: https://lore.kernel.org/all/CAD+dNTsbuU4w+Y_P7o+VEN7BYCAbZuwZx2+tH+OTzCdcZF82YA@mail.gmail.com/ Fixes: b7ce436a5d79 ("Bluetooth: switch to lock_sock in RFCOMM") Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/rfcomm/sock.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index 4bf4ea6cbb5e..21e24da4847f 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -902,7 +902,10 @@ static int rfcomm_sock_shutdown(struct socket *sock, int how) lock_sock(sk); if (!sk->sk_shutdown) { sk->sk_shutdown = SHUTDOWN_MASK; + + release_sock(sk); __rfcomm_sock_close(sk); + lock_sock(sk); if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime && !(current->flags & PF_EXITING))