Jakub Kicinski wrote: > The NAPI IDs were not fully exposed to user space prior to the netlink > API, so they were never namespaced. The netlink API must ensure that > at the very least NAPI instance belongs to the same netns as the owner > of the genl sock. > > napi_by_id() can become static now, but it needs to move because of > dev_get_by_napi_id(). > > Cc: stable@xxxxxxxxxxxxxxx > Fixes: 1287c1ae0fc2 ("netdev-genl: Support setting per-NAPI config values") > Fixes: 27f91aaf49b3 ("netdev-genl: Add netlink framework functions for napi") > Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx> > --- > Splitting this into fix per-version is a bit tricky, because we need > to replace the napi_by_id() helper with a better one. I'll send the > stable versions manually. > > CC: jdamato@xxxxxxxxxx > CC: almasrymina@xxxxxxxxxx > CC: amritha.nambiar@xxxxxxxxx > CC: sridhar.samudrala@xxxxxxxxx > --- > net/core/dev.c | 43 +++++++++++++++++++++++++++++------------- > net/core/dev.h | 3 ++- > net/core/netdev-genl.c | 6 ++---- > 3 files changed, 34 insertions(+), 18 deletions(-) > > diff --git a/net/core/dev.c b/net/core/dev.c > index 7c63d97b13c1..e001df4cb486 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -753,6 +753,36 @@ int dev_fill_forward_path(const struct net_device *dev, const u8 *daddr, > } > EXPORT_SYMBOL_GPL(dev_fill_forward_path); > > +/* must be called under rcu_read_lock(), as we dont take a reference */ > +static struct napi_struct *napi_by_id(unsigned int napi_id) > +{ > + unsigned int hash = napi_id % HASH_SIZE(napi_hash); > + struct napi_struct *napi; > + > + hlist_for_each_entry_rcu(napi, &napi_hash[hash], napi_hash_node) > + if (napi->napi_id == napi_id) > + return napi; > + > + return NULL; > +} > + > +/* must be called under rcu_read_lock(), as we dont take a reference */ Instead of function comments, invariant checks in code? Like in dev_get_by_napi_id: WARN_ON_ONCE(!rcu_read_lock_held());