mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tools/io_uring: Fix missing check for return value of malloc()
@ 2023-06-15 12:50 Chenyuan Mi
  2023-06-15 13:00 ` Ammar Faizi
  0 siblings, 1 reply; 5+ messages in thread
From: Chenyuan Mi @ 2023-06-15 12:50 UTC (permalink / raw)
  To: axboe; +Cc: sml.silence, io-uring, linux-kernel, Chenyuan Mi

The malloc() function may return NULL when it fails,
which may cause null pointer deference in kmalloc(),
add Null check for return value of malloc().

Found by our static analysis tool.

Signed-off-by: Chenyuan Mi <cymi20@fudan.edu.cn>
---
 tools/io_uring/io_uring-bench.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/io_uring/io_uring-bench.c b/tools/io_uring/io_uring-bench.c
index 7703f0118385..a7fedfdb9b84 100644
--- a/tools/io_uring/io_uring-bench.c
+++ b/tools/io_uring/io_uring-bench.c
@@ -560,6 +560,11 @@ int main(int argc, char *argv[])
 	pthread_create(&s->thread, NULL, submitter_fn, s);
 
 	fdepths = malloc(8 * s->nr_files);
+	if (!fdepths) {
+		printf("malloc failed");
+		return 1;
+	}
+
 	reap = calls = done = 0;
 	do {
 		unsigned long this_done = 0;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH] tools/io_uring: Fix missing check for return value of malloc()
@ 2023-06-15 12:53 Chenyuan Mi
  0 siblings, 0 replies; 5+ messages in thread
From: Chenyuan Mi @ 2023-06-15 12:53 UTC (permalink / raw)
  To: axboe; +Cc: sml.silence, io-uring, linux-kernel, Chenyuan Mi

The malloc() function may return NULL when it fails,
which may cause null pointer deference. Add Null 
check for return value of malloc().

Found by our static analysis tool.

Signed-off-by: Chenyuan Mi <cymi20@fudan.edu.cn>
---
 tools/io_uring/io_uring-bench.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/io_uring/io_uring-bench.c b/tools/io_uring/io_uring-bench.c
index 7703f0118385..a7fedfdb9b84 100644
--- a/tools/io_uring/io_uring-bench.c
+++ b/tools/io_uring/io_uring-bench.c
@@ -560,6 +560,11 @@ int main(int argc, char *argv[])
 	pthread_create(&s->thread, NULL, submitter_fn, s);
 
 	fdepths = malloc(8 * s->nr_files);
+	if (!fdepths) {
+		printf("malloc failed");
+		return 1;
+	}
+
 	reap = calls = done = 0;
 	do {
 		unsigned long this_done = 0;
-- 
2.17.1


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

end of thread, other threads:[~2023-06-15 13:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-15 12:50 [PATCH] tools/io_uring: Fix missing check for return value of malloc() Chenyuan Mi
2023-06-15 13:00 ` Ammar Faizi
2023-06-15 13:13   ` Jens Axboe
     [not found]     ` <F5DC6786-D8E5-435F-8FDE-ABD4DD692367@fudan.edu.cn>
2023-06-15 13:37       ` [PATCH] tools/io uring: " Jens Axboe
2023-06-15 12:53 [PATCH] tools/io_uring: " Chenyuan Mi

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®