From: Eugen Hristev <eugen.hristev@linaro.org>
To: liaoweixiong@allwinnertech.com, linux-hardening@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: kees@kernel.org, gpiccoli@igalia.com, tony.luck@intel.com,
Eugen Hristev <eugen.hristev@linaro.org>
Subject: [PATCH] pstore/zone: avoid dereferencing zero sized ptr after init zones
Date: Fri, 27 Dec 2024 19:04:59 +0200 [thread overview]
Message-ID: <20241227170459.622630-1-eugen.hristev@linaro.org> (raw)
In psz_init_zones, if the requested area has a total_size less than
record_size, kcalloc will be called with c == 0 and will return
ZERO_SIZE_PTR.
Further, this will lead to an oops.
With this patch, in this scenario, it will look like this :
[ 6.865545] pstore_zone: total size : 28672 Bytes
[ 6.865547] pstore_zone: kmsg size : 65536 Bytes
[ 6.865549] pstore_zone: pmsg size : 0 Bytes
[ 6.865551] pstore_zone: console size : 0 Bytes
[ 6.865553] pstore_zone: ftrace size : 0 Bytes
[ 6.872095] pstore_zone: zone dmesg total_size too small
[ 6.878234] pstore_zone: alloc zones failed
Signed-off-by: Eugen Hristev <eugen.hristev@linaro.org>
---
fs/pstore/zone.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/pstore/zone.c b/fs/pstore/zone.c
index 694db616663f..50a765999b54 100644
--- a/fs/pstore/zone.c
+++ b/fs/pstore/zone.c
@@ -1217,6 +1217,10 @@ static struct pstore_zone **psz_init_zones(enum pstore_type_id type,
pr_err("allocate for zones %s failed\n", name);
return ERR_PTR(-ENOMEM);
}
+ if (unlikely(zones == ZERO_SIZE_PTR)) {
+ pr_err("zone %s total_size too small\n", name);
+ return ERR_PTR(-EINVAL);
+ }
for (i = 0; i < c; i++) {
zone = psz_init_zone(type, off, record_size);
--
2.43.0
next reply other threads:[~2024-12-27 17:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-27 17:04 Eugen Hristev [this message]
2025-01-09 17:48 ` [PATCH] pstore/zone: avoid dereferencing zero sized ptr after init zones Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241227170459.622630-1-eugen.hristev@linaro.org \
--to=eugen.hristev@linaro.org \
--cc=gpiccoli@igalia.com \
--cc=kees@kernel.org \
--cc=liaoweixiong@allwinnertech.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox