Skip to contentSkip to conversation

pstore/zone: Add a null pointer check to the psz_kmsg_read

PATCH Applied Kunwu Chan 2 participants 2 messages Jan 18, 2024 – Feb 1, 2024 Pstore filesystem

lore
Share & tools
lore

Kunwu Chan

author
#0 lore raw

PATCH 1/1 pstore/zone: Add a null pointer check to the psz_kmsg_read

kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Ensure the allocation was successful by checking the pointer validity.

---
 fs/pstore/zone.c | 2 ++
 1 file changed, 2 insertions(+)
fs/pstore/zone.c +2 -0
index 2770746bb7aa..abca117725c8 100644
@@ -973,6 +973,8 @@ static ssize_t psz_kmsg_read(struct pstore_zone *zone,
 		char *buf = kasprintf(GFP_KERNEL, "%s: Total %d times\n",
 				      kmsg_dump_reason_str(record->reason),
 				      record->count);
+		if (!buf)
+			return -ENOMEM;
 		hlen = strlen(buf);
 		record->buf = krealloc(buf, hlen + size, GFP_KERNEL);
 		if (!record->buf) {
Signature · 1 line
2.39.2
Applied
#1 lore raw
Quoted 5 lines · Kunwu Chan

kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Ensure the allocation was successful by checking the pointer validity.

Applied to for-next/pstore, thanks!

[1/1] pstore/zone: Add a null pointer check to the psz_kmsg_read

      https://git.kernel.org/kees/c/69f381e67d6f

Take care,

Signature · 1 line
Kees Cook