Message ID | 20250312095251.2554708-2-michal.swiatkowski@linux.intel.com (mailing list archive) |
---|---|
State | New |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | fix xa_alloc_cyclic() return checks | expand |
On Wed, Mar 12, 2025 at 10:52:49AM +0100, Michal Swiatkowski wrote: > In case of returning 1 from xa_alloc_cyclic() (wrapping) ERR_PTR(1) will > be returned, which will cause IS_ERR() to be false. Which can lead to > dereference not allocated pointer (rel). > > Fix it by checking if err is lower than zero. > > This wasn't found in real usecase, only noticed. Credit to Pierre. > > Fixes: c137743bce02 ("devlink: introduce object and nested devlink relationship infra") > Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Andrew
diff --git a/net/devlink/core.c b/net/devlink/core.c index f49cd83f1955..7203c39532fc 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -117,7 +117,7 @@ static struct devlink_rel *devlink_rel_alloc(void) err = xa_alloc_cyclic(&devlink_rels, &rel->index, rel, xa_limit_32b, &next, GFP_KERNEL); - if (err) { + if (err < 0) { kfree(rel); return ERR_PTR(err); }
In case of returning 1 from xa_alloc_cyclic() (wrapping) ERR_PTR(1) will be returned, which will cause IS_ERR() to be false. Which can lead to dereference not allocated pointer (rel). Fix it by checking if err is lower than zero. This wasn't found in real usecase, only noticed. Credit to Pierre. Fixes: c137743bce02 ("devlink: introduce object and nested devlink relationship infra") Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com> --- net/devlink/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)