Skip to content

Commit bffce9b

Browse files
committed
Merge tag 'pstore-v7.0-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull pstore updates from Kees Cook: - Catch unlikely NULL return from vmap() (Ruipeng Qi) - Handle corner case of past incomplete buffer fills causing heap overflow (Sai Ritvik Tanksalkar) * tag 'pstore-v7.0-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: pstore/ram: fix buffer overflow in persistent_ram_save_old() pstore: ram_core: fix incorrect success return when vmap() fails
2 parents eecb03b + 5669645 commit bffce9b

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

fs/pstore/ram_core.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,17 @@ void persistent_ram_save_old(struct persistent_ram_zone *prz)
298298
if (!size)
299299
return;
300300

301+
/*
302+
* If the existing buffer is differently sized, free it so a new
303+
* one is allocated. This can happen when persistent_ram_save_old()
304+
* is called early in boot and later for a timer-triggered
305+
* survivable crash when the crash dumps don't match in size
306+
* (which would be extremely unlikely given kmsg buffers usually
307+
* exceed prz buffer sizes).
308+
*/
309+
if (prz->old_log && prz->old_log_size != size)
310+
persistent_ram_free_old(prz);
311+
301312
if (!prz->old_log) {
302313
persistent_ram_ecc_old(prz);
303314
prz->old_log = kvzalloc(size, GFP_KERNEL);
@@ -446,6 +457,13 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size,
446457
vaddr = vmap(pages, page_count, VM_MAP | VM_IOREMAP, prot);
447458
kfree(pages);
448459

460+
/*
461+
* vmap() may fail and return NULL. Do not add the offset in this
462+
* case, otherwise a NULL mapping would appear successful.
463+
*/
464+
if (!vaddr)
465+
return NULL;
466+
449467
/*
450468
* Since vmap() uses page granularity, we must add the offset
451469
* into the page here, to get the byte granularity address

0 commit comments

Comments
 (0)