netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net v1] devlink: fix xa_alloc_cyclic error handling
@ 2025-02-14 13:24 Michal Swiatkowski
  2025-02-14 13:44 ` Andrew Lunn
  0 siblings, 1 reply; 13+ messages in thread
From: Michal Swiatkowski @ 2025-02-14 13:24 UTC (permalink / raw)
  To: netdev
  Cc: jiri, davem, edumazet, kuba, pabeni, horms, pierre,
	Michal Swiatkowski

Pierre Riteau <pierre@stackhpc.com> found suspicious handling an error
from xa_alloc_cyclic() in scheduler code [1]. The same is done in
devlink_rel_alloc().

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.

Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
---
 net/devlink/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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);
 	}
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-03-11 12:12 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-14 13:24 [net v1] devlink: fix xa_alloc_cyclic error handling Michal Swiatkowski
2025-02-14 13:44 ` Andrew Lunn
2025-02-14 13:58   ` Michal Swiatkowski
2025-02-14 14:14     ` Andrew Lunn
2025-02-18 11:56     ` Paolo Abeni
2025-03-10 11:42       ` Pierre Riteau
2025-03-11  9:16         ` Michal Swiatkowski
2025-03-11 11:49           ` Dan Carpenter
2025-03-11 12:09             ` Michal Swiatkowski
2025-02-16 15:06   ` Dan Carpenter
2025-02-16 16:08     ` Andrew Lunn
2025-02-17  7:46       ` Dan Carpenter
2025-02-17  6:57     ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).