Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp4492843rwe; Tue, 30 Aug 2022 11:03:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR7tXJxSz0iD1emM/8HAxD2pwDToBNaS1f9DmWTfdK1FGbME3x6Dy62oNrd600hBYSIKpq/w X-Received: by 2002:a17:907:7242:b0:742:7c5:46b5 with SMTP id ds2-20020a170907724200b0074207c546b5mr3951035ejc.274.1661882636555; Tue, 30 Aug 2022 11:03:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661882636; cv=none; d=google.com; s=arc-20160816; b=oKkI74KtzbTKlSV2flgIMnzG35uQicwpG15NueoG7ELUqW/vPfFU9Ag7ih+1qoehYD EqCM3B2SiO/JuhTFVi49oJ9nciqATdSICXO/rIbzuuuzXWlXArZ7vzwgWU0XXEP6vUM1 YZUfzbZiCsqBRXJKLKtTsF/obnSyaj1E+el1llXw/z2CHomwx0btrIIgqHbBn5/ToL7m KMgCUR0aXdHGOY940M/agzhNLjAMEyyqgCrpv6Ee+0z0RAPP7bFT8ZwmnrSCfe8mh7m+ wy0bAgAblBkmpw7IQkahuz8u3wA1FJ0lmmqcu4kMW1UZPqMaQ4AXhv6KDXTK35PQfT4V 5fdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=fqPF+MWfeg/k3XnE3nr5+5+Bm3YtEGzavSRsoFVY5bU=; b=hqOBhsP8O1U2I197cWQiv3qXz0T6qpl4rSJVpxDqgbsB7bAote+Ic25AVT4mWnEr7+ /xa93/dBBVmEHX6j/bsbMm5U8R6Ho2nQXRI5D+qKCPsaFvJS6jGSqzkIxdmOg8e/ZRgG rcnxXXQjPolIUBOzm4rxpUtb8AGXKIH0duEEX5Q0UpwhwO1M9I6I0foYOWt+3Y5sLIPC MmKDcrDXStJhXG4DftyRIZ4Z7EV3nODBbVBCvrHz6ywJYBqns8NOdnqnUo+nQTiUGhqq +yfLyC74ZmWqU5rpvzDN3A35ndlOH0jG2vsTki2H+BkLT0WQMDds3LUpWxl9wixdbSZR Y4lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="JGt/Sl5K"; 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 hd30-20020a170907969e00b007317274bb0dsi7367967ejc.979.2022.08.30.11.03.29; Tue, 30 Aug 2022 11:03:56 -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="JGt/Sl5K"; 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 S231438AbiH3RpU (ORCPT + 99 others); Tue, 30 Aug 2022 13:45:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231510AbiH3Rot (ORCPT ); Tue, 30 Aug 2022 13:44:49 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9434CB2760; Tue, 30 Aug 2022 10:41:34 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id v26so6295559lfd.10; Tue, 30 Aug 2022 10:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=fqPF+MWfeg/k3XnE3nr5+5+Bm3YtEGzavSRsoFVY5bU=; b=JGt/Sl5KZiypaJtO/ZevExJngm47fE7Lp/B4DfxkKe2QnPOs5oHE+w7R9CsOAhlYBB TfyA3Md/yoShK6WcrVQd/UURiBX9kMI1AFYb0AJ2ua5hQ4JSD6EVoLlrECUv9NgMv5Xo 8sGwMvQm14FkIry4dvSfLvNeUU/cCw0oEPFnjBFCQWFXZufUD2BGfotKoOAWq1XVe6ih e6VG53UH980nqhEDJVsXWknMcFOyWzPpctD1ErQ6/mzg3LaOJRMliMLUA0m44nQmwb3M XVWvVNZ9+JQSgV/xbKvoxjpb14rdqGFET6NyMMkkc1BqR7DmefC/4SYx1yOg3SEpMNHJ VBMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=fqPF+MWfeg/k3XnE3nr5+5+Bm3YtEGzavSRsoFVY5bU=; b=5G14WZNY959ir8mPM8ZB0w7/N2FBfWrP/JP2XFp/Bfv91jg+w5g4tw9NQ8fOqP5+IE sHq4ynOFkcE1b51s5tvfNsbmDJtUW1x9pfEvYRZPWRQ5Ftsm4H228PXnOlj9n7bLCM/8 fI7kmL3QO1WY3wOsFzmOa3rLlyVNh4dYfuDgREjfpa/+V8M658G3iDmTvkFvhb2GqYGo KxNpFGM9WYDW4RdRAmvk4XwN2llNj5fJcnYCM0WAtGtGRO5BoBhPuHoGVs/hv0uU+g5P dYvsQur5/XTaf+Gh4ibL5qT2JewEAeKUhRl+erO3jt04Et5UUVDyYu3hSsS0OSk7B25z nG9w== X-Gm-Message-State: ACgBeo1Ykj4PCW95H3w2IDWMGk1mrL//4rM+liSql7pO432+FnRYVLgK 4PoJ4umbhsv/SfVonSX184YNcIOfu1NJN1G10+0= X-Received: by 2002:a05:6512:2621:b0:47f:d228:bdeb with SMTP id bt33-20020a056512262100b0047fd228bdebmr7618563lfb.121.1661881291091; Tue, 30 Aug 2022 10:41:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Luiz Augusto von Dentz Date: Tue, 30 Aug 2022 10:41:19 -0700 Message-ID: Subject: Re: possible deadlock in rfcomm_sk_state_change To: Desmond Cheong Zhi Xi Cc: Jiacheng Xu <578001344xu@gmail.com>, "linux-bluetooth@vger.kernel.org" , Jakub Kicinski , "open list:NETWORKING [GENERAL]" , Eric Dumazet , Linux Kernel Mailing List , Marcel Holtmann , Johan Hedberg , David Miller , Paolo Abeni Content-Type: text/plain; charset="UTF-8" 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 Hi Desmond, On Mon, Aug 29, 2022 at 11:48 PM Desmond Cheong Zhi Xi wrote: > > +cc Bluetooth and Networking maintainers > > Hi Jiacheng, > > On 28/8/22 04:03, Jiacheng Xu wrote: > > Hi, > > > > I believe the deadlock is more than possible but actually real. > > I got a poc that could stably trigger the deadlock. > > > > poc: https://drive.google.com/file/d/1PjqvMtHsrrGM1MIRGKl_zJGR-teAMMQy/view?usp=sharing > > > > Description/Root cause: > > In rfcomm_sock_shutdown(), lock_sock() is called when releasing and > > shutting down socket. > > However, lock_sock() has to be called once more when the sk_state is > > changed because the > > lock is not always held when rfcomm_sk_state_change() is called. One > > such call stack is: > > > > rfcomm_sock_shutdown(): > > lock_sock(); > > __rfcomm_sock_close(): > > rfcomm_dlc_close(): > > __rfcomm_dlc_close(): > > rfcomm_dlc_lock(); > > rfcomm_sk_state_change(): > > lock_sock(); > > > > Besides the recursive deadlock, there is also an > > issue of a lock hierarchy inversion between rfcomm_dlc_lock() and > > lock_sock() if the socket is locked in rfcomm_sk_state_change(). > > > Thanks for the poc and for following the trail all the way to the root > cause - this was a known issue and I didn't realize the patch wasn't > applied. > > > > Reference: > https://lore.kernel.org/all/20211004180734.434511-1-desmondcheongzx@gmail.com/ > > > > Fwiw, I tested the patch again with syzbot. It still applies cleanly to > the head of bluetooth-next and seems to address the root cause. > > Any thoughts from the maintainers on this issue and the proposed fix? We probably need to introduce a test to rfcomm-tester to reproduce this sort of problem, I also would like to avoid introducing a work just to trigger a state change since we don't have such problem on the likes of L2CAP socket so perhaps we need to rework the code a little bit to avoid the locking problems. > Best, > Desmond -- Luiz Augusto von Dentz