Linux Hardening
 help / color / mirror / Atom feed
* [PATCH] pstore/ram: Return directly after a failed kasprintf() call in ramoops_init_prz()
@ 2024-01-17 20:24 Markus Elfring
  2024-01-18  2:03 ` Kunwu Chan
  2024-01-18  5:29 ` Dan Carpenter
  0 siblings, 2 replies; 4+ messages in thread
From: Markus Elfring @ 2024-01-17 20:24 UTC (permalink / raw)
  To: linux-hardening, kernel-janitors, Guilherme G. Piccoli,
	Joel Fernandes, Kees Cook, Tony Luck
  Cc: LKML, Günter Röck, Sai Prakash Ranjan, Kunwu Chan

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 17 Jan 2024 21:09:22 +0100

The result from a call of the function “kasprintf” was passed to
a subsequent function call without checking for a null pointer before
(according to a memory allocation failure).
This issue was detected by using the Coccinelle software.

Thus return directly after a failed kasprintf() call.

Fixes: 1227daa43bce1 ("pstore/ram: Clarify resource reservation labels")
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/pstore/ram.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 88b34fdbf759..1a673a4af17c 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -595,6 +595,9 @@ static int ramoops_init_prz(const char *name,
 	}

 	label = kasprintf(GFP_KERNEL, "ramoops:%s", name);
+	if (!label)
+		return -ENOMEM;
+
 	*prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info,
 				  cxt->memtype, PRZ_FLAG_ZAP_OLD, label);
 	kfree(label);
--
2.43.0


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

end of thread, other threads:[~2024-01-18  8:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-17 20:24 [PATCH] pstore/ram: Return directly after a failed kasprintf() call in ramoops_init_prz() Markus Elfring
2024-01-18  2:03 ` Kunwu Chan
2024-01-18  5:29 ` Dan Carpenter
2024-01-18  8:38   ` Markus Elfring

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