diff mbox series

[04/21,SRU,OEM-OSP1-B] nl80211: use for_each_element() in validate_ie_attr()

Message ID 20190924075947.33954-5-vicamo.yang@canonical.com
State New
Headers show
Series iwlwifi: mvm: support HE context cmd API change | expand

Commit Message

You-Sheng Yang Sept. 24, 2019, 7:59 a.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

BugLink: https://bugs.launchpad.net/bugs/1845138

This makes for much simpler code, simply walk through all
the elements and check that the last one found ends with
the end of the data. This works because if any element is
malformed the walk is aborted, we end up with a mismatch.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
(cherry picked from commit 9f308616b6176b6dc470e6eb3569a09b100a823a)
Signed-off-by: You-Sheng Yang <vicamo.yang@canonical.com>
---
 net/wireless/nl80211.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 58d669690fb20..12265faed00ec 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -203,29 +203,17 @@  cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
 static int validate_ie_attr(const struct nlattr *attr,
 			    struct netlink_ext_ack *extack)
 {
-	const u8 *pos;
-	int len;
+	const u8 *data = nla_data(attr);
+	unsigned int len = nla_len(attr);
+	struct element *elem;
 
-	pos = nla_data(attr);
-	len = nla_len(attr);
-
-	while (len) {
-		u8 elemlen;
-
-		if (len < 2)
-			goto error;
-		len -= 2;
-
-		elemlen = pos[1];
-		if (elemlen > len)
-			goto error;
-
-		len -= elemlen;
-		pos += 2 + elemlen;
+	for_each_element(elem, data, len) {
+		/* nothing */
 	}
 
-	return 0;
-error:
+	if (for_each_element_completed(elem, data, len))
+		return 0;
+
 	NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements");
 	return -EINVAL;
 }