Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp3079978rwn; Sat, 10 Sep 2022 04:58:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR5oWCGJURRJDS5gYPCOkuTUGZiCfp0eJgQ+Ymf5MtufywS2TBqfuxpieMhftEayaPzY3zMs X-Received: by 2002:a17:906:9fc1:b0:761:9192:504f with SMTP id hj1-20020a1709069fc100b007619192504fmr12813180ejc.116.1662811124890; Sat, 10 Sep 2022 04:58:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662811124; cv=none; d=google.com; s=arc-20160816; b=zf96YU2S5jd3yoZdSX8wkuQ3tIdnSjU09e1MspWeaEE50YhlJeQSGeUMRP33lH2Aev rteVrK/bCafZviRHDj275/p4EQPre8V/Y5XaIMDuDPz+27JVXbtp/qri82hJ1DA7RZt/ HtPQTpohSGKwX3URSkjBCXky7RigiiVjUwIq9xk9iWWcF+KAp9iWPZeaEd0luKcz36Ch XIkO5XZckGWc81Lu8rB2FELpoxKDklzBuHB5LMD18wz3arL42dDbKwwDEXbIWh8Zk1y1 IOwL2zlfkkkbihiVD0KalX3vGWfRGX2BapkGsbPcR+hbEJLT90XF4jls4HQOFeTodDnV 9N6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from:cc :references:to:content-language:subject:user-agent:mime-version:date :message-id; bh=YRvoUzxUDYW/71MHTycvvs+ZcWfIcJF8PWgDkZjdqA4=; b=dNqwIh4xTzGD7TAKZVVPxJ2zxUZ3ImW1jvdm9HUiXhCGUc60wEhMjV1QcCjee/drOF vOh1CGLWWm6PE6NygP0r9PVnUfo5K8ArnLJzbhy6OEiuNSIr5C88+7DjoWM44NcF47m8 Tbl4SgSH1DwLTWXeI3zTfPm1HI0uMTYnTRvVKuuyLkOY6uZ6EbIl8eskxWgtgbU8RKpX IX9Gf/OxNX3RLgAraqse4yMRGsbDQ/tXkdRDc3eyALNkH8q3QlYISQFzjEZC71cFRV0M Bwf59ZmsKnESIwroctz2ljHx5SSJb/R3ZxQCHeuYZxLkeX8VdjQy/IDNAX000afks3LA tOcw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s5-20020a50ab05000000b00447b4d113a8si2525865edc.421.2022.09.10.04.57.58; Sat, 10 Sep 2022 04:58:44 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229535AbiIJLSk (ORCPT + 99 others); Sat, 10 Sep 2022 07:18:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229488AbiIJLSh (ORCPT ); Sat, 10 Sep 2022 07:18:37 -0400 Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B49E718364; Sat, 10 Sep 2022 04:18:35 -0700 (PDT) Received: from fsav115.sakura.ne.jp (fsav115.sakura.ne.jp [27.133.134.242]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 28ABINqv016377; Sat, 10 Sep 2022 20:18:23 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav115.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav115.sakura.ne.jp); Sat, 10 Sep 2022 20:18:23 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav115.sakura.ne.jp) Received: from [192.168.1.9] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 28ABIM1R016371 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Sat, 10 Sep 2022 20:18:23 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: Date: Sat, 10 Sep 2022 20:18:22 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [syzbot] WARNING: ODEBUG bug in mgmt_index_removed Content-Language: en-US To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz References: <000000000000532e0e05e826413c@google.com> Cc: syzbot , linux-bluetooth@vger.kernel.org, syzkaller-bugs@googlegroups.com From: Tetsuo Handa In-Reply-To: <000000000000532e0e05e826413c@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_NONE,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 I guess that, since hci_pi(sk)->hdev = hdev in hci_sock_bind() does not check whether a hdev is already associated with some sk, it is possible that multiple sk are bound to the same hdev. As a result, lock_sock(sk) is not sufficient for serializing access to hdev, and hci_dev_lock(hdev) is needed when calling mgmt_index_*(hdev) functions. If my guess above is correct, I think that what syzbot is telling us is that, due to lack of serialization via hci_dev_lock(hdev), setting of HCI_MGMT flag from mgmt_init_hdev() from hci_mgmt_cmd() from hci_sock_sendmsg() is racing with testing of HCI_MGMT flag from mgmt_index_removed() from hci_sock_bind(). I suggest you to explicitly use lockdep_assert_held() in Bluethooth code for clarifying what locks need to be held, instead of continue using racy operations like hci_dev_test_and_set_flag() without holding appropriate locks. hci_unregister_dev() { if (!test_bit(HCI_INIT, &hdev->flags) && !hci_dev_test_flag(hdev, HCI_SETUP) && !hci_dev_test_flag(hdev, HCI_CONFIG)) { hci_dev_lock(hdev); mgmt_index_removed(hdev) { if (!hci_dev_test_flag(hdev, HCI_MGMT)) return; cancel_delayed_work_sync(&hdev->discov_off); } hci_dev_unlock(hdev); } } hci_sock_sendmsg() { lock_sock(sk); mutex_lock(&mgmt_chan_list_lock); chan = __hci_mgmt_chan_find(hci_pi(sk)->channel); if (chan) err = hci_mgmt_cmd(chan, sk, skb) { if (hdev && chan->hdev_init) // chan->hdev_init == mgmt_init_hdev chan->hdev_init(sk, hdev) { if (hci_dev_test_and_set_flag(hdev, HCI_MGMT)) // Missing hci_dev_lock(hdev) return; INIT_DELAYED_WORK(&hdev->discov_off, discov_off); } err = handler->func(sk, hdev, cp, len) { // handler->func() == set_external_config or set_public_address hci_dev_lock(hdev); mgmt_index_removed(hdev) { if (!hci_dev_test_flag(hdev, HCI_MGMT)) return; cancel_delayed_work_sync(&hdev->discov_off); } hci_dev_unlock(hdev); } } else err = -EINVAL; mutex_unlock(&mgmt_chan_list_lock); release_sock(sk); } hci_sock_bind() { lock_sock(sk); mgmt_index_removed(hdev) { if (!hci_dev_test_flag(hdev, HCI_MGMT)) // Missing hci_dev_lock(hdev) return; cancel_delayed_work_sync(&hdev->discov_off); // ODEBUG complains missing INIT_DELAYED_WORK() } release_sock(sk); }