diff options
author | Johannes Berg <johannes.berg@intel.com> | 2018-05-18 11:40:44 +0200 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2018-05-18 12:37:55 +0200 |
commit | 7ea3e110f2f8ba23f330c2f702f556acd539bcb8 (patch) | |
tree | 8619eac094435ad790ee411991a3a4bd8f69f5b4 | |
parent | 0fdf1493b41eb64fc7e8c8e1b8830a4bd8c4bbca (diff) |
cfg80211: release station info tidstats where needed
This fixes memory leaks in cases where we got the station
info but failed sending it out properly.
Fixes: 8689c051a201 ("cfg80211: dynamically allocate per-tid stats for station info")
Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
-rw-r--r-- | include/net/cfg80211.h | 13 | ||||
-rw-r--r-- | net/wireless/nl80211.c | 11 |
2 files changed, 21 insertions, 3 deletions
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 8984d24d68b7..11a218445448 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -5711,6 +5711,19 @@ void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, int cfg80211_sinfo_alloc_tid_stats(struct station_info *sinfo, gfp_t gfp); /** + * cfg80211_sinfo_release_content - release contents of station info + * @sinfo: the station information + * + * Releases any potentially allocated sub-information of the station + * information, but not the struct itself (since it's typically on + * the stack.) + */ +static inline void cfg80211_sinfo_release_content(struct station_info *sinfo) +{ + kfree(sinfo->pertid); +} + +/** * cfg80211_new_sta - notify userspace about station * * @dev: the netdev diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 7daceb1f253d..e4a52a2b5e65 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -4702,7 +4702,6 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, } nla_nest_end(msg, tidsattr); - kfree(sinfo->pertid); } nla_nest_end(msg, sinfoattr); @@ -4712,10 +4711,12 @@ static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, sinfo->assoc_req_ies)) goto nla_put_failure; + cfg80211_sinfo_release_content(sinfo); genlmsg_end(msg, hdr); return 0; nla_put_failure: + cfg80211_sinfo_release_content(sinfo); genlmsg_cancel(msg, hdr); return -EMSGSIZE; } @@ -4797,8 +4798,10 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) return err; msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) + if (!msg) { + cfg80211_sinfo_release_content(sinfo); return -ENOMEM; + } if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, info->snd_portid, info->snd_seq, 0, @@ -14624,8 +14627,10 @@ void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, trace_cfg80211_del_sta(dev, mac_addr); msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); - if (!msg) + if (!msg) { + cfg80211_sinfo_release_content(sinfo); return; + } if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, rdev, dev, mac_addr, sinfo) < 0) { |