linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mac80211: Add null pointer check for ieee80211_link_get_chanctx()
@ 2025-05-25 16:42 Wentao Liang
  2025-05-26  8:25 ` Nicolas Escande
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2025-05-25 16:42 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>
---
 net/mac80211/chan.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index a442cb667520..9e6235001e0a 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] 2+ messages in thread

* Re: [PATCH] mac80211: Add null pointer check for ieee80211_link_get_chanctx()
  2025-05-25 16:42 [PATCH] mac80211: Add null pointer check for ieee80211_link_get_chanctx() Wentao Liang
@ 2025-05-26  8:25 ` Nicolas Escande
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Escande @ 2025-05-26  8:25 UTC (permalink / raw)
  To: Wentao Liang, johannes, luciano.coelho
  Cc: linux-wireless, linux-kernel, stable

On Sun May 25, 2025 at 6:42 PM CEST, Wentao Liang wrote:
> 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>
> ---
>  net/mac80211/chan.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
> index a442cb667520..9e6235001e0a 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)) {
Don't you mean '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;


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

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

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-25 16:42 [PATCH] mac80211: Add null pointer check for ieee80211_link_get_chanctx() Wentao Liang
2025-05-26  8:25 ` Nicolas Escande

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).