mac80211_hwsim: Fix a possible sleep-in-atomic bug in hwsim_get_radio_nl
authorJia-Ju Bai <baijiaju1990@163.com>
Tue, 12 Dec 2017 09:26:36 +0000 (17:26 +0800)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 19 Dec 2017 08:14:06 +0000 (09:14 +0100)
The driver may sleep under a spinlock.
The function call path is:
hwsim_get_radio_nl (acquire the spinlock)
  nlmsg_new(GFP_KERNEL) --> may sleep

To fix it, GFP_KERNEL is replaced with GFP_ATOMIC.

This bug is found by my static analysis tool(DSAC) and checked by my code review.

Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
drivers/net/wireless/mac80211_hwsim.c

index 59b0cedcdf7b7aafd59325df4fed9d443599420b..e8189c07b41f6b450f135ef703ec4e01568e311d 100644 (file)
@@ -3216,7 +3216,7 @@ static int hwsim_get_radio_nl(struct sk_buff *msg, struct genl_info *info)
                if (!net_eq(wiphy_net(data->hw->wiphy), genl_info_net(info)))
                        continue;
 
-               skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+               skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
                if (!skb) {
                        res = -ENOMEM;
                        goto out_err;