diff mbox series

[1/2] nl80211: Retrieve maxattr via genl for nl80211

Message ID 20231228131406.2439640-1-andrei.otcheretianski@intel.com
State Accepted
Headers show
Series [1/2] nl80211: Retrieve maxattr via genl for nl80211 | expand

Commit Message

Andrei Otcheretianski Dec. 28, 2023, 1:14 p.m. UTC
From: Benjamin Berg <benjamin.berg@intel.com>

Older kernel versions may not support all attributes and may refuse
commands that include them. To avoid sending too new attributes query
the highest supported attribute. This allows adding appropriate checks
where needed.

Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
---
 src/drivers/driver_nl80211.c | 28 ++++++++++++++++++++++++++++
 src/drivers/driver_nl80211.h |  1 +
 2 files changed, 29 insertions(+)

Comments

Jouni Malinen Jan. 14, 2024, 4:23 p.m. UTC | #1
On Thu, Dec 28, 2023 at 03:14:05PM +0200, Andrei Otcheretianski wrote:
> Older kernel versions may not support all attributes and may refuse
> commands that include them. To avoid sending too new attributes query
> the highest supported attribute. This allows adding appropriate checks
> where needed.

Thanks, both patches applied.

Are the two cases in patch 2/2 all the known issues or are there some
other known cases that could fail with older kernel versions?
Benjamin Berg Jan. 15, 2024, 10:47 a.m. UTC | #2
Hi,

On Sun, 2024-01-14 at 18:23 +0200, Jouni Malinen wrote:
> On Thu, Dec 28, 2023 at 03:14:05PM +0200, Andrei Otcheretianski
> wrote:
> > Older kernel versions may not support all attributes and may refuse
> > commands that include them. To avoid sending too new attributes
> > query
> > the highest supported attribute. This allows adding appropriate
> > checks
> > where needed.
> 
> Thanks, both patches applied.
> 
> Are the two cases in patch 2/2 all the known issues or are there some
> other known cases that could fail with older kernel versions?

Those were the only obvious places that I saw when looking over it a
while ago.

That said, Johannes recently mentioned that commit 6cc78b3945d3271a
("nl80211: Set NL80211_WPA_VERSION_2 vs. _3 based on AKM") is
problematic on older kernel versions that might not understand the new
value.

Unfortunately, in that case there is no way to directly check for the
support. However, he did say that we could check for the related
NL80211_ATTR_SAE_PASSWORD as a heuristic to know whether
NL80211_WPA_VERSION_3 is supported by the kernel.

Benjamin
diff mbox series

Patch

diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index a3bb2d5251..b56ca852d3 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -16,6 +16,7 @@ 
 #include <net/if.h>
 #include <netlink/genl/genl.h>
 #include <netlink/genl/ctrl.h>
+#include <netlink/genl/family.h>
 #ifdef CONFIG_LIBNL3_ROUTE
 #include <netlink/route/neighbour.h>
 #endif /* CONFIG_LIBNL3_ROUTE */
@@ -1938,6 +1939,8 @@  static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
 
 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
 {
+	struct nl_cache *cache = NULL;
+	struct genl_family *family = NULL;
 	int ret;
 
 	global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
@@ -2009,6 +2012,29 @@  static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
 		/* Continue without vendor events */
 	}
 
+	/* Resolve maxattr for kernel support checks */
+	ret = genl_ctrl_alloc_cache(global->nl, &cache);
+	if (ret < 0) {
+		wpa_printf(MSG_DEBUG,
+			   "nl80211: Could not allocate genl cache: %d (%s)",
+			   ret, nl_geterror(ret));
+		goto err;
+	}
+
+	family = genl_ctrl_search(cache, global->nl80211_id);
+	if (!family) {
+		wpa_printf(MSG_DEBUG,
+			   "nl80211: Could not get nl80211 family from cache: %d (%s)",
+			   ret, nl_geterror(ret));
+		goto err;
+	}
+
+	global->nl80211_maxattr = genl_family_get_maxattr(family);
+	genl_family_put(family);
+	family = NULL;
+	nl_cache_free(cache);
+	cache = NULL;
+
 	nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
 		  no_seq_check, NULL);
 	nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
@@ -2021,6 +2047,8 @@  static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
 	return 0;
 
 err:
+	genl_family_put(family);
+	nl_cache_free(cache);
 	nl_destroy_handles(&global->nl_event);
 	nl_destroy_handles(&global->nl);
 	nl_cb_put(global->nl_cb);
diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h
index 2b2bc9b117..315b88b01a 100644
--- a/src/drivers/driver_nl80211.h
+++ b/src/drivers/driver_nl80211.h
@@ -32,6 +32,7 @@  struct nl80211_global {
 	struct nl_cb *nl_cb;
 	struct nl_sock *nl;
 	int nl80211_id;
+	int nl80211_maxattr;
 	int nlctrl_id;
 	int ioctl_sock; /* socket for ioctl() use */