* [PATCH batadv 0/3] batman-adv: wifi flags cache cleanup
@ 2026-06-03 4:21 Sven Eckelmann
2026-06-03 4:21 ` [PATCH batadv 1/3] batman-adv: correct batadv_wifi_* kernel-doc Sven Eckelmann
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Sven Eckelmann @ 2026-06-03 4:21 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
Unfortunately, the new wifi flags cache had some problems in the kernel
doc and non-optimal code in batadv_wifi_net_device_insert(). Let us just
fix this while the code is fresh :)
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
Sven Eckelmann (3):
batman-adv: correct batadv_wifi_* kernel-doc
batman-adv: drop duplicated wifi_flags assigned
batman-adv: use GFP_KERNEL allocations for the wifi detection cache
net/batman-adv/hard-interface.c | 11 +++++------
net/batman-adv/hard-interface.h | 4 ++--
2 files changed, 7 insertions(+), 8 deletions(-)
---
base-commit: bba80ddd693e6d82a0b1f456511904cfefd5df24
change-id: 20260602-wifi-cache-cleanup-656e0602c946
Best regards,
--
Sven Eckelmann <sven@narfation.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH batadv 1/3] batman-adv: correct batadv_wifi_* kernel-doc
2026-06-03 4:21 [PATCH batadv 0/3] batman-adv: wifi flags cache cleanup Sven Eckelmann
@ 2026-06-03 4:21 ` Sven Eckelmann
2026-06-03 4:21 ` [PATCH batadv 2/3] batman-adv: drop duplicated wifi_flags assigned Sven Eckelmann
2026-06-03 4:21 ` [PATCH batadv 3/3] batman-adv: use GFP_KERNEL allocations for the wifi detection cache Sven Eckelmann
2 siblings, 0 replies; 5+ messages in thread
From: Sven Eckelmann @ 2026-06-03 4:21 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
The original kernel documentation for the batadv_wifi_* functions contained
copy+paste errors. Correct them to make it easier understandable.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/hard-interface.c | 6 +++---
net/batman-adv/hard-interface.h | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index bb3c31b5..213d4609 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -960,9 +960,9 @@ static int batadv_hard_if_event_meshif(unsigned long event,
/**
* batadv_wifi_net_device_insert() - save information about wifi net_device
* @net_dev: net_device to add to batadv_wifi_net_devices
- * @wifi_flags: net_device which generated an event
+ * extracted batadv_hard_iface_wifi_flags of a net_device
*
- * Return: 0 on result, negative value on error
+ * Return: 0 on success, negative value on error
*/
static int
batadv_wifi_net_device_insert(struct net_device *net_dev, u32 wifi_flags)
@@ -996,7 +996,7 @@ batadv_wifi_net_device_insert(struct net_device *net_dev, u32 wifi_flags)
/**
* batadv_wifi_net_device_remove() - remove information about wifi net_device
- * @device_state: wifi net_device state to remove from batadv_wifi_net_device_state
+ * @device_state: wifi net_device state to remove from batadv_wifi_net_devices
*/
static void
batadv_wifi_net_device_remove(struct batadv_wifi_net_device_state *device_state)
diff --git a/net/batman-adv/hard-interface.h b/net/batman-adv/hard-interface.h
index 089e65c8..41ef2944 100644
--- a/net/batman-adv/hard-interface.h
+++ b/net/batman-adv/hard-interface.h
@@ -125,7 +125,7 @@ batadv_primary_if_get_selected(struct batadv_priv *bat_priv)
/**
* batadv_is_cfg80211() - check if the given hardif is a cfg80211
* wifi interface
- * @wifi_flags: extracted batadv_hard_iface_wifi_flagss of an net_device
+ * @wifi_flags: extracted batadv_hard_iface_wifi_flags of a net_device
*
* Return: true if the net device is a cfg80211 wireless device, false
* otherwise.
@@ -142,7 +142,7 @@ static inline bool batadv_is_cfg80211(u32 wifi_flags)
/**
* batadv_is_wifi() - check if flags belong to wifi interface
- * @wifi_flags: extracted batadv_hard_iface_wifi_flagss of an net_device
+ * @wifi_flags: extracted batadv_hard_iface_wifi_flags of a net_device
*
* Return: true if the net device is a 802.11 wireless device, false otherwise.
*/
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH batadv 2/3] batman-adv: drop duplicated wifi_flags assigned
2026-06-03 4:21 [PATCH batadv 0/3] batman-adv: wifi flags cache cleanup Sven Eckelmann
2026-06-03 4:21 ` [PATCH batadv 1/3] batman-adv: correct batadv_wifi_* kernel-doc Sven Eckelmann
@ 2026-06-03 4:21 ` Sven Eckelmann
2026-06-03 4:21 ` [PATCH batadv 3/3] batman-adv: use GFP_KERNEL allocations for the wifi detection cache Sven Eckelmann
2 siblings, 0 replies; 5+ messages in thread
From: Sven Eckelmann @ 2026-06-03 4:21 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
During the initialization of the batadv_wifi_net_device_state, it is enough
to write the wifi_flags once before the batadv_wifi_net_device_state is
added to the batadv_wifi_net_devices rhashtable.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/hard-interface.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 213d4609..80eaac0e 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -976,7 +976,6 @@ batadv_wifi_net_device_insert(struct net_device *net_dev, u32 wifi_flags)
if (!device_state)
return -ENOMEM;
- device_state->wifi_flags = wifi_flags;
netdev_hold(net_dev, &device_state->dev_tracker, GFP_ATOMIC);
device_state->netdev = net_dev;
WRITE_ONCE(device_state->wifi_flags, wifi_flags);
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH batadv 3/3] batman-adv: use GFP_KERNEL allocations for the wifi detection cache
2026-06-03 4:21 [PATCH batadv 0/3] batman-adv: wifi flags cache cleanup Sven Eckelmann
2026-06-03 4:21 ` [PATCH batadv 1/3] batman-adv: correct batadv_wifi_* kernel-doc Sven Eckelmann
2026-06-03 4:21 ` [PATCH batadv 2/3] batman-adv: drop duplicated wifi_flags assigned Sven Eckelmann
@ 2026-06-03 4:21 ` Sven Eckelmann
[not found] ` <20260603045118.0625E1F00893@smtp.kernel.org>
2 siblings, 1 reply; 5+ messages in thread
From: Sven Eckelmann @ 2026-06-03 4:21 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Sven Eckelmann
The batadv_wifi_net_device_insert() is called with ASSERT_RTNL() held, but
not inside a spinlock or another context which prevents "might_sleep"
functions. To relax the requirements for the allocator, use GFP_KERNEL.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/hard-interface.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 80eaac0e..63caabf5 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -972,11 +972,11 @@ batadv_wifi_net_device_insert(struct net_device *net_dev, u32 wifi_flags)
ASSERT_RTNL();
- device_state = kzalloc_obj(*device_state, GFP_ATOMIC);
+ device_state = kzalloc_obj(*device_state, GFP_KERNEL);
if (!device_state)
return -ENOMEM;
- netdev_hold(net_dev, &device_state->dev_tracker, GFP_ATOMIC);
+ netdev_hold(net_dev, &device_state->dev_tracker, GFP_KERNEL);
device_state->netdev = net_dev;
WRITE_ONCE(device_state->wifi_flags, wifi_flags);
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH batadv 3/3] batman-adv: use GFP_KERNEL allocations for the wifi detection cache
[not found] ` <20260603045118.0625E1F00893@smtp.kernel.org>
@ 2026-06-03 9:02 ` Sven Eckelmann
0 siblings, 0 replies; 5+ messages in thread
From: Sven Eckelmann @ 2026-06-03 9:02 UTC (permalink / raw)
To: sashiko-reviews; +Cc: sw, marek.lindner, antonio, b.a.t.m.a.n
[-- Attachment #1: Type: text/plain, Size: 2195 bytes --]
On Wednesday, 3 June 2026 06:51:17 CEST sashiko-bot@kernel.org wrote:
> [Severity: High]
> This isn't a bug introduced by this patch, but while looking at the
> rhashtable usage in this file, I noticed that rhashtable_lookup_fast() is
> called without rcu_read_lock() in batadv_wifi_net_device_update():
>
> net/batman-adv/hard-interface.c:batadv_wifi_net_device_update() {
> ...
> wifi_flags = batadv_wifi_flags_evaluate(net_dev);
> device_state = rhashtable_lookup_fast(&batadv_wifi_net_devices,
> &net_dev,
> batadv_wifi_net_devices_params);
> ...
> }
>
> And similarly in batadv_wifi_net_device_unregister():
>
> net/batman-adv/hard-interface.c:batadv_wifi_net_device_unregister() {
> ...
> device_state = rhashtable_lookup_fast(&batadv_wifi_net_devices,
> &net_dev,
> batadv_wifi_net_devices_params);
> ...
> }
>
> Can this lead to a use-after-free on the bucket array?
>
> Since batadv_wifi_net_devices is initialized with automatic_shrinking = true,
> it can be asynchronously resized by a background worker at any time. This
> worker frees the old bucket array via kfree_rcu(). Without an active RCU
> read-side critical section, couldn't the RCU grace period end while
> rhashtable_lookup_fast() is still iterating?
Would be nice if someone else can double check this. But this doesn't seem to
be valid:
static __always_inline void *rhashtable_lookup_fast(
struct rhashtable *ht, const void *key,
const struct rhashtable_params params)
{
void *obj;
rcu_read_lock();
obj = rhashtable_lookup(ht, key, params);
rcu_read_unlock();
return obj;
}
So, rhashtable_lookup_fast() takes rcu_read_lock() itself. And the returned obj
cannot be freed because all functions mentioned here are protected by the
rtnl_lock().
We are therefore also fulfilling the requirement from the
rhashtable_lookup_fast comment:
* Only use this function when you have other mechanisms guaranteeing
* that the object won't go away after the RCU read lock is released.
Regards,
Sven
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-06-03 9:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03 4:21 [PATCH batadv 0/3] batman-adv: wifi flags cache cleanup Sven Eckelmann
2026-06-03 4:21 ` [PATCH batadv 1/3] batman-adv: correct batadv_wifi_* kernel-doc Sven Eckelmann
2026-06-03 4:21 ` [PATCH batadv 2/3] batman-adv: drop duplicated wifi_flags assigned Sven Eckelmann
2026-06-03 4:21 ` [PATCH batadv 3/3] batman-adv: use GFP_KERNEL allocations for the wifi detection cache Sven Eckelmann
[not found] ` <20260603045118.0625E1F00893@smtp.kernel.org>
2026-06-03 9:02 ` Sven Eckelmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox