From patchwork Wed Oct 19 08:26:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5062 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp248396wrs; Wed, 19 Oct 2022 03:43:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7wPwndHSxQX3k6Y3AsEbVVYbAoQunHxvxjF49k/aBjbOFZ63WmwbUg5Ux1+aXSm5EeLzhP X-Received: by 2002:a17:902:ef96:b0:17e:e7f3:31db with SMTP id iz22-20020a170902ef9600b0017ee7f331dbmr7607865plb.127.1666176192777; Wed, 19 Oct 2022 03:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666176192; cv=none; d=google.com; s=arc-20160816; b=fei4cWHGuGVpNHKp/qODvW6suujoxUZdsdSGuP5s9+OxIUnWOd/aGqB4+epDk+cmjh N7t/7YRgExJM+itn0rtInM7SCkesQodRC/S423Xl3KOrEE3rg8f2A+7YVIw+yvjb+o4u NrJf0NXZPxgNSwcC5QoSr7g2yuKN217g44HIavOW7Kkfn8gYO66seuypcfB6KVNHkh+M 5QfVztd1B/f7MghuI/EB4k2WHF6AE2SSYX9H9CClZMCZe3f7+ruxAGREYv8YlITuNqIm m8loIll9NLEXD9KXgWnW13EQ0u4gzYA49rtORUF0oU1hKlYF8j5i9S9FQ3gpzgflGWnX umhA== 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=mgEZhm7fIRqeluyZMXfyjDwTcmuXi/4aJAbkrOvP8auW9ajTJoDGJOK313Nun1mjBf hBSuYnvku7IRBI36+xInmbpQmgT+R6CjCWRoL6r+ZoRLPTLiQG0Mvlb+lKExSTMa32Ow Et+zK5sU2fNrZUnVkqrAO2kgcPzP0/+0sv4qYufzIaV5fuZyuX7ixkKedN7sHwkC93cw kWmJiBta5qwaUA/wjEJ7uQ6P47t9sfa2BKB0DkwSZCtlptvz/MmyAGk1LoPzNRMhRvCd 7v+bYE56IQOPOY2ggDitVhCMOwjL2/jur1HofqTUFzmKm71O9X6DfpAirjb1ePdJx2yv E6dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wwmUABvm; 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 s33-20020a634521000000b0046108b8e40bsi17699032pga.363.2022.10.19.03.42.58; Wed, 19 Oct 2022 03:43:12 -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=wwmUABvm; 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 S232514AbiJSKml (ORCPT + 99 others); Wed, 19 Oct 2022 06:42:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231986AbiJSKlq (ORCPT ); Wed, 19 Oct 2022 06:41:46 -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 45A5A27DEB; Wed, 19 Oct 2022 03:19:37 -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 19F4DB822E1; Wed, 19 Oct 2022 08:51:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B977C433C1; Wed, 19 Oct 2022 08:51:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169482; bh=C6CwbD+x4Djmkf1hfONC+CIP9Mm3gn2aJ3WQUw0pJs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wwmUABvmBIrj2jHgzEuKzwjTuHfGkUBB5k9K4ENhAiCc4RsTbVv10T49UqPu3Dhhh Edh6aRNYHRpj+k1C6/ZTDvKlDRCkAdfmzOK012dga7JWoIt2lEHryYPd+sgoTXGScQ hyCXYP/nCS7WgiHScdHcynufDoDELzAxwgWalUhM= 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 6.0 293/862] Bluetooth: RFCOMM: Fix possible deadlock on socket shutdown/release Date: Wed, 19 Oct 2022 10:26:20 +0200 Message-Id: <20221019083302.963385999@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747112367435768180?= X-GMAIL-MSGID: =?utf-8?q?1747112367435768180?= 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))