]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.8/pstore-zone-add-a-null-pointer-check-to-the-psz_kmsg.patch
607903cd60b0d88a038233afa624b7603d4e70f3
[thirdparty/kernel/stable-queue.git] / queue-6.8 / pstore-zone-add-a-null-pointer-check-to-the-psz_kmsg.patch
1 From 3c98ece1115c285ae2bc523b31284a4ee6d69ae4 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Thu, 18 Jan 2024 18:02:06 +0800
4 Subject: pstore/zone: Add a null pointer check to the psz_kmsg_read
5
6 From: Kunwu Chan <chentao@kylinos.cn>
7
8 [ Upstream commit 98bc7e26e14fbb26a6abf97603d59532475e97f8 ]
9
10 kasprintf() returns a pointer to dynamically allocated memory
11 which can be NULL upon failure. Ensure the allocation was successful
12 by checking the pointer validity.
13
14 Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
15 Link: https://lore.kernel.org/r/20240118100206.213928-1-chentao@kylinos.cn
16 Signed-off-by: Kees Cook <keescook@chromium.org>
17 Signed-off-by: Sasha Levin <sashal@kernel.org>
18 ---
19 fs/pstore/zone.c | 2 ++
20 1 file changed, 2 insertions(+)
21
22 diff --git a/fs/pstore/zone.c b/fs/pstore/zone.c
23 index 2770746bb7aa1..abca117725c81 100644
24 --- a/fs/pstore/zone.c
25 +++ b/fs/pstore/zone.c
26 @@ -973,6 +973,8 @@ static ssize_t psz_kmsg_read(struct pstore_zone *zone,
27 char *buf = kasprintf(GFP_KERNEL, "%s: Total %d times\n",
28 kmsg_dump_reason_str(record->reason),
29 record->count);
30 + if (!buf)
31 + return -ENOMEM;
32 hlen = strlen(buf);
33 record->buf = krealloc(buf, hlen + size, GFP_KERNEL);
34 if (!record->buf) {
35 --
36 2.43.0
37