Skip to contentSkip to conversation

brcmfmac: driver crash with iOS 18.6.1, potential DoS

PATCH Superseded Hsien Chou 7 participants 32 messages Sep 24, 2025 – Oct 13, 2025 1 message not in the archive Broadcom BRCM80211 IEEE802.11 wireless drivers

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CAE3HL_yv8t1Rkd+jLfQMkc3YrNONQp0pRFESV+v92ECf_+7Xjw@mail.gmail.com

Hsien Chou

author
#1 lore raw

Hi Arend and everyone on the mailing lists,

I'm reporting a driver crash in brcmfmac that can be triggered by an iPhone with iOS 18.6.1 or newer. This issue allows a remote, unauthenticated device to crash the Wi-Fi driver, leading to a denial of service.

The full details, including complete crash logs and a step-by-step reproduction guide, are available on the GitHub issue page:
https://github.com/raspberrypi/linux/issues/7033

For a quick reference, here are the key details:
* Affected devices: A Raspberry Pi running as a Wi-Fi access point.
* Trigger: An iPhone with iOS > 18.6.1 attempts to view the properties of the Wi-Fi network.
* Root cause (based on preliminary analysis): The driver panics, possibly due to a malformed or unexpected frame.

Please let me know if you need any additional information to debug this issue.

Thank you for your time and attention.

Regards,

--
Ken Chou

maintainer
#2 lore raw
In reply to a message not in the archive
Quoted 7 lines · Hsien Chou

Hi Arend and everyone on the mailing lists,

I'm reporting a driver crash in brcmfmac that can be triggered by an iPhone with iOS 18.6.1 or newer. This issue *allows a remote, unauthenticated device* to crash the Wi-Fi driver, leading to a denial of service.

The full details, including complete crash logs and a step-by-step reproduction guide, are available on the GitHub issue page:
https://github.com/raspberrypi/linux/issues/7033 <https://github.com/ raspberrypi/linux/issues/7033>

Quoted 6 lines

For a quick reference, here are the key details:
* *Affected devices:* A Raspberry Pi running as a Wi-Fi access point.
* *Trigger:* An iPhone with iOS > 18.6.1 attempts to view the properties of the Wi-Fi network.
* *Root cause (based on preliminary analysis):* The driver panics, possibly due to a malformed or unexpected frame.

Please let me know if you need any additional information to debug this issue.

Having the kernel .config file from the Raspberry Pi would be helpful reproducing the driver build. Can you provide that?

Regards,
Arend

author
#3 lore raw

Hi Arend,

Attachement is the kernel .config file. Thanks for the quick response!

Regards,

--
Ken Chou

Arend van Spriel <[email protected]> 於 2025年9月26日 週五 上午2:31寫道:

Quoted 29 lines · Hsien Chou
Quoted 19 lines

Hi Arend and everyone on the mailing lists,

I'm reporting a driver crash in brcmfmac that can be triggered by an iPhone with iOS 18.6.1 or newer. This issue *allows a remote, unauthenticated device* to crash the Wi-Fi driver, leading to a denial of service.

The full details, including complete crash logs and a step-by-step reproduction guide, are available on the GitHub issue page:
https://github.com/raspberrypi/linux/issues/7033 <https://github.com/
raspberrypi/linux/issues/7033>

For a quick reference, here are the key details:
* *Affected devices:* A Raspberry Pi running as a Wi-Fi access point.
* *Trigger:* An iPhone with iOS > 18.6.1 attempts to view the properties of the Wi-Fi network.
* *Root cause (based on preliminary analysis):* The driver panics, possibly due to a malformed or unexpected frame.

Quoted 2 lines

Please let me know if you need any additional information to debug this issue.

Having the kernel .config file from the Raspberry Pi would be helpful reproducing the driver build. Can you provide that?

Regards,
Arend

#4 lore raw
Quoted 9 lines · Hsien Chou

Hi Arend,

Attachement is the kernel .config file. Thanks for the quick response!

Regards,

--
Ken Chou

Hi Ken,

By any chance, do you have a PCAP capture of when the problematic AQNP Action frame is sent? I have experienced some elusive connectivity issues with some Apple's devices with a ath12k-based AP, I wonder if the frame is malformed and could cause a problem on other drivers too.

BR,

Pablo MG

maintainer
#5 lore raw
In reply to Hsien Chou
Quoted 3 lines · Hsien Chou

Hi Arend,

Attachement is the kernel .config file. Thanks for the quick response!

Thanks. That helps and using gdb I can determine the location in which the null deref happened:

drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c:
1561 if (p2p_af->subtype == P2P_AF_PRESENCE_RSP)
0x0000000000016d18 <+560>: ldr x0, [sp, #112]

1562 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
0x0000000000016d1c <+564>: add x1, x20, #0x48

1563 else
1564 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1565
1566 err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
0x0000000000016d20 <+568>: mov w3, #0x724 // #1828

1561 if (p2p_af->subtype == P2P_AF_PRESENCE_RSP)
0x0000000000016d24 <+572>: ldrb w2, [x0, #5] <==

1562 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
0x0000000000016d28 <+576>: add x0, x20, #0x38
0x0000000000016d2c <+580>: cmp w2, #0x2

x0 is indeed 0 so p2p_af is NULL. Offset of subtype field is indeed #5:

/* offset    |  size */  type = struct brcmf_p2p_action_frame {
/*    0      |     1 */    u8 category;
/*    1      |     3 */    u8 oui[3];
/*    4      |     1 */    u8 type;
/*    5      |     1 */    u8 subtype;
/*    6      |     1 */    u8 dialog_token;
/*    7      |     0 */    u8 elts[];
                           /* total size (bytes):    7 */
                         }

What does not make sense to me is that the logs says:

Sep 02 17:24:32 raspi kernel: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000

Given the instruction in brcmf_p2p_send_action_frame+0x23c (+572) I would expect the kernel to complain about virtual address 0000000000000005.

Also not clear how p2p_af can be NULL.

	p2p_af = (struct brcmf_p2p_action_frame *)af_params->action_frame.data;
struct brcmf_fil_action_frame_le {
	u8	da[ETH_ALEN];
	__le16	len;
	__le32	packet_id;
	u8	data[BRCMF_FIL_ACTION_FRAME_SIZE];
};
struct brcmf_fil_af_params_le {
	__le32					channel;
	__le32					dwell_time;
	u8					bssid[ETH_ALEN];
	u8					pad[2];
	struct brcmf_fil_action_frame_le	action_frame;
};

so the data field in action_frame is a sized array element so it is not possible that it has NULL address.

So it seems I could not reproduce the build reliably. I used GCC13 iso GCC12 as given in the .config, but I don't expect that could explain the difference.

Regards,
Arend

Quoted 35 lines

Regards,

--
Ken Chou

Arend van Spriel <[email protected]> 於 2025年9月26日 週五 上午2:31寫道:

Quoted 29 lines · Hsien Chou
Quoted 19 lines

Hi Arend and everyone on the mailing lists,

I'm reporting a driver crash in brcmfmac that can be triggered by an iPhone with iOS 18.6.1 or newer. This issue *allows a remote, unauthenticated device* to crash the Wi-Fi driver, leading to a denial of service.

The full details, including complete crash logs and a step-by-step reproduction guide, are available on the GitHub issue page:
https://github.com/raspberrypi/linux/issues/7033 <https://github.com/
raspberrypi/linux/issues/7033>

For a quick reference, here are the key details:
* *Affected devices:* A Raspberry Pi running as a Wi-Fi access point.
* *Trigger:* An iPhone with iOS > 18.6.1 attempts to view the properties of the Wi-Fi network.
* *Root cause (based on preliminary analysis):* The driver panics, possibly due to a malformed or unexpected frame.

Quoted 2 lines

Please let me know if you need any additional information to debug this issue.

Having the kernel .config file from the Raspberry Pi would be helpful reproducing the driver build. Can you provide that?

Regards,
Arend

#6 lore raw

Hi,
regarding reproducibility, I would assume Arend is using the mainline kernel and Hsien just tested the Raspberry Pi vendor kernel. The brcmfmac driver has some modifications downstream.

@Hsien or @Chris,
are you able to reproduce it with a mainline/torvalds kernel? You only need to replace Kernel, Modules and Device tree.

Best regards

#7 lore raw

Our experience is with kernel version 5.4.83-v7+. I've not rebuilt the kernel or worked in that space for some time.

I'm happy to follow directions and give specific examples and feedback if there's something I can test, but I don't want to cloud the results by not knowing what I'm doing. Let me know how I can help.

Thanks-
Chris

-----Original Message-----
From: Stefan Wahren <[email protected]>
Sent: Monday, September 29, 2025 12:06 PM
To: Hsien Chou <[email protected]>; Arend van Spriel <[email protected]>; Chris Spargo <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: brcmfmac: driver crash with iOS 18.6.1, potential DoS

Hi,
regarding reproducibility, I would assume Arend is using the mainline kernel and Hsien just tested the Raspberry Pi vendor kernel. The brcmfmac driver has some modifications downstream.

@Hsien or @Chris,
are you able to reproduce it with a mainline/torvalds kernel? You only need to replace Kernel, Modules and Device tree.

Best regards

maintainer
#8 lore raw
In reply to Stefan Wahren
Quoted 2 lines · Stefan Wahren

Hi,
regarding reproducibility, I would assume Arend is using the mainline kernel and Hsien just tested the Raspberry Pi vendor kernel. The brcmfmac driver has some modifications downstream.

Actually, I tried to build the downstream RPi vendor kernel. However, there are some variables in play. The config Hsien Chou sent was 6.6.28, but the log is 6.12.34. So I have taken the provided config and built from the rpi-6.6.y branch:

commit bba53a117a4a5c29da892962332ff1605990e17a (HEAD, rpi/rpi-6.6.y)

Author: Phil Elwell <[email protected]>
Date:   Wed Mar 26 11:28:28 2025 +0000

dts: rp1: Don't use DMA with UARTs

DMA has been enabled on RP1's UART0, but with mixed success. Transmits seem to work, but the DMA interface is not well suited to receiving arbitrary amounts of data. In particular, the PL011 driver is slow to pass on the received data, batching it into large blocks.

On balance, it's better to just disable the DMA support. As with the other UARTs, the required runes are left in the DTS as comments.

Probably should have tried withthe rpui-6.12.y branch instead. Let me try that although...:

$ git diff rpi/rpi-6.6.y rpi/rpi-6.12.y -- drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +1 -1
index 7376f9f37d07..7949f78c61e1 100644
@@ -2339,7 +2339,7 @@ struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name,
                goto fail;
        }
 
-       strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
+       strscpy(ifp->ndev->name, name, sizeof(ifp->ndev->name));
        ifp->ndev->name_assign_type = name_assign_type;
        err = brcmf_net_attach(ifp, true);
        if (err) {

Gr. AvS

Quoted 6 lines

@Hsien or @Chris,
are you able to reproduce it with a mainline/torvalds kernel? You only need to replace Kernel, Modules and Device tree.

Best regards

#9 lore raw

PATCH 1/1 brcmfmac: Fix NULL pointer dereference in P2P action frame handling

When iPhones query network information via the WiFi settings "i" button, the brcmfmac driver crashes with a NULL pointer dereference. This occurs because the P2P device vif is not initialized when handling certain action frames.

Add NULL check for vif before dereferencing in brcmf_p2p_tx_action_frame() and return -ENODEV when vif is NULL. Also modify the retry loop in brcmf_p2p_send_action_frame() to stop immediately on permanent failures rather than retrying.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

---
 .../wireless/broadcom/brcm80211/brcmfmac/p2p.c   | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +15 -1
index 10d9d9c63..2c73156fa 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
 	else
 		vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
 
+	/* add NULL check */
+	if (!vif) {
+		brcmf_err("vif is NULL, cannot send action frame\n");
+		return -ENODEV;
+	}
+
 	err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
 					sizeof(*af_params));
 	if (err) {
@@ -1857,7 +1863,15 @@ bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
 		if (af_params->channel)
 			msleep(P2P_AF_RETRY_DELAY_TIME);
 
-		ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
+		int result = brcmf_p2p_tx_action_frame(p2p, af_params);
+
+		/* if it's a permanent failure (like NULL vif), stop retrying */
+		if (result == -ENODEV) {
+			brcmf_err("Permanent failure, stop retries\n");
+			break;
+		}
+
+		ack = !result;
 		tx_retry++;
 		dwell_overflow = brcmf_p2p_check_dwell_overflow(requested_dwell,
 								dwell_jiffies);
Signature · 1 line
2.34.1
maintainer
#10 lore raw

Re: [PATCH] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

Op 3 oktober 2025 01:20:21 schreef Richard Reigh <[email protected]>:

Quoted 4 lines

When iPhones query network information via the WiFi settings "i" button, the brcmfmac driver crashes with a NULL pointer dereference. This occurs because the P2P device vif is not initialized when handling certain action frames.

That does make a lot more sense than the line that gdb gave me with my driver rebuild attempt.

Quoted 2 lines

Add NULL check for vif before dereferencing in brcmf_p2p_tx_action_frame() and return -ENODEV when vif is NULL. Also modify

Now I don't think it is necessary to bail out here. See my suggestion below...

Quoted 20 lines

the retry loop in
brcmf_p2p_send_action_frame() to stop immediately on permanent failures rather than retrying.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

---
.../wireless/broadcom/brcm80211/brcmfmac/p2p.c | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
index 10d9d9c63..2c73156fa 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct 
 brcmf_p2p_info *p2p,

else
vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;

Quoted 5 lines

+ /* add NULL check */
+ if (!vif) {
+ brcmf_err("vif is NULL, cannot send action frame\n");
+ return -ENODEV;
+ }

Instead of giving up and surrender we can use primary vif, ie. p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif:

if (!vif) {
       brcmf_dbg(TRACE, "no P2P device setup\n");
       vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
}

Regards,
Arend

#11 lore raw

Re: [PATCH] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

Hi,

Am 03.10.25 um 18:00 schrieb Arend van Spriel:

Quoted 42 lines

Op 3 oktober 2025 01:20:21 schreef Richard Reigh <[email protected]>:

Quoted 4 lines

When iPhones query network information via the WiFi settings "i" button, the brcmfmac driver crashes with a NULL pointer dereference. This occurs because the P2P device vif is not initialized when handling certain action frames.

That does make a lot more sense than the line that gdb gave me with my driver rebuild attempt.

Quoted 2 lines

Add NULL check for vif before dereferencing in brcmf_p2p_tx_action_frame() and return -ENODEV when vif is NULL. Also modify

Now I don't think it is necessary to bail out here. See my suggestion below...

Quoted 20 lines

the retry loop in
brcmf_p2p_send_action_frame() to stop immediately on permanent failures rather than retrying.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

---
.../wireless/broadcom/brcm80211/brcmfmac/p2p.c   | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
index 10d9d9c63..2c73156fa 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct 
 brcmf_p2p_info *p2p,

else
vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;

Quoted 5 lines

+ /* add NULL check */
+ if (!vif) {
+ brcmf_err("vif is NULL, cannot send action frame\n");
+ return -ENODEV;
+ }

Instead of giving up and surrender we can use primary vif, ie. p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif:

Quoted 4 lines

if (!vif) {
       brcmf_dbg(TRACE, "no P2P device setup\n"); vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; }

this looks much better. But the whole patch needs a fixes tag.

In case this issue is reproducible before Linux 5.8, the tag should reference:
18e2f61db3b7 ("brcmfmac: P2P action frame tx.")

otherwise it should reference:
d524d5ce3655 ("brcmfmac: p2p cert 6.1.9-support GOUT handling p2p presence request")

Best regards

Quoted 5 lines

Regards,
Arend

maintainer
#12 lore raw

Re: [PATCH] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

Quoted 44 lines · Stefan Wahren

Hi,

Am 03.10.25 um 18:00 schrieb Arend van Spriel:

Quoted 41 lines

Op 3 oktober 2025 01:20:21 schreef Richard Reigh <[email protected]>:

Quoted 4 lines

When iPhones query network information via the WiFi settings "i" button, the brcmfmac driver crashes with a NULL pointer dereference. This occurs because the P2P device vif is not initialized when handling certain action frames.

That does make a lot more sense than the line that gdb gave me with my driver rebuild attempt.

Quoted 2 lines

Add NULL check for vif before dereferencing in brcmf_p2p_tx_action_frame() and return -ENODEV when vif is NULL. Also modify

Now I don't think it is necessary to bail out here. See my suggestion below...

Quoted 20 lines

the retry loop in
brcmf_p2p_send_action_frame() to stop immediately on permanent failures rather than retrying.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

---
.../wireless/broadcom/brcm80211/brcmfmac/p2p.c   | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
index 10d9d9c63..2c73156fa 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct 
 brcmf_p2p_info *p2p,

else
vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;

Quoted 5 lines

+ /* add NULL check */
+ if (!vif) {
+ brcmf_err("vif is NULL, cannot send action frame\n");
+ return -ENODEV;
+ }

Instead of giving up and surrender we can use primary vif, ie. p2p-

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

bss_idx[P2PAPI_BSSCFG_PRIMARY].vif:

if (!vif) {
       brcmf_dbg(TRACE, "no P2P device setup\n"); vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; }

this looks much better. But the whole patch needs a fixes tag.

Sure.

Quoted 5 lines

In case this issue is reproducible before Linux 5.8, the tag should reference:
18e2f61db3b7 ("brcmfmac: P2P action frame tx.")

otherwise it should reference:
d524d5ce3655 ("brcmfmac: p2p cert 6.1.9-support GOUT handling p2p presence request")

Both good suggestions. Looking at the code I would say that 18e2f61db3b7 ("brcmfmac: P2P action frame tx.") is the best choice.

Regards,
Arend

#13 lore raw

Re: [PATCH] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

Hi Richard,

Am 04.10.25 um 11:22 schrieb Arend van Spriel:

Quoted 55 lines · Stefan Wahren
Quoted 44 lines

Hi,

Am 03.10.25 um 18:00 schrieb Arend van Spriel:

Quoted 41 lines

Op 3 oktober 2025 01:20:21 schreef Richard Reigh <[email protected]>:

Quoted 4 lines

When iPhones query network information via the WiFi settings "i" button, the brcmfmac driver crashes with a NULL pointer dereference. This occurs because the P2P device vif is not initialized when handling certain action frames.

That does make a lot more sense than the line that gdb gave me with my driver rebuild attempt.

Quoted 2 lines

Add NULL check for vif before dereferencing in brcmf_p2p_tx_action_frame() and return -ENODEV when vif is NULL. Also modify

Now I don't think it is necessary to bail out here. See my suggestion below...

Quoted 20 lines

the retry loop in
brcmf_p2p_send_action_frame() to stop immediately on permanent failures rather than retrying.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

---
.../wireless/broadcom/brcm80211/brcmfmac/p2p.c   | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
index 10d9d9c63..2c73156fa 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct 
 brcmf_p2p_info *p2p,

else
vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;

Quoted 5 lines

+ /* add NULL check */
+ if (!vif) {
+ brcmf_err("vif is NULL, cannot send action frame\n");
+ return -ENODEV;
+ }

Instead of giving up and surrender we can use primary vif, ie. p2p-

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

bss_idx[P2PAPI_BSSCFG_PRIMARY].vif:

if (!vif) {
       brcmf_dbg(TRACE, "no P2P device setup\n"); vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; }

this looks much better. But the whole patch needs a fixes tag.

Sure.

Quoted 7 lines
Quoted 5 lines

In case this issue is reproducible before Linux 5.8, the tag should reference:
18e2f61db3b7 ("brcmfmac: P2P action frame tx.")

otherwise it should reference:
d524d5ce3655 ("brcmfmac: p2p cert 6.1.9-support GOUT handling p2p presence request")

Both good suggestions. Looking at the code I would say that 18e2f61db3b7 ("brcmfmac: P2P action frame tx.") is the best choice.

thanks. @Richard Do you plan to submit a V2 patch?

Best regards

Quoted 3 lines

Regards,
Arend

#14 lore raw

Re: [PATCH] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

Quoted 75 lines · Stefan Wahren

Hi Richard,

Am 04.10.25 um 11:22 schrieb Arend van Spriel:

Quoted 71 lines · Stefan Wahren
Quoted 52 lines

Hi,

Am 03.10.25 um 18:00 schrieb Arend van Spriel:

Quoted 49 lines

Op 3 oktober 2025 01:20:21 schreef Richard Reigh <[email protected]>:

Quoted 7 lines

When iPhones query network information via the WiFi settings "i" button,
the brcmfmac driver crashes with a NULL pointer dereference. This occurs
because the P2P device vif is not initialized when handling certain action
frames.

That does make a lot more sense than the line that gdb gave me with my driver rebuild attempt.

Quoted 3 lines

Add NULL check for vif before dereferencing in
brcmf_p2p_tx_action_frame()
and return -ENODEV when vif is NULL. Also modify

Now I don't think it is necessary to bail out here. See my suggestion below...

Quoted 22 lines

the retry loop in
brcmf_p2p_send_action_frame() to stop immediately on permanent failures
rather than retrying.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

---
.../wireless/broadcom/brcm80211/brcmfmac/p2p.c | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
index 10d9d9c63..2c73156fa 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct
 brcmf_p2p_info *p2p,

else
vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;

Quoted 5 lines

+ /* add NULL check */
+ if (!vif) {
+ brcmf_err("vif is NULL, cannot send action frame\n");
+ return -ENODEV;
+ }

Instead of giving up and surrender we can use primary vif, ie. p2p-

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

bss_idx[P2PAPI_BSSCFG_PRIMARY].vif:

if (!vif) {
       brcmf_dbg(TRACE, "no P2P device setup\n");
       vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
}

this looks much better. But the whole patch needs a fixes tag.

Sure.

Quoted 7 lines

In case this issue is reproducible before Linux 5.8, the tag should reference:
18e2f61db3b7 ("brcmfmac: P2P action frame tx.")

otherwise it should reference:
d524d5ce3655 ("brcmfmac: p2p cert 6.1.9-support GOUT handling p2p presence request")

Quoted 8 lines
Quoted 2 lines

Both good suggestions. Looking at the code I would say that 18e2f61db3b7 ("brcmfmac: P2P action frame tx.") is the best choice.

thanks. @Richard Do you plan to submit a V2 patch?

Best regards

Quoted 3 lines

Regards,
Arend

Stefan,

Yes, I plan on submitting a V2 patch, after I finish testing the change.

I will also add the suggested fixes tag to the patch submission.

Thanks,
Richard

#15 lore raw

Re: [PATCH] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

Am 06.10.25 um 19:08 schrieb Richard Reigh:

Quoted 73 lines · Stefan Wahren
Quoted 72 lines

Hi Richard,

Am 04.10.25 um 11:22 schrieb Arend van Spriel:

Quoted 62 lines · Stefan Wahren
Quoted 49 lines

Hi,

Am 03.10.25 um 18:00 schrieb Arend van Spriel:

Quoted 46 lines

Op 3 oktober 2025 01:20:21 schreef Richard Reigh <[email protected]>:

Quoted 7 lines

When iPhones query network information via the WiFi settings "i" button,
the brcmfmac driver crashes with a NULL pointer dereference. This occurs
because the P2P device vif is not initialized when handling certain action
frames.

That does make a lot more sense than the line that gdb gave me with my driver rebuild attempt.

Quoted 3 lines

Add NULL check for vif before dereferencing in
brcmf_p2p_tx_action_frame()
and return -ENODEV when vif is NULL. Also modify

Now I don't think it is necessary to bail out here. See my suggestion below...

Quoted 22 lines

the retry loop in
brcmf_p2p_send_action_frame() to stop immediately on permanent failures
rather than retrying.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

---
.../wireless/broadcom/brcm80211/brcmfmac/p2p.c | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
index 10d9d9c63..2c73156fa 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct
 brcmf_p2p_info *p2p,

else
vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;

Quoted 5 lines

+ /* add NULL check */
+ if (!vif) {
+ brcmf_err("vif is NULL, cannot send action frame\n");
+ return -ENODEV;
+ }

Instead of giving up and surrender we can use primary vif, ie. p2p-

Quoted 6 lines
Quoted 5 lines
Quoted 1 line

bss_idx[P2PAPI_BSSCFG_PRIMARY].vif:

if (!vif) {
        brcmf_dbg(TRACE, "no P2P device setup\n");
        vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
}

this looks much better. But the whole patch needs a fixes tag.

Sure.

Quoted 4 lines

In case this issue is reproducible before Linux 5.8, the tag should reference:
18e2f61db3b7 ("brcmfmac: P2P action frame tx.")

Quoted 5 lines
Quoted 3 lines

otherwise it should reference:
d524d5ce3655 ("brcmfmac: p2p cert 6.1.9-support GOUT handling p2p presence request")

Both good suggestions. Looking at the code I would say that 18e2f61db3b7 ("brcmfmac: P2P action frame tx.") is the best choice.

thanks. @Richard Do you plan to submit a V2 patch?

Quoted 8 lines
Quoted 3 lines

Best regards

Quoted 2 lines

Regards,
Arend

Stefan,

Yes, I plan on submitting a V2 patch, after I finish testing the change.

I will also add the suggested fixes tag to the patch submission.

Sure, take your time.

Thanks

Quoted 3 lines

Thanks,
Richard

#16 lore raw

Re: [PATCH] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

Quoted 78 lines · Stefan Wahren

Am 06.10.25 um 19:08 schrieb Richard Reigh:

Quoted 76 lines · Stefan Wahren
Quoted 75 lines

Hi Richard,

Am 04.10.25 um 11:22 schrieb Arend van Spriel:

Quoted 62 lines · Stefan Wahren
Quoted 49 lines

Hi,

Am 03.10.25 um 18:00 schrieb Arend van Spriel:

Quoted 46 lines

Op 3 oktober 2025 01:20:21 schreef Richard Reigh <[email protected]>:

Quoted 7 lines

When iPhones query network information via the WiFi settings "i" button,
the brcmfmac driver crashes with a NULL pointer dereference. This occurs
because the P2P device vif is not initialized when handling certain action
frames.

That does make a lot more sense than the line that gdb gave me with my driver rebuild attempt.

Quoted 3 lines

Add NULL check for vif before dereferencing in
brcmf_p2p_tx_action_frame()
and return -ENODEV when vif is NULL. Also modify

Now I don't think it is necessary to bail out here. See my suggestion below...

Quoted 22 lines

the retry loop in
brcmf_p2p_send_action_frame() to stop immediately on permanent failures
rather than retrying.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

---
.../wireless/broadcom/brcm80211/brcmfmac/p2p.c | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
index 10d9d9c63..2c73156fa 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct
 brcmf_p2p_info *p2p,

else
vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;

Quoted 5 lines

+ /* add NULL check */
+ if (!vif) {
+ brcmf_err("vif is NULL, cannot send action frame\n");
+ return -ENODEV;
+ }

Instead of giving up and surrender we can use primary vif, ie. p2p-

Quoted 6 lines
Quoted 5 lines
Quoted 1 line

bss_idx[P2PAPI_BSSCFG_PRIMARY].vif:

if (!vif) {
        brcmf_dbg(TRACE, "no P2P device setup\n");
        vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
}

this looks much better. But the whole patch needs a fixes tag.

Sure.

Quoted 4 lines

In case this issue is reproducible before Linux 5.8, the tag should reference:
18e2f61db3b7 ("brcmfmac: P2P action frame tx.")

Quoted 5 lines
Quoted 3 lines

otherwise it should reference:
d524d5ce3655 ("brcmfmac: p2p cert 6.1.9-support GOUT handling p2p presence request")

Both good suggestions. Looking at the code I would say that 18e2f61db3b7 ("brcmfmac: P2P action frame tx.") is the best choice.

thanks. @Richard Do you plan to submit a V2 patch?

Best regards

Quoted 2 lines

Regards,
Arend

Quoted 11 lines
Quoted 5 lines

Stefan,

Yes, I plan on submitting a V2 patch, after I finish testing the change.

I will also add the suggested fixes tag to the patch submission.

Sure, take your time.

Thanks

Quoted 3 lines

Thanks,
Richard

Hi Arend and Stefan,

Thank you for the feedback on V1. I've tested the suggested fallback to PRIMARY vif, but unfortunately it still crashes with a NULL pointer dereference.

The PRIMARY vif itself is not NULL (confirmed via debug output), but using it for P2P action frames causes a crash later in brcmf_p2p_tx_action_frame(). It appears the PRIMARY vif may not have the necessary P2P-specific structures initialized.

Should I:

1. Investigate which specific pointer/structure is NULL when using PRIMARY vif for P2P operations, or
2. Stick with the original approach of failing gracefully with -ENODEV when DEVICE vif is unavailable?

My original fix (returning -ENODEV) does prevent the crash and allows the system to continue operating normally, just without responding to that particular iPhone query.

Best regards,
Richard

maintainer
#17 lore raw

Re: [PATCH] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

Quoted 102 lines · Richard Reigh
Quoted 78 lines · Stefan Wahren

Am 06.10.25 um 19:08 schrieb Richard Reigh:

Quoted 76 lines · Stefan Wahren
Quoted 75 lines

Hi Richard,

Am 04.10.25 um 11:22 schrieb Arend van Spriel:

Quoted 62 lines · Stefan Wahren
Quoted 49 lines

Hi,

Am 03.10.25 um 18:00 schrieb Arend van Spriel:

Quoted 46 lines

Op 3 oktober 2025 01:20:21 schreef Richard Reigh <[email protected]>:

Quoted 7 lines

When iPhones query network information via the WiFi settings "i" button,
the brcmfmac driver crashes with a NULL pointer dereference. This occurs
because the P2P device vif is not initialized when handling certain action
frames.

That does make a lot more sense than the line that gdb gave me with my driver rebuild attempt.

Quoted 3 lines

Add NULL check for vif before dereferencing in
brcmf_p2p_tx_action_frame()
and return -ENODEV when vif is NULL. Also modify

Now I don't think it is necessary to bail out here. See my suggestion below...

Quoted 22 lines

the retry loop in
brcmf_p2p_send_action_frame() to stop immediately on permanent failures
rather than retrying.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

---
.../wireless/broadcom/brcm80211/brcmfmac/p2p.c | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
index 10d9d9c63..2c73156fa 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct
 brcmf_p2p_info *p2p,

else
vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;

Quoted 5 lines

+ /* add NULL check */
+ if (!vif) {
+ brcmf_err("vif is NULL, cannot send action frame\n");
+ return -ENODEV;
+ }

Instead of giving up and surrender we can use primary vif, ie. p2p-

Quoted 6 lines
Quoted 5 lines
Quoted 1 line

bss_idx[P2PAPI_BSSCFG_PRIMARY].vif:

if (!vif) {
         brcmf_dbg(TRACE, "no P2P device setup\n");
         vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
}

this looks much better. But the whole patch needs a fixes tag.

Sure.

Quoted 4 lines

In case this issue is reproducible before Linux 5.8, the tag should reference:
18e2f61db3b7 ("brcmfmac: P2P action frame tx.")

Quoted 5 lines
Quoted 3 lines

otherwise it should reference:
d524d5ce3655 ("brcmfmac: p2p cert 6.1.9-support GOUT handling p2p presence request")

Both good suggestions. Looking at the code I would say that 18e2f61db3b7 ("brcmfmac: P2P action frame tx.") is the best choice.

thanks. @Richard Do you plan to submit a V2 patch?

Best regards

Quoted 2 lines

Regards,
Arend

Quoted 11 lines
Quoted 5 lines

Stefan,

Yes, I plan on submitting a V2 patch, after I finish testing the change.

I will also add the suggested fixes tag to the patch submission.

Sure, take your time.

Thanks

Quoted 3 lines

Thanks,
Richard

Hi Arend and Stefan,

Thank you for the feedback on V1. I've tested the suggested fallback to PRIMARY vif, but unfortunately it still crashes with a NULL pointer dereference.

The PRIMARY vif itself is not NULL (confirmed via debug output), but using it for P2P action frames causes a crash later in brcmf_p2p_tx_action_frame(). It appears the PRIMARY vif may not have the necessary P2P-specific structures initialized.

Quoted 4 lines

Should I:

1. Investigate which specific pointer/structure is NULL when using PRIMARY vif for P2P operations, or

I would be interested to see the log of the "PRIMARY vif" tesing if you still have it.

Regards,
Arend

#18 lore raw

Re: [PATCH] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

Quoted 106 lines · Arend van Spriel
Quoted 104 lines · Richard Reigh
Quoted 78 lines · Stefan Wahren

Am 06.10.25 um 19:08 schrieb Richard Reigh:

Quoted 76 lines · Stefan Wahren
Quoted 75 lines

Hi Richard,

Am 04.10.25 um 11:22 schrieb Arend van Spriel:

Quoted 62 lines · Stefan Wahren
Quoted 49 lines

Hi,

Am 03.10.25 um 18:00 schrieb Arend van Spriel:

Quoted 46 lines

Op 3 oktober 2025 01:20:21 schreef Richard Reigh <[email protected]>:

Quoted 7 lines

When iPhones query network information via the WiFi settings "i" button,
the brcmfmac driver crashes with a NULL pointer dereference. This occurs
because the P2P device vif is not initialized when handling certain action
frames.

That does make a lot more sense than the line that gdb gave me with my driver rebuild attempt.

Quoted 3 lines

Add NULL check for vif before dereferencing in
brcmf_p2p_tx_action_frame()
and return -ENODEV when vif is NULL. Also modify

Now I don't think it is necessary to bail out here. See my suggestion below...

Quoted 22 lines

the retry loop in
brcmf_p2p_send_action_frame() to stop immediately on permanent failures
rather than retrying.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

---
.../wireless/broadcom/brcm80211/brcmfmac/p2p.c | 16 +++++++++++++++-

1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
index 10d9d9c63..2c73156fa 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct
 brcmf_p2p_info *p2p,

else
vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;

Quoted 5 lines

+ /* add NULL check */
+ if (!vif) {
+ brcmf_err("vif is NULL, cannot send action frame\n");
+ return -ENODEV;
+ }

Instead of giving up and surrender we can use primary vif, ie. p2p-

Quoted 6 lines
Quoted 5 lines
Quoted 1 line

bss_idx[P2PAPI_BSSCFG_PRIMARY].vif:

if (!vif) {
         brcmf_dbg(TRACE, "no P2P device setup\n");
         vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
}

this looks much better. But the whole patch needs a fixes tag.

Sure.

Quoted 4 lines

In case this issue is reproducible before Linux 5.8, the tag should reference:
18e2f61db3b7 ("brcmfmac: P2P action frame tx.")

Quoted 5 lines
Quoted 3 lines

otherwise it should reference:
d524d5ce3655 ("brcmfmac: p2p cert 6.1.9-support GOUT handling p2p presence request")

Both good suggestions. Looking at the code I would say that 18e2f61db3b7 ("brcmfmac: P2P action frame tx.") is the best choice.

thanks. @Richard Do you plan to submit a V2 patch?

Best regards

Quoted 2 lines

Regards,
Arend

Quoted 11 lines
Quoted 5 lines

Stefan,

Yes, I plan on submitting a V2 patch, after I finish testing the change.

I will also add the suggested fixes tag to the patch submission.

Sure, take your time.

Thanks

Quoted 3 lines

Thanks,
Richard

Hi Arend and Stefan,

Thank you for the feedback on V1. I've tested the suggested fallback to PRIMARY vif, but unfortunately it still crashes with a NULL pointer dereference.

The PRIMARY vif itself is not NULL (confirmed via debug output), but using it for P2P action frames causes a crash later in brcmf_p2p_tx_action_frame(). It appears the PRIMARY vif may not have the necessary P2P-specific structures initialized.

Should I:

Quoted 8 lines
Quoted 2 lines

1. Investigate which specific pointer/structure is NULL when using PRIMARY vif for P2P operations, or

I would be interested to see the log of the "PRIMARY vif" tesing if you still have it.

Regards,
Arend

Unfortunately, I don't have any logs for this test. When the bug occurs, the Pi immediately becomes unstable and is unable to sync files to disk, so no logs are preserved.

Richard

#19 lore raw

Re: [PATCH] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

In reply to Richard Reigh

Hi Richard,

Disclaimer: my knowledge about the brcmfmac driver is very limited

Am 03.10.25 um 01:20 schrieb Richard Reigh:

Quoted 9 lines

When iPhones query network information via the WiFi settings "i" button, the brcmfmac driver crashes with a NULL pointer dereference. This occurs because the P2P device vif is not initialized when handling certain action frames.

Add NULL check for vif before dereferencing in brcmf_p2p_tx_action_frame() and return -ENODEV when vif is NULL. Also modify the retry loop in brcmf_p2p_send_action_frame() to stop immediately on permanent failures rather than retrying.

Since Arend's first suggestion didn't work, here is my feedback to your version in the case you still want to follow this approach here.

Quoted 1 line

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

This is the vendor kernel correct?

Quoted 10 lines
---
  .../wireless/broadcom/brcm80211/brcmfmac/p2p.c   | 16 +++++++++++++++-
  1 file changed, 15 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
index 10d9d9c63..2c73156fa 100644

drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p, · line 1564

Quoted 6 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +3 -0
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
  	else
  		vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
 
+	/* add NULL check */
+	if (!vif) {
+		brcmf_err("vif is NULL, cannot send action frame\n");

Such errors are dedicated for real driver issues, but now we know that's possible to trigger this. It's okay for your tests, but at the end it should be a debug message.

drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p, · line 1567

Quoted 3 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +3 -0
+		return -ENODEV;
+	}
+

I don't think this is the right place (tm), for the following reasons:
- the check is too late for an efficient bailout (e.g. there are msleeps before)
- we introduce a special return code for brcmf_p2p_tx_action_frame(), which makes it harder to maintain

So my suggestion would be to add the bailout in brcmf_cfg80211_mgmt_tx() if it's possible.

Best regards

#20 lore raw

PATCH v2 1/1 brcmfmac: Fix NULL pointer dereference in P2P action frame handling

When iPhones query network information via the WiFi settings "i" button, the brcmfmac driver crashes with a NULL pointer dereference. This occurs because the P2P device vif is not initialized when handling certain action frames.

Added an early check in brcmf_cfg80211_mgmt_tx() to verify P2P device vif availability before attepting to send action frames. Also added a defensive check in brcmf_p2p_tx_action_frame() as a safety net.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

Fixes 18e2f61db3b7 ("brcmfmac: P2P action frame tx")

---
Changes in v2:
- Added early check in cfg80211.c before calling P2P functions (suggested by Stefan Wahren)
- Changed error message to debug level in p2p.c (suggested by Stefan Wahren)
- Added fixes tag

---
 .../wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 13 +++++++++++++
 .../net/wireless/broadcom/brcm80211/brcmfmac/p2p.c  |  6 ++++++
 2 files changed, 19 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +13 -0
index ea8409e0e..9983136a7 100644
@@ -5137,6 +5137,19 @@ brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
 
 	vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
 
+	/* check if P2P device vif is available before attempting */
+	/* action frames */
+	if (ieee80211_is_action(mgmt->frame_control)) {
+		struct brcmf_p2p_info *p2p = &cfg->p2p;
+
+		if (!p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif) {
+			brcmf_dbg(TRACE, "P2P device vif not available\n");
+			cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, false,
+						GFP_KERNEL);
+			return 0;
+		}
+	}
+
 	if (ieee80211_is_probe_resp(mgmt->frame_control)) {
 		/* Right now the only reason to get a probe response */
 		/* is for p2p listen response or for p2p GO from     */
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +6 -0
index 10d9d9c63..e62135cd4 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
 	else
 		vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
 
+	/* add NULL check */
+	if (!vif) {
+		brcmf_dbg(TRACE, "vif is NULL, cannot send action frame\n");
+		return -ENODEV;
+	}
+
 	err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
 					sizeof(*af_params));
 	if (err) {
Signature · 1 line
2.34.1
#21 lore raw

Re: [PATCH v2] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

Quoted 30 lines · Richard Reigh

When iPhones query network information via the WiFi settings "i" button, the brcmfmac driver crashes with a NULL pointer dereference. This occurs because the P2P device vif is not initialized when handling certain action frames.

Added an early check in brcmf_cfg80211_mgmt_tx() to verify P2P device vif availability before attepting to send action frames. Also added a defensive check in brcmf_p2p_tx_action_frame() as a safety net.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

Fixes 18e2f61db3b7 ("brcmfmac: P2P action frame tx")

---
Changes in v2:
- Added early check in cfg80211.c before calling P2P functions (suggested by Stefan Wahren)
- Changed error message to debug level in p2p.c (suggested by Stefan Wahren)
- Added fixes tag

---
 .../wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 13 +++++++++++++
 .../net/wireless/broadcom/brcm80211/brcmfmac/p2p.c  |  6 ++++++
 2 files changed, 19 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +0 -0
index ea8409e0e..9983136a7 100644

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, · line 5142

Quoted 6 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -0
@@ -5137,6 +5137,19 @@ brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
 
        vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
 
+       /* check if P2P device vif is available before attempting */
+       /* action frames */
+       if (ieee80211_is_action(mgmt->frame_control)) {

The action frame type specific operations are done already below in the else if (ieee80211_is_action()) block. So ideally, it is better to do all action frame type specific operations in the existing else if{} block, instead of introducing a new if{} block, until unless it is really needed.

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, · line 5152

Quoted 10 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +10 -0
+               struct brcmf_p2p_info *p2p = &cfg->p2p;
+
+               if (!p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif) {
+                       brcmf_dbg(TRACE, "P2P device vif not available\n");
+                       cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, false,
+                                               GFP_KERNEL);
+                       return 0;
+               }
+       }
+

IMHO, bailing out here without responding to the ANQP Request, may not be a viable solution for the crash. Need to have a way for the AP to respond with the ANQP Response Public Action frame without crashing the driver.

Have a solution in mind, will send the patch for review after testing it.

Quoted 21 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +6 -1
index 10d9d9c63..e62135cd4 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
        else
                vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
 
+       /* add NULL check */
+       if (!vif) {
+               brcmf_dbg(TRACE, "vif is NULL, cannot send action frame\n");
+               return -ENODEV;
+       }
+
        err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
                                        sizeof(*af_params));
        if (err) {
--

2.34.1

maintainer
#22 lore raw

Re: [PATCH v2] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

Quoted 43 lines · Gokul Sivakumar
Quoted 30 lines · Richard Reigh

When iPhones query network information via the WiFi settings "i" button, the brcmfmac driver crashes with a NULL pointer dereference. This occurs because the P2P device vif is not initialized when handling certain action frames.

Added an early check in brcmf_cfg80211_mgmt_tx() to verify P2P device vif availability before attepting to send action frames. Also added a defensive check in brcmf_p2p_tx_action_frame() as a safety net.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

Fixes 18e2f61db3b7 ("brcmfmac: P2P action frame tx")

---
Changes in v2:
- Added early check in cfg80211.c before calling P2P functions (suggested by Stefan Wahren)
- Changed error message to debug level in p2p.c (suggested by Stefan Wahren)
- Added fixes tag

---
  .../wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 13 +++++++++++++
  .../net/wireless/broadcom/brcm80211/brcmfmac/p2p.c  |  6 ++++++
  2 files changed, 19 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +0 -0
index ea8409e0e..9983136a7 100644

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, · line 5142

Quoted 6 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +3 -0
@@ -5137,6 +5137,19 @@ brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
 
         vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
 
+       /* check if P2P device vif is available before attempting */
+       /* action frames */
+       if (ieee80211_is_action(mgmt->frame_control)) {

The action frame type specific operations are done already below in the else if (ieee80211_is_action()) block. So ideally, it is better to do all action frame type specific operations in the existing else if{} block, instead of introducing a new if{} block, until unless it is really needed.

Quoted 14 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, · line 5152

Quoted 10 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +10 -0
+               struct brcmf_p2p_info *p2p = &cfg->p2p;
+
+               if (!p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif) {
+                       brcmf_dbg(TRACE, "P2P device vif not available\n");
+                       cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, false,
+                                               GFP_KERNEL);
+                       return 0;
+               }
+       }
+

IMHO, bailing out here without responding to the ANQP Request, may not be a viable solution for the crash. Need to have a way for the AP to respond with the ANQP Response Public Action frame without crashing the driver.

Carying the historical burden. The action frame transmission support in brcmfmac was originally introduced with only P2P in mind. So it ended up very entwined with the P2P code. In my opinion the action frame handling should be implemented in a separate source file in the driver.

Quoted 1 line

Have a solution in mind, will send the patch for review after testing it.

Okay. Go ahead.

Gr. AvS

Quoted 21 lines
Quoted 21 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +6 -1
index 10d9d9c63..e62135cd4 100644
@@ -1559,6 +1559,12 @@ static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
         else
                 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
 
+       /* add NULL check */
+       if (!vif) {
+               brcmf_dbg(TRACE, "vif is NULL, cannot send action frame\n");
+               return -ENODEV;
+       }
+
         err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
                                         sizeof(*af_params));
         if (err) {
--

2.34.1

#23 lore raw

PATCH 1/1 wifi: brcmfmac: fix crash while sending Action Frames in standalone AP Mode

Currently, whenever there is a need to transmit an Action frame, the brcmfmac driver always uses the P2P vif to send the "actframe" IOVAR to firmware. The P2P interfaces were available when wpa_supplicant is managing the wlan interface.

However, the P2P interfaces are not created/initialized when only hostapd is managing the wlan interface. And if hostapd receives an ANQP Query REQ Action frame even from an un-associated STA, the brcmfmac driver tries to use an uninitialized P2P vif pointer for sending the IOVAR to firmware. This NULL pointer dereferencing triggers a driver crash.

 [ 1417.074538] Unable to handle kernel NULL pointer dereference at virtual
 address 0000000000000000
 [...]
 [ 1417.075188] Hardware name: Raspberry Pi 4 Model B Rev 1.5 (DT)
 [...]
 [ 1417.075653] Call trace:
 [ 1417.075662]  brcmf_p2p_send_action_frame+0x23c/0xc58 [brcmfmac]
 [ 1417.075738]  brcmf_cfg80211_mgmt_tx+0x304/0x5c0 [brcmfmac]
 [ 1417.075810]  cfg80211_mlme_mgmt_tx+0x1b0/0x428 [cfg80211]
 [ 1417.076067]  nl80211_tx_mgmt+0x238/0x388 [cfg80211]
 [ 1417.076281]  genl_family_rcv_msg_doit+0xe0/0x158
 [ 1417.076302]  genl_rcv_msg+0x220/0x2a0
 [ 1417.076317]  netlink_rcv_skb+0x68/0x140
 [ 1417.076330]  genl_rcv+0x40/0x60
 [ 1417.076343]  netlink_unicast+0x330/0x3b8
 [ 1417.076357]  netlink_sendmsg+0x19c/0x3f8
 [ 1417.076370]  __sock_sendmsg+0x64/0xc0
 [ 1417.076391]  ____sys_sendmsg+0x268/0x2a0
 [ 1417.076408]  ___sys_sendmsg+0xb8/0x118
 [ 1417.076427]  __sys_sendmsg+0x90/0xf8
 [ 1417.076445]  __arm64_sys_sendmsg+0x2c/0x40
 [ 1417.076465]  invoke_syscall+0x50/0x120
 [ 1417.076486]  el0_svc_common.constprop.0+0x48/0xf0
 [ 1417.076506]  do_el0_svc+0x24/0x38
 [ 1417.076525]  el0_svc+0x30/0x100
 [ 1417.076548]  el0t_64_sync_handler+0x100/0x130
 [ 1417.076569]  el0t_64_sync+0x190/0x198
 [ 1417.076589] Code: f9401e80 aa1603e2 f9403be1 5280e483 (f9400000)

Fix this, by always using the vif corresponding to the wdev on which the Action frame Transmission request was initiated by the userspace. This way, even if P2P vif is not available, the IOVAR is sent to firmware on AP vif and the ANQP Query RESP Action frame is transmitted without crashing the driver.

Remove init_completion() for "send_af_done" from brcmf_p2p_create_p2pdev() and do it in brcmf_p2p_tx_action_frame() instead of reinit_completion(). Because the formar function would not get executed when hostapd is managing wlan interface, and so it is not safe to do reinit_completion() without any prior init_completion().

And in the brcmf_p2p_tx_action_frame() function, the condition check for P2P Presence response frame is not needed, since the wpa_supplicant is properly sending the P2P Presense Response frame on the P2P-GO vif instead of the P2P-Device vif.

Fixes 18e2f61db3b7 ("brcmfmac: P2P action frame tx.")
---
 .../broadcom/brcm80211/brcmfmac/cfg80211.c    |  3 +-
 .../broadcom/brcm80211/brcmfmac/p2p.c         | 28 ++++++-------------
 .../broadcom/brcm80211/brcmfmac/p2p.h         |  3 +-
 3 files changed, 11 insertions(+), 23 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -2
index 8afaffe31031..bb96b87b2a6e 100644
@@ -5627,8 +5627,7 @@ brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
 			  *cookie, le16_to_cpu(action_frame->len),
 			  le32_to_cpu(af_params->channel));
 
-		ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
-						  af_params);
+		ack = brcmf_p2p_send_action_frame(vif->ifp, af_params);
 
 		cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
 					GFP_KERNEL);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +9 -19
index 0dc9d28cd77b..c7c40dc3be08 100644
@@ -1529,6 +1529,7 @@ int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
 /**
  * brcmf_p2p_tx_action_frame() - send action frame over fil.
  *
+ * @ifp: interface to transmit on.
  * @p2p: p2p info struct for vif.
  * @af_params: action frame data/info.
  *
@@ -1538,28 +1539,20 @@ int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
  * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
  * frame is transmitted.
  */
-static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
+static s32 brcmf_p2p_tx_action_frame(struct brcmf_if *ifp,
+				     struct brcmf_p2p_info *p2p,
 				     struct brcmf_fil_af_params_le *af_params)
 {
 	struct brcmf_pub *drvr = p2p->cfg->pub;
-	struct brcmf_cfg80211_vif *vif;
-	struct brcmf_p2p_action_frame *p2p_af;
 	s32 err = 0;
 
 	brcmf_dbg(TRACE, "Enter\n");
 
-	reinit_completion(&p2p->send_af_done);
+	init_completion(&p2p->send_af_done);
 	clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
 	clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
 
-	/* check if it is a p2p_presence response */
-	p2p_af = (struct brcmf_p2p_action_frame *)af_params->action_frame.data;
-	if (p2p_af->subtype == P2P_AF_PRESENCE_RSP)
-		vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
-	else
-		vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
-
-	err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
+	err = brcmf_fil_bsscfg_data_set(ifp, "actframe", af_params,
 					sizeof(*af_params));
 	if (err) {
 		bphy_err(drvr, " sending action frame has failed\n");
@@ -1711,16 +1704,14 @@ static bool brcmf_p2p_check_dwell_overflow(u32 requested_dwell,
 /**
  * brcmf_p2p_send_action_frame() - send action frame .
  *
- * @cfg: driver private data for cfg80211 interface.
- * @ndev: net device to transmit on.
+ * @ifp: interface to transmit on.
  * @af_params: configuration data for action frame.
  */
-bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
-				 struct net_device *ndev,
+bool brcmf_p2p_send_action_frame(struct brcmf_if *ifp,
 				 struct brcmf_fil_af_params_le *af_params)
 {
+	struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
 	struct brcmf_p2p_info *p2p = &cfg->p2p;
-	struct brcmf_if *ifp = netdev_priv(ndev);
 	struct brcmf_fil_action_frame_le *action_frame;
 	struct brcmf_config_af_params config_af_params;
 	struct afx_hdl *afx_hdl = &p2p->afx_hdl;
@@ -1857,7 +1848,7 @@ bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
 		if (af_params->channel)
 			msleep(P2P_AF_RETRY_DELAY_TIME);
 
-		ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
+		ack = !brcmf_p2p_tx_action_frame(ifp, p2p, af_params);
 		tx_retry++;
 		dwell_overflow = brcmf_p2p_check_dwell_overflow(requested_dwell,
 								dwell_jiffies);
@@ -2217,7 +2208,6 @@ static struct wireless_dev *brcmf_p2p_create_p2pdev(struct brcmf_p2p_info *p2p,
 
 	WARN_ON(p2p_ifp->bsscfgidx != bsscfgidx);
 
-	init_completion(&p2p->send_af_done);
 	INIT_WORK(&p2p->afx_hdl.afx_work, brcmf_p2p_afx_handler);
 	init_completion(&p2p->afx_hdl.act_frm_scan);
 	init_completion(&p2p->wait_next_af);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.h +1 -2
index d2ecee565bf2..d3137ebd7158 100644
@@ -168,8 +168,7 @@ int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp,
 int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
 					const struct brcmf_event_msg *e,
 					void *data);
-bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
-				 struct net_device *ndev,
+bool brcmf_p2p_send_action_frame(struct brcmf_if *ifp,
 				 struct brcmf_fil_af_params_le *af_params);
 bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info *cfg,
 					   struct brcmf_bss_info_le *bi);

base-commit: 94aced6ed9e2630bae0b5631e384a5302c4b6783

Signature · 1 line
2.25.1
Tested-by on v1 1/1
#24 lore raw

Re: [PATCH wireless-next] wifi: brcmfmac: fix crash while sending Action Frames in standalone AP Mode

Quoted 177 lines · Gokul Sivakumar

Currently, whenever there is a need to transmit an Action frame, the brcmfmac driver always uses the P2P vif to send the "actframe" IOVAR to firmware. The P2P interfaces were available when wpa_supplicant is managing the wlan interface.

However, the P2P interfaces are not created/initialized when only hostapd is managing the wlan interface. And if hostapd receives an ANQP Query REQ Action frame even from an un-associated STA, the brcmfmac driver tries to use an uninitialized P2P vif pointer for sending the IOVAR to firmware. This NULL pointer dereferencing triggers a driver crash.

 [ 1417.074538] Unable to handle kernel NULL pointer dereference at virtual
 address 0000000000000000
 [...]
 [ 1417.075188] Hardware name: Raspberry Pi 4 Model B Rev 1.5 (DT)
 [...]
 [ 1417.075653] Call trace:
 [ 1417.075662]  brcmf_p2p_send_action_frame+0x23c/0xc58 [brcmfmac]
 [ 1417.075738]  brcmf_cfg80211_mgmt_tx+0x304/0x5c0 [brcmfmac]
 [ 1417.075810]  cfg80211_mlme_mgmt_tx+0x1b0/0x428 [cfg80211]
 [ 1417.076067]  nl80211_tx_mgmt+0x238/0x388 [cfg80211]
 [ 1417.076281]  genl_family_rcv_msg_doit+0xe0/0x158
 [ 1417.076302]  genl_rcv_msg+0x220/0x2a0
 [ 1417.076317]  netlink_rcv_skb+0x68/0x140
 [ 1417.076330]  genl_rcv+0x40/0x60
 [ 1417.076343]  netlink_unicast+0x330/0x3b8
 [ 1417.076357]  netlink_sendmsg+0x19c/0x3f8
 [ 1417.076370]  __sock_sendmsg+0x64/0xc0
 [ 1417.076391]  ____sys_sendmsg+0x268/0x2a0
 [ 1417.076408]  ___sys_sendmsg+0xb8/0x118
 [ 1417.076427]  __sys_sendmsg+0x90/0xf8
 [ 1417.076445]  __arm64_sys_sendmsg+0x2c/0x40
 [ 1417.076465]  invoke_syscall+0x50/0x120
 [ 1417.076486]  el0_svc_common.constprop.0+0x48/0xf0
 [ 1417.076506]  do_el0_svc+0x24/0x38
 [ 1417.076525]  el0_svc+0x30/0x100
 [ 1417.076548]  el0t_64_sync_handler+0x100/0x130
 [ 1417.076569]  el0t_64_sync+0x190/0x198
 [ 1417.076589] Code: f9401e80 aa1603e2 f9403be1 5280e483 (f9400000)

Fix this, by always using the vif corresponding to the wdev on which the Action frame Transmission request was initiated by the userspace. This way, even if P2P vif is not available, the IOVAR is sent to firmware on AP vif and the ANQP Query RESP Action frame is transmitted without crashing the driver.

Remove init_completion() for "send_af_done" from brcmf_p2p_create_p2pdev() and do it in brcmf_p2p_tx_action_frame() instead of reinit_completion(). Because the formar function would not get executed when hostapd is managing wlan interface, and so it is not safe to do reinit_completion() without any prior init_completion().

And in the brcmf_p2p_tx_action_frame() function, the condition check for P2P Presence response frame is not needed, since the wpa_supplicant is properly sending the P2P Presense Response frame on the P2P-GO vif instead of the P2P-Device vif.

Fixes 18e2f61db3b7 ("brcmfmac: P2P action frame tx.")
---
 .../broadcom/brcm80211/brcmfmac/cfg80211.c    |  3 +-
 .../broadcom/brcm80211/brcmfmac/p2p.c         | 28 ++++++-------------
 .../broadcom/brcm80211/brcmfmac/p2p.h         |  3 +-
 3 files changed, 11 insertions(+), 23 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -2
index 8afaffe31031..bb96b87b2a6e 100644
@@ -5627,8 +5627,7 @@ brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
                          *cookie, le16_to_cpu(action_frame->len),
                          le32_to_cpu(af_params->channel));
 
-               ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
-                                                 af_params);
+               ack = brcmf_p2p_send_action_frame(vif->ifp, af_params);
 
                cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
                                        GFP_KERNEL);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +9 -19
index 0dc9d28cd77b..c7c40dc3be08 100644
@@ -1529,6 +1529,7 @@ int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
 /**
  * brcmf_p2p_tx_action_frame() - send action frame over fil.
  *
+ * @ifp: interface to transmit on.
  * @p2p: p2p info struct for vif.
  * @af_params: action frame data/info.
  *
@@ -1538,28 +1539,20 @@ int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
  * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
  * frame is transmitted.
  */
-static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
+static s32 brcmf_p2p_tx_action_frame(struct brcmf_if *ifp,
+                                    struct brcmf_p2p_info *p2p,
                                     struct brcmf_fil_af_params_le *af_params)
 {
        struct brcmf_pub *drvr = p2p->cfg->pub;
-       struct brcmf_cfg80211_vif *vif;
-       struct brcmf_p2p_action_frame *p2p_af;
        s32 err = 0;
 
        brcmf_dbg(TRACE, "Enter\n");
 
-       reinit_completion(&p2p->send_af_done);
+       init_completion(&p2p->send_af_done);
        clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
        clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
 
-       /* check if it is a p2p_presence response */
-       p2p_af = (struct brcmf_p2p_action_frame *)af_params->action_frame.data;
-       if (p2p_af->subtype == P2P_AF_PRESENCE_RSP)
-               vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
-       else
-               vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
-
-       err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
+       err = brcmf_fil_bsscfg_data_set(ifp, "actframe", af_params,
                                        sizeof(*af_params));
        if (err) {
                bphy_err(drvr, " sending action frame has failed\n");
@@ -1711,16 +1704,14 @@ static bool brcmf_p2p_check_dwell_overflow(u32 requested_dwell,
 /**
  * brcmf_p2p_send_action_frame() - send action frame .
  *
- * @cfg: driver private data for cfg80211 interface.
- * @ndev: net device to transmit on.
+ * @ifp: interface to transmit on.
  * @af_params: configuration data for action frame.
  */
-bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
-                                struct net_device *ndev,
+bool brcmf_p2p_send_action_frame(struct brcmf_if *ifp,
                                 struct brcmf_fil_af_params_le *af_params)
 {
+       struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
        struct brcmf_p2p_info *p2p = &cfg->p2p;
-       struct brcmf_if *ifp = netdev_priv(ndev);
        struct brcmf_fil_action_frame_le *action_frame;
        struct brcmf_config_af_params config_af_params;
        struct afx_hdl *afx_hdl = &p2p->afx_hdl;
@@ -1857,7 +1848,7 @@ bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
                if (af_params->channel)
                        msleep(P2P_AF_RETRY_DELAY_TIME);
 
-               ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
+               ack = !brcmf_p2p_tx_action_frame(ifp, p2p, af_params);
                tx_retry++;
                dwell_overflow = brcmf_p2p_check_dwell_overflow(requested_dwell,
                                                                dwell_jiffies);
@@ -2217,7 +2208,6 @@ static struct wireless_dev *brcmf_p2p_create_p2pdev(struct brcmf_p2p_info *p2p,
 
        WARN_ON(p2p_ifp->bsscfgidx != bsscfgidx);
 
-       init_completion(&p2p->send_af_done);
        INIT_WORK(&p2p->afx_hdl.afx_work, brcmf_p2p_afx_handler);
        init_completion(&p2p->afx_hdl.act_frm_scan);
        init_completion(&p2p->wait_next_af);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.h +1 -2
index d2ecee565bf2..d3137ebd7158 100644
@@ -168,8 +168,7 @@ int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp,
 int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
                                        const struct brcmf_event_msg *e,
                                        void *data);
-bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
-                                struct net_device *ndev,
+bool brcmf_p2p_send_action_frame(struct brcmf_if *ifp,
                                 struct brcmf_fil_af_params_le *af_params);
 bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info *cfg,
                                           struct brcmf_bss_info_le *bi);
Quoted 3 lines

base-commit: 94aced6ed9e2630bae0b5631e384a5302c4b6783 --
2.25.1

Hi Gokul,

I tested your patch on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+ and can confirm it fixes the crash. The iPhone now successfully queries network information without causing a NULL pointer dereference.

Best regards,
Richard

maintainer
#25 lore raw

Re: [PATCH wireless-next] wifi: brcmfmac: fix crash while sending Action Frames in standalone AP Mode

Quoted 13 lines · Richard Reigh
Quoted 11 lines · Gokul Sivakumar

Currently, whenever there is a need to transmit an Action frame, the brcmfmac driver always uses the P2P vif to send the "actframe" IOVAR to firmware. The P2P interfaces were available when wpa_supplicant is managing the wlan interface.

However, the P2P interfaces are not created/initialized when only hostapd is managing the wlan interface. And if hostapd receives an ANQP Query REQ Action frame even from an un-associated STA, the brcmfmac driver tries to use an uninitialized P2P vif pointer for sending the IOVAR to firmware. This NULL pointer dereferencing triggers a driver crash.

[...]

Quoted 10 lines
Quoted 8 lines

+bool brcmf_p2p_send_action_frame(struct brcmf_if *ifp,

                                  struct brcmf_fil_af_params_le *af_params);
  bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info *cfg,
                                            struct brcmf_bss_info_le *bi);

base-commit: 94aced6ed9e2630bae0b5631e384a5302c4b6783 --
2.25.1

Quoted 8 lines

Hi Gokul,

I tested your patch on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+ and can confirm it fixes the crash. The iPhone now successfully queries network information without causing a NULL pointer dereference.

Hi Richard,

Thanks for testing the patch.

Regards,
Arend

maintainer
#26 lore raw

Re: [PATCH wireless-next] wifi: brcmfmac: fix crash while sending Action Frames in standalone AP Mode

In reply to Gokul Sivakumar
Quoted 52 lines · Gokul Sivakumar

Currently, whenever there is a need to transmit an Action frame, the brcmfmac driver always uses the P2P vif to send the "actframe" IOVAR to firmware. The P2P interfaces were available when wpa_supplicant is managing the wlan interface.

However, the P2P interfaces are not created/initialized when only hostapd is managing the wlan interface. And if hostapd receives an ANQP Query REQ Action frame even from an un-associated STA, the brcmfmac driver tries to use an uninitialized P2P vif pointer for sending the IOVAR to firmware. This NULL pointer dereferencing triggers a driver crash.

  [ 1417.074538] Unable to handle kernel NULL pointer dereference at virtual
  address 0000000000000000
  [...]
  [ 1417.075188] Hardware name: Raspberry Pi 4 Model B Rev 1.5 (DT)
  [...]
  [ 1417.075653] Call trace:
  [ 1417.075662]  brcmf_p2p_send_action_frame+0x23c/0xc58 [brcmfmac]
  [ 1417.075738]  brcmf_cfg80211_mgmt_tx+0x304/0x5c0 [brcmfmac]
  [ 1417.075810]  cfg80211_mlme_mgmt_tx+0x1b0/0x428 [cfg80211]
  [ 1417.076067]  nl80211_tx_mgmt+0x238/0x388 [cfg80211]
  [ 1417.076281]  genl_family_rcv_msg_doit+0xe0/0x158
  [ 1417.076302]  genl_rcv_msg+0x220/0x2a0
  [ 1417.076317]  netlink_rcv_skb+0x68/0x140
  [ 1417.076330]  genl_rcv+0x40/0x60
  [ 1417.076343]  netlink_unicast+0x330/0x3b8
  [ 1417.076357]  netlink_sendmsg+0x19c/0x3f8
  [ 1417.076370]  __sock_sendmsg+0x64/0xc0
  [ 1417.076391]  ____sys_sendmsg+0x268/0x2a0
  [ 1417.076408]  ___sys_sendmsg+0xb8/0x118
  [ 1417.076427]  __sys_sendmsg+0x90/0xf8
  [ 1417.076445]  __arm64_sys_sendmsg+0x2c/0x40
  [ 1417.076465]  invoke_syscall+0x50/0x120
  [ 1417.076486]  el0_svc_common.constprop.0+0x48/0xf0
  [ 1417.076506]  do_el0_svc+0x24/0x38
  [ 1417.076525]  el0_svc+0x30/0x100
  [ 1417.076548]  el0t_64_sync_handler+0x100/0x130
  [ 1417.076569]  el0t_64_sync+0x190/0x198
  [ 1417.076589] Code: f9401e80 aa1603e2 f9403be1 5280e483 (f9400000)

Fix this, by always using the vif corresponding to the wdev on which the Action frame Transmission request was initiated by the userspace. This way, even if P2P vif is not available, the IOVAR is sent to firmware on AP vif and the ANQP Query RESP Action frame is transmitted without crashing the driver.

Remove init_completion() for "send_af_done" from brcmf_p2p_create_p2pdev() and do it in brcmf_p2p_tx_action_frame() instead of reinit_completion(). Because the formar function would not get executed when hostapd is managing wlan interface, and so it is not safe to do reinit_completion() without any prior init_completion().

Quoted 4 lines

And in the brcmf_p2p_tx_action_frame() function, the condition check for P2P Presence response frame is not needed, since the wpa_supplicant is properly sending the P2P Presense Response frame on the P2P-GO vif instead of the P2P-Device vif.

Thanks, Gokul

Looks good. Respecting the vif provided by userspace is a better approach. So the actual issue is that hostapd does not create the P2P-Device interface, which is why I suggested to fallback on the primary vif. Overlooked the fact that we are doing a init_completion() in brcmf_p2p_create_p2pdev() which is needed for the action frame transmit. I have some comment on theat init_completion() change you made (see below).

Still would prefer to move the action frame transmit (afx) functionality out of the p2p source file, but that can be a separate rework.

Regards,
Arend

Quoted 7 lines
Fixes 18e2f61db3b7 ("brcmfmac: P2P action frame tx.")
---
  .../broadcom/brcm80211/brcmfmac/cfg80211.c    |  3 +-
  .../broadcom/brcm80211/brcmfmac/p2p.c         | 28 ++++++-------------
  .../broadcom/brcm80211/brcmfmac/p2p.h         |  3 +-
  3 files changed, 11 insertions(+), 23 deletions(-)

[...]

Quoted 4 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
index 0dc9d28cd77b..c7c40dc3be08 100644

[...]

Quoted 8 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +2 -1
@@ -1538,28 +1539,20 @@ int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
   * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
   * frame is transmitted.
   */
-static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
+static s32 brcmf_p2p_tx_action_frame(struct brcmf_if *ifp,
+				     struct brcmf_p2p_info *p2p,
  				     struct brcmf_fil_af_params_le *af_params)

drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp, · line 1551

Quoted 10 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +1 -3
  {
  	struct brcmf_pub *drvr = p2p->cfg->pub;
-	struct brcmf_cfg80211_vif *vif;
-	struct brcmf_p2p_action_frame *p2p_af;
  	s32 err = 0;
 
  	brcmf_dbg(TRACE, "Enter\n");
 
-	reinit_completion(&p2p->send_af_done);
+	init_completion(&p2p->send_af_done);

I think we should not do this here. It used to be init_completion() here but the kernel API changed introducing the reinit_completion() to make explicit distinction between init and reinit. So I would suggest to do the init_completion() in brcmf_p2p_attach() which is always invoked and leave the reinit_completion() here.

Quoted 2 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
  	clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
  	clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
#27 lore raw

Re: [PATCH wireless-next] wifi: brcmfmac: fix crash while sending Action Frames in standalone AP Mode

Quoted 68 lines · Arend van Spriel
Quoted 52 lines · Gokul Sivakumar

Currently, whenever there is a need to transmit an Action frame, the brcmfmac driver always uses the P2P vif to send the "actframe" IOVAR to firmware. The P2P interfaces were available when wpa_supplicant is managing the wlan interface.

However, the P2P interfaces are not created/initialized when only hostapd is managing the wlan interface. And if hostapd receives an ANQP Query REQ Action frame even from an un-associated STA, the brcmfmac driver tries to use an uninitialized P2P vif pointer for sending the IOVAR to firmware. This NULL pointer dereferencing triggers a driver crash.

  [ 1417.074538] Unable to handle kernel NULL pointer dereference at virtual
  address 0000000000000000
  [...]
  [ 1417.075188] Hardware name: Raspberry Pi 4 Model B Rev 1.5 (DT)
  [...]
  [ 1417.075653] Call trace:
  [ 1417.075662]  brcmf_p2p_send_action_frame+0x23c/0xc58 [brcmfmac]
  [ 1417.075738]  brcmf_cfg80211_mgmt_tx+0x304/0x5c0 [brcmfmac]
  [ 1417.075810]  cfg80211_mlme_mgmt_tx+0x1b0/0x428 [cfg80211]
  [ 1417.076067]  nl80211_tx_mgmt+0x238/0x388 [cfg80211]
  [ 1417.076281]  genl_family_rcv_msg_doit+0xe0/0x158
  [ 1417.076302]  genl_rcv_msg+0x220/0x2a0
  [ 1417.076317]  netlink_rcv_skb+0x68/0x140
  [ 1417.076330]  genl_rcv+0x40/0x60
  [ 1417.076343]  netlink_unicast+0x330/0x3b8
  [ 1417.076357]  netlink_sendmsg+0x19c/0x3f8
  [ 1417.076370]  __sock_sendmsg+0x64/0xc0
  [ 1417.076391]  ____sys_sendmsg+0x268/0x2a0
  [ 1417.076408]  ___sys_sendmsg+0xb8/0x118
  [ 1417.076427]  __sys_sendmsg+0x90/0xf8
  [ 1417.076445]  __arm64_sys_sendmsg+0x2c/0x40
  [ 1417.076465]  invoke_syscall+0x50/0x120
  [ 1417.076486]  el0_svc_common.constprop.0+0x48/0xf0
  [ 1417.076506]  do_el0_svc+0x24/0x38
  [ 1417.076525]  el0_svc+0x30/0x100
  [ 1417.076548]  el0t_64_sync_handler+0x100/0x130
  [ 1417.076569]  el0t_64_sync+0x190/0x198
  [ 1417.076589] Code: f9401e80 aa1603e2 f9403be1 5280e483 (f9400000)

Fix this, by always using the vif corresponding to the wdev on which the Action frame Transmission request was initiated by the userspace. This way, even if P2P vif is not available, the IOVAR is sent to firmware on AP vif and the ANQP Query RESP Action frame is transmitted without crashing the driver.

Remove init_completion() for "send_af_done" from brcmf_p2p_create_p2pdev() and do it in brcmf_p2p_tx_action_frame() instead of reinit_completion(). Because the formar function would not get executed when hostapd is managing wlan interface, and so it is not safe to do reinit_completion() without any prior init_completion().

Quoted 4 lines

And in the brcmf_p2p_tx_action_frame() function, the condition check for P2P Presence response frame is not needed, since the wpa_supplicant is properly sending the P2P Presense Response frame on the P2P-GO vif instead of the P2P-Device vif.

Thanks, Gokul

Looks good. Respecting the vif provided by userspace is a better approach. So the actual issue is that hostapd does not create the P2P-Device interface, which is why I suggested to fallback on the primary vif. Overlooked the fact that we are doing a init_completion() in brcmf_p2p_create_p2pdev() which is needed for the action frame transmit. I have some comment on theat init_completion() change you made (see below).

Quoted 2 lines

Still would prefer to move the action frame transmit (afx) functionality out of the p2p source file, but that can be a separate rework.

I agree. The action frame transmission funcationality should properly work for STA and AP mode, irrespective of P2P being enabled/disabled. So this functionality needs to be cleaned up.

Quoted 32 lines
Quoted 7 lines
Fixes 18e2f61db3b7 ("brcmfmac: P2P action frame tx.")
---
  .../broadcom/brcm80211/brcmfmac/cfg80211.c    |  3 +-
  .../broadcom/brcm80211/brcmfmac/p2p.c         | 28 ++++++-------------
  .../broadcom/brcm80211/brcmfmac/p2p.h         |  3 +-
  3 files changed, 11 insertions(+), 23 deletions(-)

[...]

Quoted 4 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +0 -0
index 0dc9d28cd77b..c7c40dc3be08 100644

[...]

Quoted 16 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +2 -3
@@ -1538,28 +1539,20 @@ int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
   * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
   * frame is transmitted.
   */
-static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
+static s32 brcmf_p2p_tx_action_frame(struct brcmf_if *ifp,
+                                  struct brcmf_p2p_info *p2p,
                                   struct brcmf_fil_af_params_le *af_params)
  {
      struct brcmf_pub *drvr = p2p->cfg->pub;
-     struct brcmf_cfg80211_vif *vif;
-     struct brcmf_p2p_action_frame *p2p_af;
      s32 err = 0;
 
      brcmf_dbg(TRACE, "Enter\n");
 
Quoted 8 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp, · line 1551

Quoted 2 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +1 -1
-     reinit_completion(&p2p->send_af_done);
+     init_completion(&p2p->send_af_done);

I think we should not do this here. It used to be init_completion() here but the kernel API changed introducing the reinit_completion() to make explicit distinction between init and reinit. So I would suggest to do the init_completion() in brcmf_p2p_attach() which is always invoked and leave the reinit_completion() here.

That works too. Will create an updated v2 patch after making this change and submit it for the wireless tree instead of wireless-next.

maintainer
#28 lore raw

Re: [PATCH wireless-next] wifi: brcmfmac: fix crash while sending Action Frames in standalone AP Mode

Quoted 9 lines · Gokul Sivakumar
Quoted 7 lines

drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp, · line 1551

Quoted 2 lines
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +1 -1
-     reinit_completion(&p2p->send_af_done);
+     init_completion(&p2p->send_af_done);

I think we should not do this here. It used to be init_completion() here but the kernel API changed introducing the reinit_completion() to make explicit distinction between init and reinit. So I would suggest to do the init_completion() in brcmf_p2p_attach() which is always invoked and leave the reinit_completion() here.

That works too. Will create an updated v2 patch after making this change and submit it for the wireless tree instead of wireless-next.

Great.

Thanks,
Arend

#29 lore raw

PATCH v2 1/1 wifi: brcmfmac: fix crash while sending Action Frames in standalone AP Mode

Currently, whenever there is a need to transmit an Action frame, the brcmfmac driver always uses the P2P vif to send the "actframe" IOVAR to firmware. The P2P interfaces were available when wpa_supplicant is managing the wlan interface.

However, the P2P interfaces are not created/initialized when only hostapd is managing the wlan interface. And if hostapd receives an ANQP Query REQ Action frame even from an un-associated STA, the brcmfmac driver tries to use an uninitialized P2P vif pointer for sending the IOVAR to firmware. This NULL pointer dereferencing triggers a driver crash.

 [ 1417.074538] Unable to handle kernel NULL pointer dereference at virtual
 address 0000000000000000
 [...]
 [ 1417.075188] Hardware name: Raspberry Pi 4 Model B Rev 1.5 (DT)
 [...]
 [ 1417.075653] Call trace:
 [ 1417.075662]  brcmf_p2p_send_action_frame+0x23c/0xc58 [brcmfmac]
 [ 1417.075738]  brcmf_cfg80211_mgmt_tx+0x304/0x5c0 [brcmfmac]
 [ 1417.075810]  cfg80211_mlme_mgmt_tx+0x1b0/0x428 [cfg80211]
 [ 1417.076067]  nl80211_tx_mgmt+0x238/0x388 [cfg80211]
 [ 1417.076281]  genl_family_rcv_msg_doit+0xe0/0x158
 [ 1417.076302]  genl_rcv_msg+0x220/0x2a0
 [ 1417.076317]  netlink_rcv_skb+0x68/0x140
 [ 1417.076330]  genl_rcv+0x40/0x60
 [ 1417.076343]  netlink_unicast+0x330/0x3b8
 [ 1417.076357]  netlink_sendmsg+0x19c/0x3f8
 [ 1417.076370]  __sock_sendmsg+0x64/0xc0
 [ 1417.076391]  ____sys_sendmsg+0x268/0x2a0
 [ 1417.076408]  ___sys_sendmsg+0xb8/0x118
 [ 1417.076427]  __sys_sendmsg+0x90/0xf8
 [ 1417.076445]  __arm64_sys_sendmsg+0x2c/0x40
 [ 1417.076465]  invoke_syscall+0x50/0x120
 [ 1417.076486]  el0_svc_common.constprop.0+0x48/0xf0
 [ 1417.076506]  do_el0_svc+0x24/0x38
 [ 1417.076525]  el0_svc+0x30/0x100
 [ 1417.076548]  el0t_64_sync_handler+0x100/0x130
 [ 1417.076569]  el0t_64_sync+0x190/0x198
 [ 1417.076589] Code: f9401e80 aa1603e2 f9403be1 5280e483 (f9400000)

Fix this, by always using the vif corresponding to the wdev on which the Action frame Transmission request was initiated by the userspace. This way, even if P2P vif is not available, the IOVAR is sent to firmware on AP vif and the ANQP Query RESP Action frame is transmitted without crashing the driver.

Move init_completion() for "send_af_done" from brcmf_p2p_create_p2pdev() to brcmf_p2p_attach(). Because the former function would not get executed when only hostapd is managing wlan interface, and it is not safe to do reinit_completion() later in brcmf_p2p_tx_action_frame(), without any prior init_completion().

And in the brcmf_p2p_tx_action_frame() function, the condition check for P2P Presence response frame is not needed, since the wpa_supplicant is properly sending the P2P Presense Response frame on the P2P-GO vif instead of the P2P-Device vif.

Fixes 18e2f61db3b7 ("brcmfmac: P2P action frame tx")

---

v2:
- Retain the reinit_completion() for "senf_af_done" in existing function brcmf_p2p_tx_action_frame(). And move the init_completion() from brcmf_p2p_create_p2pdev() to the brcmf_p2p_attach() function.

 .../broadcom/brcm80211/brcmfmac/cfg80211.c    |  3 +-
 .../broadcom/brcm80211/brcmfmac/p2p.c         | 28 +++++++------------
 .../broadcom/brcm80211/brcmfmac/p2p.h         |  3 +-
 3 files changed, 12 insertions(+), 22 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +1 -2
index 8af402555b5e..f57f3efa9b36 100644
@@ -5627,8 +5627,7 @@ brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
 			  *cookie, le16_to_cpu(action_frame->len),
 			  le32_to_cpu(af_params->channel));
 
-		ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
-						  af_params);
+		ack = brcmf_p2p_send_action_frame(vif->ifp, af_params);
 
 		cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
 					GFP_KERNEL);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +10 -18
index 0dc9d28cd77b..e1752a513c73 100644
@@ -1529,6 +1529,7 @@ int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
 /**
  * brcmf_p2p_tx_action_frame() - send action frame over fil.
  *
+ * @ifp: interface to transmit on.
  * @p2p: p2p info struct for vif.
  * @af_params: action frame data/info.
  *
@@ -1538,12 +1539,11 @@ int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
  * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
  * frame is transmitted.
  */
-static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
+static s32 brcmf_p2p_tx_action_frame(struct brcmf_if *ifp,
+				     struct brcmf_p2p_info *p2p,
 				     struct brcmf_fil_af_params_le *af_params)
 {
 	struct brcmf_pub *drvr = p2p->cfg->pub;
-	struct brcmf_cfg80211_vif *vif;
-	struct brcmf_p2p_action_frame *p2p_af;
 	s32 err = 0;
 
 	brcmf_dbg(TRACE, "Enter\n");
@@ -1552,14 +1552,7 @@ static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
 	clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
 	clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
 
-	/* check if it is a p2p_presence response */
-	p2p_af = (struct brcmf_p2p_action_frame *)af_params->action_frame.data;
-	if (p2p_af->subtype == P2P_AF_PRESENCE_RSP)
-		vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
-	else
-		vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
-
-	err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
+	err = brcmf_fil_bsscfg_data_set(ifp, "actframe", af_params,
 					sizeof(*af_params));
 	if (err) {
 		bphy_err(drvr, " sending action frame has failed\n");
@@ -1711,16 +1704,14 @@ static bool brcmf_p2p_check_dwell_overflow(u32 requested_dwell,
 /**
  * brcmf_p2p_send_action_frame() - send action frame .
  *
- * @cfg: driver private data for cfg80211 interface.
- * @ndev: net device to transmit on.
+ * @ifp: interface to transmit on.
  * @af_params: configuration data for action frame.
  */
-bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
-				 struct net_device *ndev,
+bool brcmf_p2p_send_action_frame(struct brcmf_if *ifp,
 				 struct brcmf_fil_af_params_le *af_params)
 {
+	struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
 	struct brcmf_p2p_info *p2p = &cfg->p2p;
-	struct brcmf_if *ifp = netdev_priv(ndev);
 	struct brcmf_fil_action_frame_le *action_frame;
 	struct brcmf_config_af_params config_af_params;
 	struct afx_hdl *afx_hdl = &p2p->afx_hdl;
@@ -1857,7 +1848,7 @@ bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
 		if (af_params->channel)
 			msleep(P2P_AF_RETRY_DELAY_TIME);
 
-		ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
+		ack = !brcmf_p2p_tx_action_frame(ifp, p2p, af_params);
 		tx_retry++;
 		dwell_overflow = brcmf_p2p_check_dwell_overflow(requested_dwell,
 								dwell_jiffies);
@@ -2217,7 +2208,6 @@ static struct wireless_dev *brcmf_p2p_create_p2pdev(struct brcmf_p2p_info *p2p,
 
 	WARN_ON(p2p_ifp->bsscfgidx != bsscfgidx);
 
-	init_completion(&p2p->send_af_done);
 	INIT_WORK(&p2p->afx_hdl.afx_work, brcmf_p2p_afx_handler);
 	init_completion(&p2p->afx_hdl.act_frm_scan);
 	init_completion(&p2p->wait_next_af);
@@ -2513,6 +2503,8 @@ s32 brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg, bool p2pdev_forced)
 	pri_ifp = brcmf_get_ifp(cfg->pub, 0);
 	p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif = pri_ifp->vif;
 
+	init_completion(&p2p->send_af_done);
+
 	if (p2pdev_forced) {
 		err_ptr = brcmf_p2p_create_p2pdev(p2p, NULL, NULL);
 		if (IS_ERR(err_ptr)) {
drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.h +1 -2
index d2ecee565bf2..d3137ebd7158 100644
@@ -168,8 +168,7 @@ int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp,
 int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
 					const struct brcmf_event_msg *e,
 					void *data);
-bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
-				 struct net_device *ndev,
+bool brcmf_p2p_send_action_frame(struct brcmf_if *ifp,
 				 struct brcmf_fil_af_params_le *af_params);
 bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info *cfg,
 					   struct brcmf_bss_info_le *bi);

base-commit: 4ff71af020ae59ae2d83b174646fc2ad9fcd4dc4

Signature · 1 line
2.25.1
maintainer Acked-by on v2 1/1
#30 lore raw

Re: [PATCH wireless v2] wifi: brcmfmac: fix crash while sending Action Frames in standalone AP Mode

Quoted 13 lines · Gokul Sivakumar

Currently, whenever there is a need to transmit an Action frame, the brcmfmac driver always uses the P2P vif to send the "actframe" IOVAR to firmware. The P2P interfaces were available when wpa_supplicant is managing the wlan interface.

However, the P2P interfaces are not created/initialized when only hostapd is managing the wlan interface. And if hostapd receives an ANQP Query REQ Action frame even from an un-associated STA, the brcmfmac driver tries to use an uninitialized P2P vif pointer for sending the IOVAR to firmware. This NULL pointer dereferencing triggers a driver crash.

  [ 1417.074538] Unable to handle kernel NULL pointer dereference at virtual
  address 0000000000000000

[...]

Quoted 2 lines
Fixes 18e2f61db3b7 ("brcmfmac: P2P action frame tx")
Quoted 12 lines

---

v2:
- Retain the reinit_completion() for "senf_af_done" in existing function brcmf_p2p_tx_action_frame(). And move the init_completion() from brcmf_p2p_create_p2pdev() to the brcmf_p2p_attach() function.

  .../broadcom/brcm80211/brcmfmac/cfg80211.c    |  3 +-
  .../broadcom/brcm80211/brcmfmac/p2p.c         | 28 +++++++------------
  .../broadcom/brcm80211/brcmfmac/p2p.h         |  3 +-
  3 files changed, 12 insertions(+), 22 deletions(-)
maintainer
#31 lore raw

Re: [PATCH wireless-next] wifi: brcmfmac: fix crash while sending Action Frames in standalone AP Mode

In reply to Gokul Sivakumar
Quoted 10 lines · Gokul Sivakumar

Currently, whenever there is a need to transmit an Action frame, the brcmfmac driver always uses the P2P vif to send the "actframe" IOVAR to firmware. The P2P interfaces were available when wpa_supplicant is managing the wlan interface.

However, the P2P interfaces are not created/initialized when only hostapd is managing the wlan interface. And if hostapd receives an ANQP Query REQ Action frame even from an un-associated STA, the brcmfmac driver tries to use an uninitialized P2P vif pointer for sending the IOVAR to firmware. This NULL pointer dereferencing triggers a driver crash.

Hi Gokul,

One more thing. I think the crash warrants that this patch is submitted against the wireless tree iso wireless-next.

Gr. AvS

maintainer
#32 lore raw

Re: [PATCH v2] brcmfmac: Fix NULL pointer dereference in P2P action frame handling

In reply to Richard Reigh
Quoted 10 lines · Richard Reigh

When iPhones query network information via the WiFi settings "i" button, the brcmfmac driver crashes with a NULL pointer dereference. This occurs because the P2P device vif is not initialized when handling certain action frames.

Added an early check in brcmf_cfg80211_mgmt_tx() to verify P2P device vif availability before attepting to send action frames. Also added a defensive check in brcmf_p2p_tx_action_frame() as a safety net.

Tested on Raspberry Pi Zero 2 W with kernel 6.1.21-v8+

Hi, Richard

Thanks for sending the patch and putting us on the right track to fix this issue. Very much appreciated. As you may agree the proposed fix from Gokul is preferred. So I will drop this patch.

Regards,
Arend