* [PATCH] pstore/zone: avoid dereferencing zero sized ptr after init zones
@ 2024-12-27 17:04 Eugen Hristev
2025-01-09 17:48 ` Kees Cook
0 siblings, 1 reply; 2+ messages in thread
From: Eugen Hristev @ 2024-12-27 17:04 UTC (permalink / raw)
To: liaoweixiong, linux-hardening, linux-kernel
Cc: kees, gpiccoli, tony.luck, Eugen Hristev
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] pstore/zone: avoid dereferencing zero sized ptr after init zones
2024-12-27 17:04 [PATCH] pstore/zone: avoid dereferencing zero sized ptr after init zones Eugen Hristev
@ 2025-01-09 17:48 ` Kees Cook
0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2025-01-09 17:48 UTC (permalink / raw)
To: Eugen Hristev
Cc: liaoweixiong, linux-hardening, linux-kernel, gpiccoli, tony.luck
On Fri, Dec 27, 2024 at 07:04:59PM +0200, Eugen Hristev wrote:
> 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);
> + }
I'd rather catch this after the calculation of "c" rather than after a
zero-sized allocation. Can you rework the patch to test it then?
-Kees
>
> for (i = 0; i < c; i++) {
> zone = psz_init_zone(type, off, record_size);
> --
> 2.43.0
>
--
Kees Cook
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-09 17:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-27 17:04 [PATCH] pstore/zone: avoid dereferencing zero sized ptr after init zones Eugen Hristev
2025-01-09 17:48 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox