diff options
| author | Ruipeng Qi | 2026-02-03 10:03:58 +0800 |
|---|---|---|
| committer | Sasha Levin | 2026-03-04 07:20:36 -0500 |
| commit | 1da904e84de608907662ad8a51ba9c571d61e003 (patch) | |
| tree | b0b2bf367f82807834da51916c3666eedf3a5286 /fs | |
| parent | a4345acbe390b82fb63276aff18e522a62857c0f (diff) | |
pstore: ram_core: fix incorrect success return when vmap() fails
[ Upstream commit 05363abc7625cf18c96e67f50673cd07f11da5e9 ]
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.
Signed-off-by: Ruipeng Qi <ruipengqi3@gmail.com>
Link: https://patch.msgid.link/20260203020358.3315299-1-ruipengqi3@gmail.com
Signed-off-by: Kees Cook <kees@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/pstore/ram_core.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index c9eaacdec37e..7b6d6378a3b8 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -458,6 +458,13 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size, 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 * into the mapping to represent the actual "start" location. |
