From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: akpm@linux-foundation.org
Cc: jserv@ccns.ncku.edu.tw, linux-kernel@vger.kernel.org,
Kuan-Wei Chiu <visitorckw@gmail.com>
Subject: [PATCH] tools/lib/slab: Fix potential NULL pointer dereference in kmalloc()
Date: Sat, 25 May 2024 03:14:59 +0800 [thread overview]
Message-ID: <20240524191459.949731-1-visitorckw@gmail.com> (raw)
In kmalloc(), add a check to ensure that the pointer 'ret' is not NULL
before attempting to memset it when the __GFP_ZERO flag is set. This
prevents a potential NULL pointer dereference.
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
---
tools/lib/slab.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/lib/slab.c b/tools/lib/slab.c
index 959997fb0652..aeaf535b422a 100644
--- a/tools/lib/slab.c
+++ b/tools/lib/slab.c
@@ -22,7 +22,7 @@ void *kmalloc(size_t size, gfp_t gfp)
uatomic_inc(&kmalloc_nr_allocated);
if (kmalloc_verbose)
printf("Allocating %p from malloc\n", ret);
- if (gfp & __GFP_ZERO)
+ if (gfp & __GFP_ZERO && ret)
memset(ret, 0, size);
return ret;
}
--
2.34.1
next reply other threads:[~2024-05-24 19:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-24 19:14 Kuan-Wei Chiu [this message]
2024-05-24 19:23 ` Andrew Morton
2024-05-24 19:46 ` Kuan-Wei Chiu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240524191459.949731-1-visitorckw@gmail.com \
--to=visitorckw@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=jserv@ccns.ncku.edu.tw \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®