pstore: ram_core: fix incorrect success return when vmap() fails
PATCH 1/1 pstore: ram_core: fix incorrect success return when vmap() fails
From: Ruipeng Qi <[email protected]>
In persistent_ram_vmap(), vmap() may return NULL on failure.
If offset is non-zero, adding offset_in_page(start) causes the function to return a non-NULL pointer even though the mapping failed. persistent_ram_buffer_map() therefore incorrectly returns success.
Subsequent access to prz->buffer may dereference an invalid address and cause crashes.
Add proper NULL checking for vmap() failures.
--- fs/pstore/ram_core.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/pstore/ram_core.c +7 -0
@@ -446,6 +446,13 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size, vaddr =vmap (pages, page_count,VM_MAP |VM_IOREMAP , prot);kfree (pages); +/* +* vmap() may fail and return NULL. Do not add the offset in this +* case, otherwise a NULL mapping would appear successful. +*/ +if (!vaddr) +return NULL ; +/* * Since vmap() uses page granularity, we must add the offset * into the page here, to get the byte granularity address
Signature · 1 line
2.25.1
Quoted 10 lines · ruipengqi
In
persistent_ram_vmap(),vmap()may return NULL on failure.If offset is non-zero, adding
offset_in_page(start)causes the function to return a non-NULL pointer even though the mapping failed.persistent_ram_buffer_map()therefore incorrectly returns success.Subsequent access to
prz->buffermay dereference an invalid address and cause crashes.[...]
Applied to for-next/pstore, thanks!
[1/1] pstore: ram_core: fix incorrect success return when vmap() fails
https://git.kernel.org/kees/c/05363abc7625
Take care,
Signature · 1 line
Kees Cook