Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7227721rwn; Tue, 13 Sep 2022 16:33:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR6ELndX2QnhM8GA4rD35piFbe1ftQMAN0dRyUx/tAsdBWtYt8H+LM4T6hPQqapM02RiLXsP X-Received: by 2002:a05:6402:354c:b0:451:d47f:653 with SMTP id f12-20020a056402354c00b00451d47f0653mr10231114edd.69.1663112004219; Tue, 13 Sep 2022 16:33:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663112004; cv=none; d=google.com; s=arc-20160816; b=z+pEtoCuWFn6tVlDyu1WlwOAmRg1LK0rYX1I/JFj6ngse1MOBTX7+OFccb3pX3zhCI X45haBZOtFGOs7uNkSAEuzuD0OZCgh5N3G7BM2/JU0rxlyXjCA1aDHLe4E8o9P1cotTB PJiJSGrHzaQtqxbbrlIO73+tfILJ9aIZpO9rEh/3c5g/zJRUu5paA0K2NUg8ZORzMvs1 yvZCsmoVc08SuF+5tsGlxXHgNgzEsVS+feHJDY7cBshAZzyejbutLo8s9Y7e1AC2x+3y 3XQ7Wn8jXByZ7TFoF1PljsanVmuOGFn3o1uRMmKSIsskaxgbRkzvwcH1w5YvgAq+tNaL hykA== 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 :message-id:date:subject:to:from:dkim-signature; bh=Sth9s6jFuAgyrkcRmgl3qDDWKNFIt5yzW79ugW82O8E=; b=BO6QgB7siOVyKoFwJ9qyoj6h/CjFkCj08yWIXyFrlHmy+6i8szZzdBr3TbUkinmIAd GBDknprOBV8rvYAclYn+y6QgP6CNOBrpNXYFA+aSDt9NM8uRMH4OEpDbrkLJPHaUD47k OSei7OxG4y1cX1M7ELFyxIchJ0APUkuhkVXTLWVZr6lI9dY1IlPLKoNuBE+uYXCMcAWF SJGlp8mnCQYAaLHciQSg2Jh4pLwBrW3H9vs06LsPcZYmoxTW1ibo2MiL8tn0zN2doqoV r47SA1eKb7iUjOeV9JBmyOfZPsHBBc4l4bHpaG5P22P76PH8Zl90O02stWyG7v3EXx55 QIGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=b1TAbHUv; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g13-20020a056402090d00b0044ce972297bsi12972398edz.561.2022.09.13.16.32.50; Tue, 13 Sep 2022 16:33:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-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=@gmail.com header.s=20210112 header.b=b1TAbHUv; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229739AbiIMXcD (ORCPT + 99 others); Tue, 13 Sep 2022 19:32:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbiIMXcC (ORCPT ); Tue, 13 Sep 2022 19:32:02 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35D0171BD7 for ; Tue, 13 Sep 2022 16:32:00 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id c2so13390914plo.3 for ; Tue, 13 Sep 2022 16:32:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date; bh=Sth9s6jFuAgyrkcRmgl3qDDWKNFIt5yzW79ugW82O8E=; b=b1TAbHUvUSmMva7ETzGd/2dJOh1gjLOnBBiy53mS4RC5YIDyvk5XynEEZimYjcDQeb 5rlAQBe6s0hptP3ECuD0mJKyql7DzKq4MDut8LI20Nz2CFQXp+dH+31sOzdxOsxmtZEM O7isnHd9ZIdfPmIg3UvZgINU9PE4w9SLYu/emKrO23fNdSiSiWSSMt8OtzL6LXR/Vkd0 pWM3u4/kLdEoA/ljeFycPmD6+083QkUDHWOcamqQAAfVJeOQtgmrP2QvBSzlaF0PwvuP Sis7LvXBCpj2pa5CmKC1JXktp4bp81aKbTfpWDirz3PXQ9wIrIA/Hk25uq/CBwAWBnTB smJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=Sth9s6jFuAgyrkcRmgl3qDDWKNFIt5yzW79ugW82O8E=; b=ohFSbnAl5rkGSzSkOdLZgedQl+7cbILLZL3kzwBHvd6m14Pf2cvdUFTuoN9BghitVn wSUUgLs3Xg4uMKThPxZnT3w97WJSGqa0A5xvtM450q44JT44irgjFpBPcVUjPTltdqf4 s9dLffU/Rcgfode4EfCkkWQhCtwdkKcXKNn82Vsxnhg949hNkwwIqAQQEkjW7qQ/f+Fa YyAqdsZUxdYEF0dquIOf63wg15bDKxApfDjHcVFuDmc1sUBEuzN+nWzfqjO+lCMlKBFe 4KxNHEeB5ix3QgiKXicukaZzoP9P149JiJEVeEaas73i7H2qU3SSXMFt6fPP8cdvaG2U l2kA== X-Gm-Message-State: ACrzQf0yArHDz1yqLFWFGJZYBWwuBvY2Iekd1f8SPh20b+7c9jcERFwz 6CMw0lyTd+PbhqK5X4tfCpbbR2RyHVzS/acs X-Received: by 2002:a17:90a:8b92:b0:202:c361:9dba with SMTP id z18-20020a17090a8b9200b00202c3619dbamr1655341pjn.62.1663111918942; Tue, 13 Sep 2022 16:31:58 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id n18-20020a170903111200b00174d4fabe76sm9010599plh.214.2022.09.13.16.31.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 16:31:58 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH] Bluetooth: RFCOMM: Fix possible deadlock on socket shutdown/release Date: Tue, 13 Sep 2022 16:31:57 -0700 Message-Id: <20220913233157.526041-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz 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 --- 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)) -- 2.37.3