From patchwork Wed Oct 19 08:33:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4865 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp223979wrs; Wed, 19 Oct 2022 02:39:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4uQzRoUpEDZiScFs7bJ1kwXGGsK2qwpKSxEprgoUn9G1LBUbiTORemjpLfHBPKHiNUWbcM X-Received: by 2002:aa7:c58a:0:b0:459:1511:6cff with SMTP id g10-20020aa7c58a000000b0045915116cffmr6635024edq.27.1666172340693; Wed, 19 Oct 2022 02:39:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172340; cv=none; d=google.com; s=arc-20160816; b=cUHj0NuLsBL2BlAxMc4TTf5lP1jGaRz/drZDEJ8sM1aqwQrzQE8/Si077nQrfB9MST N6kS4anO2ZpnUo9QzS8LB8sSQcuZfKdw2Sj4ideOh1jwTp7gX7moWxIC+n+XVFHZVxCg j3Y2M0rchvt2XjQHIvkclfzgkQ1vaM+iqwOMN67ufN6iK6GmEGv/wk/p5JL2a1B35NGb Ltx0vYiJuJVNboFvVkQfVOE06PlJe2ZKr+2vVraOAoCNnFM0o0QrLWTjO3e2iWueWL1m r0CvnYgdsWdnch1J4/ctlRYTnDzodNGEvlopdAOBIkYu9Puy7pijGoG0++atPZsXaBWr 4QDQ== 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=n7G6QeBJWNK7LCG912/6gUUEmSVRY4BCXKoyiuL9ouQ=; b=wkrtjN9qEoAqMTK0YSJODNVxtpoCwcfNL7zCntnEXmpBEeTFxqjuH4BG4+64NNAKW9 di5fQ3yjI35nXYVLI8KkF5cNWwx78woLMi6pzEGVgx2bvUnJAPvqBc8CwS59deKW0LJE 74f0+EyI1h/opRER9J0yD2s740YOtVWJMR1Dol6rdryJDEG1BWf/4kbqn7nGe+7pwpJK 6qJ83RblKiU+aa+wqVvCBtuqCgZa9TOg0fSN7DjE/d+bp5a87iN4QVWhiAoldTCSxSbG Hk3B5yX5XyPWKLNux6WULNrgRkzX3I0oIBFHSRTlRI+bfVD6aTrgsFY89hoTxKPWSd+j TXzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R1AO3kf9; 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 z21-20020a05640235d500b0045d073d7ca5si13879565edc.339.2022.10.19.02.38.36; Wed, 19 Oct 2022 02:39:00 -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=R1AO3kf9; 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 S233590AbiJSJ27 (ORCPT + 99 others); Wed, 19 Oct 2022 05:28:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233512AbiJSJ1Q (ORCPT ); Wed, 19 Oct 2022 05:27:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECB00E52E2; Wed, 19 Oct 2022 02:12:11 -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 BEEA661843; Wed, 19 Oct 2022 09:10:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D390DC433D6; Wed, 19 Oct 2022 09:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170624; bh=C0chszaV7MjF4tzyFjt3te2p553hPsz6RhT2J+josWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R1AO3kf9aJcUC3sPuAgNf15KISTUcqHGAXDkQehiQaLziBMmQKzCuRBSLT5c+LGK2 Hx+Ure/PJD1ClWAUflLgU8DfRMpFyU7pOJaxUIlTtQ6m+0uNcVFtsnioKLzTekSvtB nLFUlhmPfSgFld79UBeknBUSu8/wW8FYJgqq7ddU= 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 6.0 708/862] Bluetooth: L2CAP: initialize delayed works at l2cap_chan_create() Date: Wed, 19 Oct 2022 10:33:15 +0200 Message-Id: <20221019083321.252675098@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747108328159029506?= X-GMAIL-MSGID: =?utf-8?q?1747108328159029506?= 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 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);