From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Johannes Berg <johannes.berg@intel.com>
Subject: [PATCH 4.9 32/92] cfg80211: add and use strongly typed element iteration macros
Date: Wed, 16 Oct 2019 14:50:05 -0700 [thread overview]
Message-ID: <20191016214826.756979955@linuxfoundation.org> (raw)
In-Reply-To: <20191016214759.600329427@linuxfoundation.org>
From: Johannes Berg <johannes.berg@intel.com>
commit 0f3b07f027f87a38ebe5c436490095df762819be upstream.
Rather than always iterating elements from frames with pure
u8 pointers, add a type "struct element" that encapsulates
the id/datalen/data format of them.
Then, add the element iteration macros
* for_each_element
* for_each_element_id
* for_each_element_extid
which take, as their first 'argument', such a structure and
iterate through a given u8 array interpreting it as elements.
While at it and since we'll need it, also add
* for_each_subelement
* for_each_subelement_id
* for_each_subelement_extid
which instead of taking data/length just take an outer element
and use its data/datalen.
Also add for_each_element_completed() to determine if any of
the loops above completed, i.e. it was able to parse all of
the elements successfully and no data remained.
Use for_each_element_id() in cfg80211_find_ie_match() as the
first user of this.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/ieee80211.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++
net/wireless/scan.c | 14 +++++-------
2 files changed, 59 insertions(+), 8 deletions(-)
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -2630,4 +2630,57 @@ static inline bool ieee80211_action_cont
return true;
}
+struct element {
+ u8 id;
+ u8 datalen;
+ u8 data[];
+};
+
+/* element iteration helpers */
+#define for_each_element(element, _data, _datalen) \
+ for (element = (void *)(_data); \
+ (u8 *)(_data) + (_datalen) - (u8 *)element >= \
+ sizeof(*element) && \
+ (u8 *)(_data) + (_datalen) - (u8 *)element >= \
+ sizeof(*element) + element->datalen; \
+ element = (void *)(element->data + element->datalen))
+
+#define for_each_element_id(element, _id, data, datalen) \
+ for_each_element(element, data, datalen) \
+ if (element->id == (_id))
+
+#define for_each_element_extid(element, extid, data, datalen) \
+ for_each_element(element, data, datalen) \
+ if (element->id == WLAN_EID_EXTENSION && \
+ element->datalen > 0 && \
+ element->data[0] == (extid))
+
+#define for_each_subelement(sub, element) \
+ for_each_element(sub, (element)->data, (element)->datalen)
+
+#define for_each_subelement_id(sub, id, element) \
+ for_each_element_id(sub, id, (element)->data, (element)->datalen)
+
+#define for_each_subelement_extid(sub, extid, element) \
+ for_each_element_extid(sub, extid, (element)->data, (element)->datalen)
+
+/**
+ * for_each_element_completed - determine if element parsing consumed all data
+ * @element: element pointer after for_each_element() or friends
+ * @data: same data pointer as passed to for_each_element() or friends
+ * @datalen: same data length as passed to for_each_element() or friends
+ *
+ * This function returns %true if all the data was parsed or considered
+ * while walking the elements. Only use this if your for_each_element()
+ * loop cannot be broken out of, otherwise it always returns %false.
+ *
+ * If some data was malformed, this returns %false since the last parsed
+ * element will not fill the whole remaining data.
+ */
+static inline bool for_each_element_completed(const struct element *element,
+ const void *data, size_t datalen)
+{
+ return (u8 *)element == (u8 *)data + datalen;
+}
+
#endif /* LINUX_IEEE80211_H */
--- a/net/wireless/scan.c
+++ b/net/wireless/scan.c
@@ -407,6 +407,8 @@ const u8 *cfg80211_find_ie_match(u8 eid,
const u8 *match, int match_len,
int match_offset)
{
+ const struct element *elem;
+
/* match_offset can't be smaller than 2, unless match_len is
* zero, in which case match_offset must be zero as well.
*/
@@ -414,14 +416,10 @@ const u8 *cfg80211_find_ie_match(u8 eid,
(!match_len && match_offset)))
return NULL;
- while (len >= 2 && len >= ies[1] + 2) {
- if ((ies[0] == eid) &&
- (ies[1] + 2 >= match_offset + match_len) &&
- !memcmp(ies + match_offset, match, match_len))
- return ies;
-
- len -= ies[1] + 2;
- ies += ies[1] + 2;
+ for_each_element_id(elem, eid, ies, len) {
+ if (elem->datalen >= match_offset - 2 + match_len &&
+ !memcmp(elem->data + match_offset - 2, match, match_len))
+ return (void *)elem;
}
return NULL;
next prev parent reply other threads:[~2019-10-16 22:18 UTC|newest]
Thread overview: 98+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-16 21:49 [PATCH 4.9 00/92] 4.9.197-stable review Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 01/92] KVM: s390: Test for bad access register and size at the start of S390_MEM_OP Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 02/92] s390/topology: avoid firing events before kobjs are created Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 03/92] s390/cio: avoid calling strlen on null pointer Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 04/92] s390/cio: exclude subchannels with no parent from pseudo check Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 05/92] KVM: nVMX: handle page fault in vmread fix Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 06/92] ASoC: Define a set of DAPM pre/post-up events Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 07/92] powerpc/powernv: Restrict OPAL symbol map to only be readable by root Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 08/92] can: mcp251x: mcp251x_hw_reset(): allow more time after a reset Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 09/92] crypto: qat - Silence smp_processor_id() warning Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 10/92] usercopy: Avoid HIGHMEM pfn warning Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 11/92] timer: Read jiffies once when forwarding base clk Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 12/92] watchdog: imx2_wdt: fix min() calculation in imx2_wdt_set_timeout Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 13/92] ieee802154: atusb: fix use-after-free at disconnect Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 14/92] cfg80211: initialize on-stack chandefs Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 15/92] ima: always return negative code for error Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 16/92] fs: nfs: Fix possible null-pointer dereferences in encode_attrs() Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 17/92] 9p: avoid attaching writeback_fid on mmap with type PRIVATE Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 18/92] xen/pci: reserve MCFG areas earlier Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 19/92] ceph: fix directories inode i_blkbits initialization Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 20/92] ceph: reconnect connection if session hang in opening state Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 21/92] drm/amdgpu: Check for valid number of registers to read Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 22/92] thermal: Fix use-after-free when unregistering thermal zone device Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 23/92] fuse: fix memleak in cuse_channel_open Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 24/92] sched/core: Fix migration to invalid CPU in __set_cpus_allowed_ptr() Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 25/92] kernel/elfcore.c: include proper prototypes Greg Kroah-Hartman
2019-10-16 21:49 ` [PATCH 4.9 26/92] tools lib traceevent: Do not free tep->cmdlines in add_new_comm() on failure Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 28/92] perf stat: Fix a segmentation fault when using repeat forever Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 29/92] perf stat: Reset previous counts on repeat with interval Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 30/92] crypto: caam - fix concurrency issue in givencrypt descriptor Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 31/92] coresight: etm4x: Use explicit barriers on enable/disable Greg Kroah-Hartman
2019-10-16 21:50 ` Greg Kroah-Hartman [this message]
2019-10-16 21:50 ` [PATCH 4.9 33/92] cfg80211: Use const more consistently in for_each_element macros Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 34/92] nl80211: validate beacon head Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 35/92] ASoC: sgtl5000: Improve VAG power and mute control Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 36/92] panic: ensure preemption is disabled during panic() Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 37/92] USB: rio500: Remove Rio 500 kernel driver Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 38/92] USB: yurex: Dont retry on unexpected errors Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 39/92] USB: yurex: fix NULL-derefs on disconnect Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 40/92] USB: usb-skeleton: fix runtime PM after driver unbind Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 41/92] USB: usb-skeleton: fix NULL-deref on disconnect Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 42/92] xhci: Fix false warning message about wrong bounce buffer write length Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 43/92] xhci: Prevent device initiated U1/U2 link pm if exit latency is too long Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 44/92] xhci: Check all endpoints for LPM timeout Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 45/92] usb: xhci: wait for CNR controller not ready bit in xhci resume Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 46/92] xhci: Increase STS_SAVE timeout in xhci_suspend() Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 47/92] USB: adutux: remove redundant variable minor Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 48/92] USB: adutux: fix use-after-free on disconnect Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 49/92] USB: adutux: fix NULL-derefs " Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 50/92] USB: adutux: fix use-after-free on release Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 51/92] USB: iowarrior: fix use-after-free on disconnect Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 52/92] USB: iowarrior: fix use-after-free on release Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 53/92] USB: iowarrior: fix use-after-free after driver unbind Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 54/92] USB: usblp: fix runtime PM " Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 55/92] USB: chaoskey: fix use-after-free on release Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 56/92] USB: ldusb: fix NULL-derefs on driver unbind Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 57/92] serial: uartlite: fix exit path null pointer Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 58/92] USB: serial: keyspan: fix NULL-derefs on open() and write() Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 59/92] USB: serial: ftdi_sio: add device IDs for Sienna and Echelon PL-20 Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 60/92] USB: serial: option: add Telit FN980 compositions Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 61/92] USB: serial: option: add support for Cinterion CLS8 devices Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 62/92] USB: serial: fix runtime PM after driver unbind Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 63/92] USB: usblcd: fix I/O after disconnect Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 64/92] USB: microtek: fix info-leak at probe Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 65/92] USB: dummy-hcd: fix power budget for SuperSpeed mode Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 66/92] usb: renesas_usbhs: gadget: Do not discard queues in usb_ep_set_{halt,wedge}() Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 67/92] usb: renesas_usbhs: gadget: Fix usb_ep_set_{halt,wedge}() behavior Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 68/92] USB: legousbtower: fix slab info leak at probe Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 69/92] USB: legousbtower: fix deadlock on disconnect Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 70/92] USB: legousbtower: fix potential NULL-deref " Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 71/92] USB: legousbtower: fix open after failed reset request Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 72/92] USB: legousbtower: fix use-after-free on release Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 73/92] staging: vt6655: Fix memory leak in vt6655_probe Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 74/92] iio: adc: ad799x: fix probe error handling Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 75/92] iio: light: opt3001: fix mutex unlock race Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 76/92] efivar/ssdt: Dont iterate over EFI vars if no SSDT override was specified Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 77/92] perf llvm: Dont access out-of-scope array Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 78/92] perf inject jit: Fix JIT_CODE_MOVE filename Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 79/92] CIFS: Gracefully handle QueryInfo errors during open Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 80/92] CIFS: Force revalidate inode when dentry is stale Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 81/92] CIFS: Force reval dentry if LOOKUP_REVAL flag is set Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 82/92] kernel/sysctl.c: do not override max_threads provided by userspace Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 83/92] staging: fbtft: Stop using BL_CORE_DRIVER1 Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 84/92] Staging: fbtft: fix memory leak in fbtft_framebuffer_alloc Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 85/92] MIPS: Disable Loongson MMI instructions for kernel build Greg Kroah-Hartman
2019-10-16 21:50 ` [PATCH 4.9 86/92] Fix the locking in dcache_readdir() and friends Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 4.9 87/92] media: stkwebcam: fix runtime PM after driver unbind Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 4.9 88/92] tracing/hwlat: Report total time spent in all NMIs during the sample Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 4.9 89/92] tracing/hwlat: Dont ignore outer-loop duration when calculating max_latency Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 4.9 90/92] tracing: Get trace_array reference for available_tracers files Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 4.9 91/92] x86/asm: Fix MWAITX C-state hint value Greg Kroah-Hartman
2019-10-16 21:51 ` [PATCH 4.9 92/92] xfs: clear sb->s_fs_info on mount failure Greg Kroah-Hartman
2019-10-17 1:42 ` [PATCH 4.9 00/92] 4.9.197-stable review kernelci.org bot
2019-10-17 6:21 ` Naresh Kamboju
2019-10-17 14:47 ` shuah
2019-10-17 18:03 ` Guenter Roeck
2019-10-17 18:47 ` Didik Setiawan
2019-10-18 7:56 ` Jon Hunter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191016214826.756979955@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=johannes.berg@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).