Commit 03edf00d authored by Tetsuo Handa's avatar Tetsuo Handa Committed by Zheng Zengkai
Browse files

ath9k_htc: fix NULL pointer dereference at ath9k_htc_rxep()

stable inclusion
from stable-v5.10.136
commit 4f3b852336602ee37876494077efb3f23afd5ba3
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5ZWNE

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4f3b852336602ee37876494077efb3f23afd5ba3

--------------------------------

commit b0ec7e55 upstream.

syzbot is reporting lockdep warning followed by kernel panic at
ath9k_htc_rxep() [1], for ath9k_htc_rxep() depends on ath9k_rx_init()
being already completed.

Since ath9k_htc_rxep() is set by ath9k_htc_connect_svc(WMI_BEACON_SVC)
 from ath9k_init_htc_services(), it is possible that ath9k_htc_rxep() is
called via timer interrupt before ath9k_rx_init() from ath9k_init_device()
is called.

Since we can't call ath9k_init_device() before ath9k_init_htc_services(),
let's hold ath9k_htc_rxep() no-op until ath9k_rx_init() completes.

Link: https://syzkaller.appspot.com/bug?extid=4d2d56175b934b9a7bf9

 [1]
Reported-by: default avatarsyzbot <syzbot+4d2d56175b934b9a7bf9@syzkaller.appspotmail.com>
Signed-off-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Tested-by: default avatarsyzbot <syzbot+4d2d56175b934b9a7bf9@syzkaller.appspotmail.com>
Signed-off-by: default avatarKalle Valo <quic_kvalo@quicinc.com>
Link: https://lore.kernel.org/r/2b88f416-b2cb-7a18-d688-951e6dc3fe92@i-love.sakura.ne.jp


Signed-off-by: default avatarFedor Pchelkin <pchelkin@ispras.ru>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: default avatarWei Li <liwei391@huawei.com>
parent 954cbd48
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -281,6 +281,7 @@ struct ath9k_htc_rxbuf {
struct ath9k_htc_rx {
	struct list_head rxbuf;
	spinlock_t rxbuflock;
	bool initialized;
};

#define ATH9K_HTC_TX_CLEANUP_INTERVAL 50 /* ms */
+8 −0
Original line number Diff line number Diff line
@@ -1133,6 +1133,10 @@ void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,
	struct ath9k_htc_rxbuf *rxbuf = NULL, *tmp_buf = NULL;
	unsigned long flags;

	/* Check if ath9k_rx_init() completed. */
	if (!data_race(priv->rx.initialized))
		goto err;

	spin_lock_irqsave(&priv->rx.rxbuflock, flags);
	list_for_each_entry(tmp_buf, &priv->rx.rxbuf, list) {
		if (!tmp_buf->in_process) {
@@ -1188,6 +1192,10 @@ int ath9k_rx_init(struct ath9k_htc_priv *priv)
		list_add_tail(&rxbuf->list, &priv->rx.rxbuf);
	}

	/* Allow ath9k_htc_rxep() to operate. */
	smp_wmb();
	priv->rx.initialized = true;

	return 0;

err: