]> git.itanic.dy.fi Git - linux-stable/commitdiff
Bluetooth: L2CAP: initialize delayed works at l2cap_chan_create()
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Sat, 3 Sep 2022 15:32:56 +0000 (00:32 +0900)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 19 Sep 2022 16:59:33 +0000 (09:59 -0700)
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
Reported-by: syzbot <syzbot+83672956c7aa6af698b3@syzkaller.appspotmail.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net/bluetooth/l2cap_core.c

index 2c9de67daadcfb00aa175aa5e2b81ea06dd124cd..770891f68703be7553233318872d9d0b2ef5068e 100644 (file)
@@ -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);