[net v2 2/2] netdev-genl: Hold rcu_read_lock in napi_set

From: Joe Damato
Date: Tue Nov 12 2024 - 21:18:56 EST


Hold rcu_read_lock during netdev_nl_napi_set_doit, which calls
napi_by_id and requires rcu_read_lock to be held.

Closes: https://lore.kernel.org/netdev/719083c2-e277-447b-b6ea-ca3acb293a03@xxxxxxxxxx/
Fixes: 1287c1ae0fc2 ("netdev-genl: Support setting per-NAPI config values")
Signed-off-by: Joe Damato <jdamato@xxxxxxxxxx>
---
v2:
- Simplified by adding rcu_read_lock/unlock instead of using the
helper proposed in the RFC.

net/core/netdev-genl.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index 0b684410b52d..9527dd46e4dc 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -348,6 +348,7 @@ int netdev_nl_napi_set_doit(struct sk_buff *skb, struct genl_info *info)
napi_id = nla_get_u32(info->attrs[NETDEV_A_NAPI_ID]);

rtnl_lock();
+ rcu_read_lock();

napi = napi_by_id(napi_id);
if (napi) {
@@ -357,6 +358,7 @@ int netdev_nl_napi_set_doit(struct sk_buff *skb, struct genl_info *info)
err = -ENOENT;
}

+ rcu_read_unlock();
rtnl_unlock();

return err;
--
2.25.1