From patchwork Mon Oct 24 11:31:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9424 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp478853wru; Mon, 24 Oct 2022 07:18:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4C5P1EzMT9Kx7H0gmceJI2jffnFzof+3Xlcp5tG8B4jo1en8acLko9R2E0jG1W4U8dVht6 X-Received: by 2002:a17:907:d0f:b0:78d:a335:8368 with SMTP id gn15-20020a1709070d0f00b0078da3358368mr28485811ejc.260.1666621086850; Mon, 24 Oct 2022 07:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666621086; cv=none; d=google.com; s=arc-20160816; b=yzIDt8+nRTuROF7f3F/omt5w8lHAOaqYBLto84F4hETwJ8r1yMMxK7DtCyCD+brh3D ea4SN7FXbCzxLIpt9zS9RT1C7zI0MQs4rPF/0TA/GPxEl2hs/qPSrH8V4W7fVNUq/+02 sZIMmr1WkP9FrzsCHHF92tjp/4mRfAGHU0L918gsp8g6Vl4gGJChfMb9ZGuNFjzkpEa6 5Gb3HW+NAzRzhkLCxo2iJI3RpjOKr6NftgcTKWt4xcLXxj3SzjATe4MIxZjd6qGjwVFD 38Au2lfCpfqGHt4rNdEeu/e76Wf895TExcFcjfkvABxNLCp3Cn/e7Z2D0xYu6QfCz/0b o7tA== 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=+2aS56KocB0BkZU6WEWM3pRdq9EZx6A1OEjyMnPSdUQ=; b=l9k2wXc+z5nV9XSUVsDrUiecZGNHCn9o3qf4sf5SaqHWFu+yraGDi1yoVpeeEVk/TY DAA0dIKFClwjQwxfTAfqCv3mexgDaGJjLrqdti4940c5ghtehvwIaoQeEr9Uak1UAsZE J/3seOPXOS7L4i6UwVOwk3tN8QVV11UyS6Yiw2zyJK47uzH2KqqPk1iTWdD1+5TVZlLe L+1xN8poriwPuqm2Aqz5BHyH+JJREjSpal/oEN0l2MDdBgPhZTdkcQhO1Bc87L5RqTAB FZFwn5SQfDLBKRza70M5idg2ngiPUoSSDStSoS8Virbj/+3uMbrsRWGXueVJK6VlqqYW +HEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=e+uFerGL; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go32-20020a1709070da000b007aac98ec3dfsi891770ejc.303.2022.10.24.07.17.37; Mon, 24 Oct 2022 07:18:06 -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=e+uFerGL; 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 S230517AbiJXOLr (ORCPT + 99 others); Mon, 24 Oct 2022 10:11:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230273AbiJXOIl (ORCPT ); Mon, 24 Oct 2022 10:08:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B40E923F2; Mon, 24 Oct 2022 05:50:39 -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 ams.source.kernel.org (Postfix) with ESMTPS id 5693AB816AA; Mon, 24 Oct 2022 12:31:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0B3CC433D6; Mon, 24 Oct 2022 12:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614686; bh=EdcwY0D8B7I0Mwb7B6eSp2g/eQ+WY0LiEEa3Q5KACew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e+uFerGLyrTALq/0fNRijS0U4pNFx20JOGiAcUHB4SRZilY+Bmd4sMZt7jk4YG5mr XKoLsqiTVHxjGu9XlVOzqSil92ig9O1Ugrj3TzuiGXs15Q1Jrojhd8y2lLpZz4YOWn ChZLyrURrXf0otGVwqWBPadhZjQQlWSgPCfpNt2s= 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 5.10 314/390] Bluetooth: L2CAP: initialize delayed works at l2cap_chan_create() Date: Mon, 24 Oct 2022 13:31:51 +0200 Message-Id: <20221024113036.346100455@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747578873044284811?= X-GMAIL-MSGID: =?utf-8?q?1747578873044284811?= 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 0c38af2ff209..8d5029c81ee7 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; @@ -3316,10 +3322,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);