linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mac80211: Add null pointer check for ieee80211_link_get_chanctx()
@ 2025-05-26  9:19 Wentao Liang
  2025-05-26  9:35 ` Johannes Berg
  2025-05-26  9:44 ` Greg KH
  0 siblings, 2 replies; 6+ messages in thread
From: Wentao Liang @ 2025-05-26  9:19 UTC (permalink / raw)
  To: johannes, luciano.coelho
  Cc: linux-wireless, linux-kernel, Wentao Liang, stable

The function ieee80211_chsw_switch_vifs() calls the function
ieee80211_link_get_chanctx(), but does not check its return value.
The return value is a null pointer if the ieee80211_link_get_chanctx()
fails. This will lead to a null pointer dereference in the following
code "&old_ctx->conf". A proper implementation can be found in
ieee80211_link_use_reserved_assign().

Add a null pointer check and goto error handling path if the
function fails.

Fixes: 5d52ee811019 ("mac80211: allow reservation of a running chanctx")
Cc: stable@vger.kernel.org # v3.16
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
v2: Fix code error.

 net/mac80211/chan.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index a442cb667520..c9b703c283e7 100644
--- a/net/mac80211/chan.c
+++ b/net/mac80211/chan.c
@@ -1503,6 +1503,10 @@ static int ieee80211_chsw_switch_vifs(struct ieee80211_local *local,
 				continue;
 
 			old_ctx = ieee80211_link_get_chanctx(link);
+			if (WARN_ON(!old_ctx)) {
+				err = -EINVAL;
+				goto out;
+			}
 			vif_chsw[i].vif = &link->sdata->vif;
 			vif_chsw[i].old_ctx = &old_ctx->conf;
 			vif_chsw[i].new_ctx = &ctx->conf;
-- 
2.42.0.windows.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-05-26 10:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-26  9:19 [PATCH v2] mac80211: Add null pointer check for ieee80211_link_get_chanctx() Wentao Liang
2025-05-26  9:35 ` Johannes Berg
2025-05-26  9:44 ` Greg KH
2025-05-26  9:50   ` Johannes Berg
2025-05-26  9:56     ` Johannes Berg
2025-05-26 10:25       ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).