Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6819601rwi; Mon, 24 Oct 2022 06:32:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6JDlRytS9VpXZnqzUPDDDcYD4uKpHOrkO608vS3f97ltOubehegirZPuGUXxK5/fq5uaGa X-Received: by 2002:a17:90b:180f:b0:20d:4e7f:5f52 with SMTP id lw15-20020a17090b180f00b0020d4e7f5f52mr75546819pjb.119.1666618368593; Mon, 24 Oct 2022 06:32:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618368; cv=none; d=google.com; s=arc-20160816; b=0WDh33/qKAme6WLevy3IKbY+COCtXXxn8JXacPag7u1M7SWmwVE/+VEDoWED0NfqcM /PJsgY2OjhHvnhPUaBkr8fzcZfWcUrM/6GTUhlC0i/JusTy3o7A6Vwzp+OrfUjsId4mL 5b+271ivhs4AhjzjM4n/136Ha5xWEp6uE44ZWV6ljieyB9kZptDPi7pcj2/AL1M0qqFl s7czgwSWF3WFip1k0Q8EEXoe/KndqvIode4q2htVjEjm0fAzHUOV4e8q7hZ2HleFxYUu +D9FUtzhqIpfjvpvtIpjNYLWIe1QoEVtRK9cHI+4OmI+jcC4sLoPXOY2YyhGsVw6vEBf /zrw== 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=GlfaECGuFhxs+Ynrsri76Cy74YuI/WNYA/brMj6NgKI=; b=xdKpyQe7WU2YTYXt+DlM8jvfSkffTj9/AjcZ75izqVn8zqNOitIJMbCQoJyz3xwjya 3Yg3UFWOi1wpl5YmtmYgYZJOvcOamilxaj+pZQCwRS0H4FJG3iplflOg9gLtwAdmbSFF tYnApS5Sdi91WKGptoP1enHAsFpnceSUXEGt9wla17Cogju5nsJjmlXesB0EL2Vb3TyT /r79lJZlgnUVpZHOh+T6e8rpVfnmly3H52Enbe9w/dAgzAyMAFF5p5LKA2gdkpHiQ1vV SSTFKINpS/enTp2nLY6w3tZmQadKXAuP1XhtK4z6I3lLKSBPiCYHBhIqLu+gR7LM2azk fLpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F8rdWeWW; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ij11-20020a170902ab4b00b00186698255a3si13279121plb.607.2022.10.24.06.32.36; Mon, 24 Oct 2022 06:32:48 -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=F8rdWeWW; 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 S232239AbiJXNDO (ORCPT + 99 others); Mon, 24 Oct 2022 09:03:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235244AbiJXM7o (ORCPT ); Mon, 24 Oct 2022 08:59:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE669AC3B; Mon, 24 Oct 2022 05:19:07 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 25C6761257; Mon, 24 Oct 2022 12:04:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38DE7C433C1; Mon, 24 Oct 2022 12:04:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613061; bh=rNP+Al6u5YeMGaU/bAoWFB6k46B24myAjYk+sEp9nMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F8rdWeWWY5NBUOfmK0KPFbaZbtuuphunuT8ZnOewF2cO5jvyLPsUJvJiKkYgA1d92 EoA6ZcuXF68rsgupPt/5H7c209JrjuZgpJyFCzLjk0OETjc8iKaZj1V1yg4Dr9O/o1 V2pBzsVjr0JyA9/JigJQc/N+DSXC81rzI7emvvcY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Tetsuo Handa , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 4.19 183/229] Bluetooth: L2CAP: initialize delayed works at l2cap_chan_create() Date: Mon, 24 Oct 2022 13:31:42 +0200 Message-Id: <20221024113005.022499824@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 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 From: Tetsuo Handa [ Upstream commit 2d2cb3066f2c90cd8ca540b36ba7a55e7f2406e0 ] 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 Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- 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 65d20bdff023..7c280fcdcaa0 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -63,6 +63,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) { @@ -470,6 +473,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; @@ -3154,10 +3160,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.35.1