Skip to content

Commit 7bc40ae

Browse files
committed
mac80211: free sta in sta_info_insert_finish() on errors
If sta_info_insert_finish() fails, we currently keep the station around and free it only in the caller, but there's only one such caller and it always frees it immediately. As syzbot found, another consequence of this split is that we can put things that sleep only into __cleanup_single_sta() and not in sta_info_free(), but this is the only place that requires such of sta_info_free() now. Change this to free the station in sta_info_insert_finish(), in which case we can still sleep. This will also let us unify the cleanup code later. Cc: stable@vger.kernel.org Fixes: dcd479e ("mac80211: always wind down STA state") Reported-by: syzbot+32c6c38c4812d22f2f0b@syzkaller.appspotmail.com Reported-by: syzbot+4c81fe92e372d26c4246@syzkaller.appspotmail.com Reported-by: syzbot+6a7fe9faf0d1d61bc24a@syzkaller.appspotmail.com Reported-by: syzbot+abed06851c5ffe010921@syzkaller.appspotmail.com Reported-by: syzbot+b7aeb9318541a1c709f1@syzkaller.appspotmail.com Reported-by: syzbot+d5a9416c6cafe53b5dd0@syzkaller.appspotmail.com Link: https://lore.kernel.org/r/20201112112201.ee6b397b9453.I9c31d667a0ea2151441cc64ed6613d36c18a48e0@changeid Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent b2911a8 commit 7bc40ae

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

net/mac80211/sta_info.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
705705
out_drop_sta:
706706
local->num_sta--;
707707
synchronize_net();
708-
__cleanup_single_sta(sta);
708+
cleanup_single_sta(sta);
709709
out_err:
710710
mutex_unlock(&local->sta_mtx);
711711
kfree(sinfo);
@@ -724,19 +724,13 @@ int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
724724

725725
err = sta_info_insert_check(sta);
726726
if (err) {
727+
sta_info_free(local, sta);
727728
mutex_unlock(&local->sta_mtx);
728729
rcu_read_lock();
729-
goto out_free;
730+
return err;
730731
}
731732

732-
err = sta_info_insert_finish(sta);
733-
if (err)
734-
goto out_free;
735-
736-
return 0;
737-
out_free:
738-
sta_info_free(local, sta);
739-
return err;
733+
return sta_info_insert_finish(sta);
740734
}
741735

742736
int sta_info_insert(struct sta_info *sta)

0 commit comments

Comments
 (0)