Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp1115377rwb; Sat, 3 Sep 2022 08:43:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ZNaHbizCowRNUSQn3tehxRkMrqnlPNFn2hYCRDvQnPp7p+yYVPzWxyZGa8tQeMIhfjJvG X-Received: by 2002:a17:907:d0b:b0:741:7ca6:a2b with SMTP id gn11-20020a1709070d0b00b007417ca60a2bmr21640924ejc.654.1662219804908; Sat, 03 Sep 2022 08:43:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662219804; cv=none; d=google.com; s=arc-20160816; b=GAY3UHv9GZU4L/1EdPaGpA/hUp0jHWkunB0+tN95UAh4EUep9yNlPjXZ9GJnlp2WYR fiNw1Mck9njBBzNK7jCXMzAT1c5IXiBn/nUAcPM07NPVyg40dGSryavZ3vc7cc4isr2W cqfT/UnWwsoV+cyfj1HhhN31GHMRCd2TdFDamdzbsiLjKjSY1zMJr4bJ4OnctZRdeSgz RvhiH+pPLhSnE8yVEVuwmb2qvJbjEeMtHFvwdXAj8ZvO8Fu32l6Y2KfTbd15ErH6YuS0 2jdWRm/Xu0y0NRzMMzm4u6b0ALLYpsOMnrNHkMhv5BGDRy6qSt+5dmv0bYTd2K2cdG+y 5GOg== 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=VhQPCvJnvEDEzph3lRyXv6SP6j/UdpbPE3lLnheeV9Q=; b=FapuDjWoufAE/3OEywFDyj3Yfm1GuRSPGzbgdvBnzvf8rpHa3CC4OUrK371RICcgW2 X+y4rvBEy729nTcGkZor/6HFWXmOvH/lGSoyiydhD7Z6qspxCwqXvYtuTCt8Zr9QexnF ghi3dDrUVPesONj0pqRlvK/5TJvpKf618Cx57eLbzKDlm5sHURfgmC0apGq9MZv+3jvh 9HNkt1DzSvavta/j0P6YwC1DmxZZc6eHMvGizYfLMR74EP+3MQmzB/PFo189VoRJYhlR m1FsHpF7qPzsTsehRlI0UbxPrDtMVnbBzRHrQjv3MOyR3xciG7cO3vyYPP5sI+dq5ng8 JIPw== 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 qa30-20020a170907869e00b00732f76a97a0si4363220ejc.0.2022.09.03.08.42.42; Sat, 03 Sep 2022 08:43: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; 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 S231134AbiICPdT (ORCPT + 99 others); Sat, 3 Sep 2022 11:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230050AbiICPdR (ORCPT ); Sat, 3 Sep 2022 11:33:17 -0400 Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 120FE5AC50 for ; Sat, 3 Sep 2022 08:33:15 -0700 (PDT) Received: from fsav111.sakura.ne.jp (fsav111.sakura.ne.jp [27.133.134.238]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 283FX3dJ008352; Sun, 4 Sep 2022 00:33:03 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav111.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav111.sakura.ne.jp); Sun, 04 Sep 2022 00:33:03 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav111.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 283FX33B008349 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Sun, 4 Sep 2022 00:33:03 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: Date: Sun, 4 Sep 2022 00:32:56 +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: [PATCH] Bluetooth: L2CAP: initialize delayed works at l2cap_chan_create() Content-Language: en-US To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz References: <0000000000007a222005e68f139f@google.com> Cc: linux-bluetooth@vger.kernel.org, syzkaller-bugs@googlegroups.com, syzbot From: Tetsuo Handa In-Reply-To: <0000000000007a222005e68f139f@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 syzbot is reporting cancel_delayed_work() without INIT_DELAYED_WORK() at l2cap_chan_del() [1], for CONF_NOT_COMPLETE flag (which meant to prevent l2cap_chan_del() from calling cancel_delayed_work()) is cleared by timer which fires before l2cap_chan_del() is called by closing file descriptor created by socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_L2CAP). l2cap_bredr_sig_cmd(L2CAP_CONF_REQ) and l2cap_bredr_sig_cmd(L2CAP_CONF_RSP) are calling l2cap_ertm_init(chan), and they call l2cap_chan_ready() (which clears CONF_NOT_COMPLETE flag) only when l2cap_ertm_init(chan) succeeded. l2cap_sock_init() does not call l2cap_ertm_init(chan), and it instead sets CONF_NOT_COMPLETE flag by calling l2cap_chan_set_defaults(). However, when connect() is requested, "command 0x0409 tx timeout" happens after 2 seconds from connect() request, and CONF_NOT_COMPLETE flag is cleared after 4 seconds from connect() request, for l2cap_conn_start() from l2cap_info_timeout() callback scheduled by schedule_delayed_work(&conn->info_timer, L2CAP_INFO_TIMEOUT); in l2cap_connect() is calling l2cap_chan_ready(). Fix this problem by initializing delayed works used by L2CAP_MODE_ERTM mode as soon as l2cap_chan_create() allocates a channel, like I did in commit be8597239379f0f5 ("Bluetooth: initialize skb_queue_head at l2cap_chan_create()"). Link: https://syzkaller.appspot.com/bug?extid=83672956c7aa6af698b3 [1] Reported-by: syzbot Signed-off-by: Tetsuo Handa --- net/bluetooth/l2cap_core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 2c9de67daadc..770891f68703 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -61,6 +61,9 @@ static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err); static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control, struct sk_buff_head *skbs, u8 event); +static void l2cap_retrans_timeout(struct work_struct *work); +static void l2cap_monitor_timeout(struct work_struct *work); +static void l2cap_ack_timeout(struct work_struct *work); static inline u8 bdaddr_type(u8 link_type, u8 bdaddr_type) { @@ -476,6 +479,9 @@ struct l2cap_chan *l2cap_chan_create(void) write_unlock(&chan_list_lock); INIT_DELAYED_WORK(&chan->chan_timer, l2cap_chan_timeout); + INIT_DELAYED_WORK(&chan->retrans_timer, l2cap_retrans_timeout); + INIT_DELAYED_WORK(&chan->monitor_timer, l2cap_monitor_timeout); + INIT_DELAYED_WORK(&chan->ack_timer, l2cap_ack_timeout); chan->state = BT_OPEN; @@ -3320,10 +3326,6 @@ int l2cap_ertm_init(struct l2cap_chan *chan) chan->rx_state = L2CAP_RX_STATE_RECV; chan->tx_state = L2CAP_TX_STATE_XMIT; - INIT_DELAYED_WORK(&chan->retrans_timer, l2cap_retrans_timeout); - INIT_DELAYED_WORK(&chan->monitor_timer, l2cap_monitor_timeout); - INIT_DELAYED_WORK(&chan->ack_timer, l2cap_ack_timeout); - skb_queue_head_init(&chan->srej_q); err = l2cap_seq_list_init(&chan->srej_list, chan->tx_win); -- 2.34.1