[PATCH OLK-6.6 0/2] pstore: fix two ramoops error-path bugs
Two bugs in the ramoops error paths, found by review and confirmed with test-only reproducers against an unfixed kernel: - ramoops_init_prz() stores persistent_ram_new()'s ERR_PTR in the zone pointer and returns without clearing it; the probe error path then passes it to persistent_ram_free(), which dereferences it and oopses. - persistent_ram_buffer_map() computes buffer_size = size - sizeof(struct persistent_ram_buffer) with no lower bound, so a zone no larger than the header underflows buffer_size to a huge value and defeats the bounds checks in the write paths. The second patch adds a new failure return from persistent_ram_new() for undersized zones, which is exactly the error path that exposes the first bug: a tiny zone now leaves an ERR_PTR behind on cleanup. Applied without the first patch, it turns the memory-corruption bug into a probe-time panic on the same input, so the ERR_PTR fix is sent first. Pan Taixi (2): pstore: don't leave an ERR_PTR in the ramoops zone pointer pstore: reject persistent RAM zones too small for the buffer header fs/pstore/ram.c | 1 + fs/pstore/ram_core.c | 6 ++++++ 2 files changed, 7 insertions(+) -- 2.34.1
From: Andrea Parri <parri.andrea@gmail.com> stable inclusion from stable-v6.6.163 commit 7148d58404ff904c14a73247c6808bf93c7fb5d7 category: bugfix bugzilla: https://atomgit.com/src-openeuler/kernel/issues/21190 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=... -------------------------------- [ Upstream commit 70fec428c845216da98041b1ae9f16a8f54b3d68 ] ramoops_init_prz() stores the result of persistent_ram_new() in *prz and returns the error without clearing it when initialization fails. ramoops_probe() then cleans up through ramoops_free_przs(), which hands *prz to persistent_ram_free(); that treats the ERR_PTR as a valid zone and dereferences it, crashing the kernel. Clear *prz before returning so that cleanup sees a NULL zone. Fixes: b5d38e9bf1b0c ("pstore/ram: Add console messages handling") Assisted-by: LLM Signed-off-by: Andrea Parri <parri.andrea@gmail.com> Link: https://patch.msgid.link/20260921202317.70595-2-parri.andrea@gmail.com Signed-off-by: Kees Cook <kees@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Pan Taixi <pantaixi1@huawei.com> --- fs/pstore/ram.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 88b34fdbf759..736d6348a713 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -599,10 +599,11 @@ static int ramoops_init_prz(const char *name, cxt->memtype, PRZ_FLAG_ZAP_OLD, label); kfree(label); if (IS_ERR(*prz)) { int err = PTR_ERR(*prz); + *prz = NULL; dev_err(dev, "failed to request %s mem region (0x%zx@0x%llx): %d\n", name, sz, (unsigned long long)*paddr, err); return err; } -- 2.34.1
From: Andrea Parri <parri.andrea@gmail.com> stable inclusion from stable-v6.6.163 commit b1e677c18ba6c194fa247ac0f095417cf492a0eb category: bugfix bugzilla: https://atomgit.com/src-openeuler/kernel/issues/21190 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=... -------------------------------- [ Upstream commit 1b30df8662ac85a6759be4332f3bec7e3cb28efc ] persistent_ram_buffer_map() computes prz->buffer_size = size - sizeof(struct persistent_ram_buffer); without checking that size is large enough to hold the header. A ramoops zone configured with a tiny size (e.g. ramoops.pmsg_size=1) underflows buffer_size to a huge value, which defeats every bounds check in persistent_ram_write() and persistent_ram_write_user(); a write to /dev/pmsg0 then copies user data far past the end of the zone and corrupts kernel memory. Reject zones that are not larger than the buffer header. Fixes: 404a6043385de ("staging: android: persistent_ram: handle reserving and mapping memory") Assisted-by: LLM Signed-off-by: Andrea Parri <parri.andrea@gmail.com> Link: https://patch.msgid.link/20260921202317.70595-3-parri.andrea@gmail.com Signed-off-by: Kees Cook <kees@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Pan Taixi <pantaixi1@huawei.com> --- fs/pstore/ram_core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index 95675d4bab14..4d0728076897 100644 --- a/fs/pstore/ram_core.c +++ b/fs/pstore/ram_core.c @@ -505,10 +505,16 @@ static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size, struct persistent_ram_zone *prz, int memtype) { prz->paddr = start; prz->size = size; + if (size <= sizeof(struct persistent_ram_buffer)) { + pr_err("%s: persistent ram zone too small (%#llx bytes)\n", + prz->label, (unsigned long long)size); + return -EINVAL; + } + if (pfn_valid(start >> PAGE_SHIFT)) prz->vaddr = persistent_ram_vmap(start, size, memtype); else prz->vaddr = persistent_ram_iomap(start, size, memtype, prz->label); -- 2.34.1
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://atomgit.com/openeuler/kernel/merge_requests/31727 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/L3Q... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://atomgit.com/openeuler/kernel/merge_requests/31727 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/L3Q...
participants (2)
-
Pan Taixi -
patchwork bot