mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] wifi: p54: Fix memory leak in p54_beacon_update()
@ 2026-01-19 11:31 Zilin Guan
  2026-01-20  8:16 ` Johannes Berg
  0 siblings, 1 reply; 3+ messages in thread
From: Zilin Guan @ 2026-01-19 11:31 UTC (permalink / raw)
  To: chunkeey
  Cc: johannes.berg, quic_rdevanat, linux-wireless, linux-kernel, Zilin Guan

In p54_beacon_update(), beacon is allocated via ieee80211_beacon_get().
If p54_beacon_format_ie_tim() fails, the function returns immediately
without freeing the allocated beacon skb, leading to a memory leak.

Since no other references to this memory exist, it must be freed locally
before returning the error. Fix this by freeing the buffer using
dev_kfree_skb_any() in the error path.

Compile tested only. Issue found using a prototype static analysis tool
and code review.

Fixes: 0ac0d6cedf61 ("p54: Move mac80211 glue code")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
 drivers/net/wireless/intersil/p54/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/intersil/p54/main.c b/drivers/net/wireless/intersil/p54/main.c
index 2ec3655f1a9c..57a62108cbc3 100644
--- a/drivers/net/wireless/intersil/p54/main.c
+++ b/drivers/net/wireless/intersil/p54/main.c
@@ -143,8 +143,10 @@ static int p54_beacon_update(struct p54_common *priv,
 	if (!beacon)
 		return -ENOMEM;
 	ret = p54_beacon_format_ie_tim(beacon);
-	if (ret)
+	if (ret) {
+		dev_kfree_skb_any(beacon);
 		return ret;
+	}
 
 	/*
 	 * During operation, the firmware takes care of beaconing.
-- 
2.34.1


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

* Re: [PATCH] wifi: p54: Fix memory leak in p54_beacon_update()
  2026-01-19 11:31 [PATCH] wifi: p54: Fix memory leak in p54_beacon_update() Zilin Guan
@ 2026-01-20  8:16 ` Johannes Berg
  2026-01-20 12:47   ` Zilin Guan
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Berg @ 2026-01-20  8:16 UTC (permalink / raw)
  To: Zilin Guan, chunkeey; +Cc: quic_rdevanat, linux-wireless, linux-kernel

On Mon, 2026-01-19 at 11:31 +0000, Zilin Guan wrote:
> In p54_beacon_update(), beacon is allocated via ieee80211_beacon_get().
> If p54_beacon_format_ie_tim() fails, the function returns immediately
> without freeing the allocated beacon skb, leading to a memory leak.
> 
> Since no other references to this memory exist, it must be freed locally
> before returning the error. Fix this by freeing the buffer using
> dev_kfree_skb_any() in the error path.
> 
> Compile tested only. Issue found using a prototype static analysis tool
> and code review.
> 
> Fixes: 0ac0d6cedf61 ("p54: Move mac80211 glue code")

That doesn't seem right, although that commit didn't really "move" code,
it added unused code ... but I think that it probably could go further
back.

johannes

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

* Re: [PATCH] wifi: p54: Fix memory leak in p54_beacon_update()
  2026-01-20  8:16 ` Johannes Berg
@ 2026-01-20 12:47   ` Zilin Guan
  0 siblings, 0 replies; 3+ messages in thread
From: Zilin Guan @ 2026-01-20 12:47 UTC (permalink / raw)
  To: johannes; +Cc: chunkeey, linux-kernel, linux-wireless, quic_rdevanat, zilin

On Tue, Jan 20, 2026 at 09:16:05AM +0100, Johannes Berg wrote:
> On Mon, 2026-01-19 at 11:31 +0000, Zilin Guan wrote:
> > In p54_beacon_update(), beacon is allocated via ieee80211_beacon_get().
> > If p54_beacon_format_ie_tim() fails, the function returns immediately
> > without freeing the allocated beacon skb, leading to a memory leak.
> > 
> > Since no other references to this memory exist, it must be freed locally
> > before returning the error. Fix this by freeing the buffer using
> > dev_kfree_skb_any() in the error path.
> > 
> > Compile tested only. Issue found using a prototype static analysis tool
> > and code review.
> > 
> > Fixes: 0ac0d6cedf61 ("p54: Move mac80211 glue code")
> 
> That doesn't seem right, although that commit didn't really "move" code,
> it added unused code ... but I think that it probably could go further
> back.
> 
> johannes

Thanks for pointing this out. I traced it further back and found the issue
was introduced in commit e5ea92a7528d ("p54: AP & Ad-hoc testing").

I will update the Fixes tag and send v2.

Regards,
Zilin Guan

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

end of thread, other threads:[~2026-01-20 12:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-19 11:31 [PATCH] wifi: p54: Fix memory leak in p54_beacon_update() Zilin Guan
2026-01-20  8:16 ` Johannes Berg
2026-01-20 12:47   ` Zilin Guan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®