public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] debug: Fix a NULL vs IS_ERR() bug in __debug_object_init()
@ 2025-11-10  7:57 Haotian Zhang
  2025-11-10 13:39 ` Kuan-Wei Chiu
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Haotian Zhang @ 2025-11-10  7:57 UTC (permalink / raw)
  To: Andrew Morton, Thomas Gleixner; +Cc: linux-kernel, Haotian Zhang

The lookup_object_or_alloc() returns error pointers on failure, but the
code only checks for NULL. This leads to dereferencing an invalid error
pointer and causes a kernel crash.

Use IS_ERR_OR_NULL() instead of a NULL check to properly handle both
error pointers and NULL returns.

Fixes: 63a759694eed ("debugobject: Prevent init race with static objects")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 lib/debugobjects.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index 7f50c4480a4e..9587ef619054 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -741,9 +741,10 @@ __debug_object_init(void *addr, const struct debug_obj_descr *descr, int onstack
 	raw_spin_lock_irqsave(&db->lock, flags);
 
 	obj = lookup_object_or_alloc(addr, db, descr, onstack, false);
-	if (unlikely(!obj)) {
+	if (IS_ERR_OR_NULL(obj)) {
 		raw_spin_unlock_irqrestore(&db->lock, flags);
-		debug_objects_oom();
+		if (!obj)
+			debug_objects_oom();
 		return;
 	}
 
-- 
2.50.1.windows.1


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

end of thread, other threads:[~2025-11-16 18:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-10  7:57 [PATCH] debug: Fix a NULL vs IS_ERR() bug in __debug_object_init() Haotian Zhang
2025-11-10 13:39 ` Kuan-Wei Chiu
2025-11-11  2:15 ` [PATCH v2] debug: Fix a mixed use of NULL and error pointers Haotian Zhang
2025-11-13 19:49   ` Kuan-Wei Chiu
2025-11-13 20:03   ` Kuan-Wei Chiu
2025-11-14  1:56 ` [PATCH v3] debugobjects: Fix inconsistent return handling and potential ERR_PTR dereference Haotian Zhang
2025-11-15 23:18   ` Thomas Gleixner
2025-11-16 18:08     ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox