Skip to content

Commit 65486c8

Browse files
jmberglinvjw
authored andcommitted
cfg80211: fix error path in cfg80211_wext_siwscan
If there's an invalid channel or SSID, the code leaks the scan request. Always free the scan request, unless it was successfully given to the driver. Reported-by: Dan Carpenter <error27@gmail.com> Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Acked-by: Dan Carpenter <error27@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent befabac commit 65486c8

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎net/wireless/scan.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ int cfg80211_wext_siwscan(struct net_device *dev,
601601
struct cfg80211_registered_device *rdev;
602602
struct wiphy *wiphy;
603603
struct iw_scan_req *wreq = NULL;
604-
struct cfg80211_scan_request *creq;
604+
struct cfg80211_scan_request *creq = NULL;
605605
int i, err, n_channels = 0;
606606
enum ieee80211_band band;
607607

@@ -694,8 +694,10 @@ int cfg80211_wext_siwscan(struct net_device *dev,
694694
/* translate "Scan for SSID" request */
695695
if (wreq) {
696696
if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
697-
if (wreq->essid_len > IEEE80211_MAX_SSID_LEN)
698-
return -EINVAL;
697+
if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) {
698+
err = -EINVAL;
699+
goto out;
700+
}
699701
memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len);
700702
creq->ssids[0].ssid_len = wreq->essid_len;
701703
}
@@ -707,12 +709,15 @@ int cfg80211_wext_siwscan(struct net_device *dev,
707709
err = rdev->ops->scan(wiphy, dev, creq);
708710
if (err) {
709711
rdev->scan_req = NULL;
710-
kfree(creq);
712+
/* creq will be freed below */
711713
} else {
712714
nl80211_send_scan_start(rdev, dev);
715+
/* creq now owned by driver */
716+
creq = NULL;
713717
dev_hold(dev);
714718
}
715719
out:
720+
kfree(creq);
716721
cfg80211_unlock_rdev(rdev);
717722
return err;
718723
}

0 commit comments

Comments
 (0)