pstore/zone: Add a null pointer check to the psz_kmsg_read
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.
Signed-off-by Kunwu Chan <[email protected]>
--- fs/pstore/zone.c | 2 ++ 1 file changed, 2 insertions(+)
fs/pstore/zone.c +2 -0
@@ -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
Kees Cook
AppliedQuoted 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