Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1738699

[PATCH review for 4.9 06/50] mac80211_hwsim: check HWSIM_ATTR_RADIO_NAME length

From "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
Newsgroups linux.kernel
Subject [PATCH review for 4.9 06/50] mac80211_hwsim: check HWSIM_ATTR_RADIO_NAME length
Date 2017-09-25 03:40 +0200
Message-ID <utqxl-7O2-37@gated-at.bofh.it> (permalink)
References <utqdY-7Fr-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Johannes Berg <johannes.berg@intel.com>

[ Upstream commit ff4dd73dd2b4806419f8ff65cbce11d5019548d0 ]

Unfortunately, the nla policy was defined to have HWSIM_ATTR_RADIO_NAME
as an NLA_STRING, rather than NLA_NUL_STRING, so we can't use it as a
NUL-terminated string in the kernel.

Rather than break the API, kasprintf() the string to a new buffer to
guarantee NUL termination.

Reported-by: Andrew Zaborowski <andrew.zaborowski@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
---
 drivers/net/wireless/mac80211_hwsim.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 0fd7d7ed07ce..77528d647b6e 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -3048,6 +3048,7 @@ static int hwsim_register_received_nl(struct sk_buff *skb_2,
 static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
 {
 	struct hwsim_new_radio_params param = { 0 };
+	const char *hwname = NULL;
 
 	param.reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG];
 	param.p2p_device = info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE];
@@ -3061,8 +3062,14 @@ static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
 	if (info->attrs[HWSIM_ATTR_NO_VIF])
 		param.no_vif = true;
 
-	if (info->attrs[HWSIM_ATTR_RADIO_NAME])
-		param.hwname = nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]);
+	if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
+		hwname = kasprintf(GFP_KERNEL, "%.*s",
+				   nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
+				   (char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]));
+		if (!hwname)
+			return -ENOMEM;
+		param.hwname = hwname;
+	}
 
 	if (info->attrs[HWSIM_ATTR_USE_CHANCTX])
 		param.use_chanctx = true;
@@ -3090,11 +3097,15 @@ static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
 	s64 idx = -1;
 	const char *hwname = NULL;
 
-	if (info->attrs[HWSIM_ATTR_RADIO_ID])
+	if (info->attrs[HWSIM_ATTR_RADIO_ID]) {
 		idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
-	else if (info->attrs[HWSIM_ATTR_RADIO_NAME])
-		hwname = (void *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]);
-	else
+	} else if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
+		hwname = kasprintf(GFP_KERNEL, "%.*s",
+				   nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
+				   (char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]));
+		if (!hwname)
+			return -ENOMEM;
+	} else
 		return -EINVAL;
 
 	spin_lock_bh(&hwsim_radio_lock);
@@ -3103,7 +3114,8 @@ static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
 			if (data->idx != idx)
 				continue;
 		} else {
-			if (strcmp(hwname, wiphy_name(data->hw->wiphy)))
+			if (!hwname ||
+			    strcmp(hwname, wiphy_name(data->hw->wiphy)))
 				continue;
 		}
 
@@ -3114,10 +3126,12 @@ static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
 		spin_unlock_bh(&hwsim_radio_lock);
 		mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy),
 					 info);
+		kfree(hwname);
 		return 0;
 	}
 	spin_unlock_bh(&hwsim_radio_lock);
 
+	kfree(hwname);
 	return -ENODEV;
 }
 
-- 
2.11.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH review for 4.9 01/50] xen-netback: Use GFP_ATOMIC to allocate  hash "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200
  [PATCH review for 4.9 17/50] f2fs: do not wait for writeback in  write_begin "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200
  [PATCH review for 4.9 15/50] sched/fair: Update rq clock before  changing a task's CPU affinity "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200
  [PATCH review for 4.9 26/50] ASoC: mediatek: add I2C dependency for  CS42XX8 "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200
  [PATCH review for 4.9 42/50] hrtimer: Catch invalid clockids again "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200
  [PATCH review for 4.9 06/50] mac80211_hwsim: check  HWSIM_ATTR_RADIO_NAME length "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200
  [PATCH review for 4.9 07/50] ALSA: hda: Add Geminilake HDMI codec ID "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200
  [PATCH review for 4.9 05/50] initramfs: finish fput() before  accessing any binary from initramfs "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200
  [PATCH review for 4.9 14/50] f2fs: do SSR for data when there is  enough free space "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200
  [PATCH review for 4.9 02/50] locking/lockdep: Add nest_lock integrity  test "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200
  [PATCH review for 4.9 18/50] md/linear: shutup lockdep warnning "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200
  [PATCH review for 4.9 12/50] netfilter: nf_ct_expect: Change  __nf_ct_expect_check() return value. "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200
  [PATCH review for 4.9 24/50] slub: do not merge cache if slub_debug  contains a never-merge flag "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-09-25 03:40 +0200

csiph-web