1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Fri, 9 Jun 2017 17:06:51 +0200
3 Subject: [PATCH] batman-adv: Accept only filled wifi station info
5 The wifi driver can decide to not provide parts of the station info. For
6 example, the expected throughput of the station can be omitted when the
7 used rate control doesn't provide this kind of information.
9 The B.A.T.M.A.N. V implementation must therefore check the filled bitfield
10 before it tries to access the expected_throughput of the returned
13 Reported-by: Alvaro Antelo <alvaro.antelo@gmail.com>
14 Fixes: 5c3245172c01 ("batman-adv: ELP - compute the metric based on the estimated throughput")
15 Signed-off-by: Sven Eckelmann <sven@narfation.org>
16 Reviewed-by: Marek Lindner <mareklindner@neomailbox.ch>
17 Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
19 Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/1e26904b364ceffe9ca7d6da7412e70fb2a04178
21 compat-include/linux/nl80211.h | 14 ++++++++++++++
22 compat-include/uapi/linux/nl80211.h | 16 ++++++++++++++++
23 net/batman-adv/bat_v_elp.c | 4 ++++
24 3 files changed, 34 insertions(+)
25 create mode 100644 compat-include/linux/nl80211.h
26 create mode 100644 compat-include/uapi/linux/nl80211.h
28 diff --git a/compat-include/linux/nl80211.h b/compat-include/linux/nl80211.h
30 index 0000000000000000000000000000000000000000..e6654df8cd67caa52a16a1f709141d7415b9f523
32 +++ b/compat-include/linux/nl80211.h
34 +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NL80211_H_
35 +#define _NET_BATMAN_ADV_COMPAT_LINUX_NL80211_H_
37 +#include <linux/version.h>
38 +#include_next <linux/nl80211.h>
40 +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0)
42 +/* Linux 3.15 misses the uapi include.... */
43 +#include <uapi/linux/nl80211.h>
45 +#endif /* < KERNEL_VERSION(3, 16, 0) */
47 +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NL80211_H_ */
48 diff --git a/compat-include/uapi/linux/nl80211.h b/compat-include/uapi/linux/nl80211.h
50 index 0000000000000000000000000000000000000000..06f5625af21360be5718a1a6f7e8949f6739c927
52 +++ b/compat-include/uapi/linux/nl80211.h
54 +#ifndef _NET_BATMAN_ADV_COMPAT_UAPI_LINUX_NL80211_H_
55 +#define _NET_BATMAN_ADV_COMPAT_UAPI_LINUX_NL80211_H_
57 +#include <linux/version.h>
58 +#include_next <uapi/linux/nl80211.h>
60 +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
62 +/* for batadv_v_elp_get_throughput which would have used
63 + * STATION_INFO_EXPECTED_THROUGHPUT in Linux 4.0.0
65 +#define NL80211_STA_INFO_EXPECTED_THROUGHPUT 28
67 +#endif /* < KERNEL_VERSION(4, 0, 0) */
69 +#endif /* _NET_BATMAN_ADV_COMPAT_UAPI_LINUX_NL80211_H_ */
70 diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
71 index 7c54a9291c9eaed75dfdfdfbd200f84c51576cb3..06b2924f4cb7dde54bab97ad2d28aecd9b1a4ceb 100644
72 --- a/net/batman-adv/bat_v_elp.c
73 +++ b/net/batman-adv/bat_v_elp.c
77 #include <linux/atomic.h>
78 +#include <linux/bitops.h>
79 #include <linux/byteorder/generic.h>
80 #include <linux/errno.h>
81 #include <linux/etherdevice.h>
83 #include <linux/kernel.h>
84 #include <linux/kref.h>
85 #include <linux/netdevice.h>
86 +#include <linux/nl80211.h>
87 #include <linux/random.h>
88 #include <linux/rculist.h>
89 #include <linux/rcupdate.h>
90 @@ -111,6 +113,8 @@ static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh)
93 goto default_throughput;
94 + if (!(sinfo.filled & BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT)))
95 + goto default_throughput;
97 return sinfo.expected_throughput / 100;