summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorMichal Swiatkowski <michal.swiatkowski@linux.intel.com>2025-03-12 10:52:49 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-03-28 22:04:53 +0100
commit466132f6d28a7e47a82501fe1c46b8f90487412e (patch)
tree9515cca7b8adc573a1447f4b232f10db4506b8af /net
parentbd6363eb56a1740c74622dd258c2eda925bfcb1e (diff)
downloadlinux-466132f6d28a7e47a82501fe1c46b8f90487412e.tar.gz
linux-466132f6d28a7e47a82501fe1c46b8f90487412e.tar.bz2
linux-466132f6d28a7e47a82501fe1c46b8f90487412e.zip
devlink: fix xa_alloc_cyclic() error handling
[ Upstream commit f3b97b7d4bf316c3991e5634c9f4847c2df35478 ] 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> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'net')
-rw-r--r--net/devlink/core.c2
1 files changed, 1 insertions, 1 deletions
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);
}