Skip to content

Commit fd1e716

Browse files
committed
wifi: cfg80211: fix double free for link_sinfo in nl80211_station_dump()
JIRA: https://issues.redhat.com/browse/RHEL-114891 commit 9a44b5e Author: Sarika Sharma <quic_sarishar@quicinc.com> Date: Mon Jul 14 14:14:05 2025 +0530 wifi: cfg80211: fix double free for link_sinfo in nl80211_station_dump() Currently, the link_sinfo structure is being freed twice in nl80211_dump_station(), once after the send_station() call and again in the error handling path. This results in a double free of both link_sinfo and link_sinfo->pertid, which might lead to undefined behavior or kernel crashes. Hence, fix by ensuring cfg80211_sinfo_release_content() is only invoked once during execution of nl80211_station_dump(). Fixes: 49e4722 ("wifi: cfg80211: allocate memory for link_station info structure") Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/all/81f30515-a83d-4b05-a9d1-e349969df9e9@sabinyo.mountain/ Reported-by: syzbot+4ba6272678aa468132c8@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/68655325.a70a0220.5d25f.0316.GAE@google.com Signed-off-by: Sarika Sharma <quic_sarishar@quicinc.com> Link: https://patch.msgid.link/20250714084405.178066-1-quic_sarishar@quicinc.com Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
1 parent 60adfec commit fd1e716

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

net/wireless/nl80211.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7456,6 +7456,7 @@ static int nl80211_dump_station(struct sk_buff *skb,
74567456
struct wireless_dev *wdev;
74577457
u8 mac_addr[ETH_ALEN];
74587458
int sta_idx = cb->args[2];
7459+
bool sinfo_alloc = false;
74597460
int err, i;
74607461

74617462
err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL);
@@ -7484,6 +7485,7 @@ static int nl80211_dump_station(struct sk_buff *skb,
74847485
err = -ENOMEM;
74857486
goto out_err;
74867487
}
7488+
sinfo_alloc = true;
74877489
}
74887490

74897491
err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
@@ -7496,6 +7498,11 @@ static int nl80211_dump_station(struct sk_buff *skb,
74967498
if (sinfo.valid_links)
74977499
cfg80211_sta_set_mld_sinfo(&sinfo);
74987500

7501+
/* reset the sinfo_alloc flag as nl80211_send_station()
7502+
* always releases sinfo
7503+
*/
7504+
sinfo_alloc = false;
7505+
74997506
if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
75007507
NETLINK_CB(cb->skb).portid,
75017508
cb->nlh->nlmsg_seq, NLM_F_MULTI,
@@ -7510,7 +7517,8 @@ static int nl80211_dump_station(struct sk_buff *skb,
75107517
cb->args[2] = sta_idx;
75117518
err = skb->len;
75127519
out_err:
7513-
cfg80211_sinfo_release_content(&sinfo);
7520+
if (sinfo_alloc)
7521+
cfg80211_sinfo_release_content(&sinfo);
75147522
wiphy_unlock(&rdev->wiphy);
75157523

75167524
return err;

0 commit comments

Comments
 (0)