Skip to content

Commit 067cdf0

Browse files
ehristevkees
authored andcommitted
pstore/zone: avoid dereferencing zero sized ptr after init zones
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> Link: https://lore.kernel.org/r/20250110125714.2594719-1-eugen.hristev@linaro.org Signed-off-by: Kees Cook <kees@kernel.org>
1 parent 542243a commit 067cdf0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

fs/pstore/zone.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,11 @@ static struct pstore_zone **psz_init_zones(enum pstore_type_id type,
12121212
}
12131213

12141214
c = total_size / record_size;
1215+
if (unlikely(!c)) {
1216+
pr_err("zone %s total_size too small\n", name);
1217+
return ERR_PTR(-EINVAL);
1218+
}
1219+
12151220
zones = kcalloc(c, sizeof(*zones), GFP_KERNEL);
12161221
if (!zones) {
12171222
pr_err("allocate for zones %s failed\n", name);

0 commit comments

Comments
 (0)