All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marco Scardovi <scardracs@disroot.org>
To: Felix Fietkau <nbd@nbd.name>,
	Lorenzo Bianconi <lorenzo@kernel.org>,
	Ryder Lee <ryder.lee@mediatek.com>,
	Deren Wu <deren.wu@mediatek.com>,
	Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Cc: linux-wireless@vger.kernel.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
	Marco Scardovi <scardracs@disroot.org>
Subject: [PATCH] wifi: mt76: mt792x: fix NULL pointer dereference in mt792x_init_acpi_sar_power
Date: Fri,  4 Sep 2026 18:18:26 +0200	[thread overview]
Message-ID: <20260904161826.5638-1-scardracs@disroot.org> (raw)

In mt792x_init_acpi_sar_power(), capa is obtained from
phy->mt76->hw->wiphy->sar_capa. On systems where ACPI SAR tables exist
(such as ASUS ROG laptops) but wiphy->sar_capa has not yet been
initialized (for instance, when a regulatory notifier triggers
mt7921_set_tx_sar_pwr() before the asynchronous dev->init_work
completes mt76_register_device()), capa is NULL.

Attempting to read capa->num_freq_ranges leads to a NULL pointer
dereference at offset 0x04:

  BUG: kernel NULL pointer dereference, address: 0000000000000004
  RIP: 0010:mt792x_init_acpi_sar_power+0x40/0x1ef [mt792x_lib]
  Call Trace:
   <TASK>
   mt792x_init_acpi_sar_power+0x40/0x1ef [mt792x_lib]
   mt7921_set_tx_sar_pwr+0x3b/0x70 [mt7921_common]
   mt7921_regd_notifier_work+0x1b/0x30 [mt7921_common]
   ...

Add a check for !capa and !phy->mt76->frp before dereferencing,
matching the existing defensive pattern in mt76/mac80211.c.

Fixes: f965333e491e ("mt76: mt7921: introduce ACPI SAR support")
Signed-off-by: Marco Scardovi <scardracs@disroot.org>
---
 drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c b/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c
index 946dd7956e4a..fbc2f9706dd4 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c
+++ b/drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c
@@ -326,6 +326,9 @@ int mt792x_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default)
 	if (!phy->acpisar || !((struct mt792x_acpi_sar *)phy->acpisar)->dyn)
 		return 0;
 
+	if (!capa || !phy->mt76->frp)
+		return 0;
+
 	/* When ACPI SAR enabled in HW, we should apply rules for .frp
 	 * 1. w/o .sar_specs : set ACPI SAR power as the defatul value
 	 * 2. w/  .sar_specs : set power with min(.sar_specs, ACPI_SAR)
-- 
2.55.0


             reply	other threads:[~2026-09-04 16:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04 16:18 Marco Scardovi [this message]
2026-09-04 23:48 ` [PATCH] wifi: mt76: mt792x: fix NULL pointer dereference in mt792x_init_acpi_sar_power Devin Wittmayer
2026-09-05  5:48   ` Marco Scardovi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260904161826.5638-1-scardracs@disroot.org \
    --to=scardracs@disroot.org \
    --cc=deren.wu@mediatek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=mingyen.hsieh@mediatek.com \
    --cc=nbd@nbd.name \
    --cc=ryder.lee@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.