From 57212c7c6e10e983ccf740b58ab83b52c47e1eae Mon Sep 17 00:00:00 2001 From: Wentao Liang Date: Fri, 17 Oct 2025 04:00:36 +0000 Subject: [PATCH] pcmcia: Add error handling for add_interval() in do_validate_mem() stable inclusion from stable-v6.6.105 commit 4a81f78caa53e0633cf311ca1526377d9bff7479 category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/ID0R49 CVE: CVE-2025-39920 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4a81f78caa53e0633cf311ca1526377d9bff7479 -------------------------------- [ Upstream commit 4a81f78caa53e0633cf311ca1526377d9bff7479 ] In the do_validate_mem(), the call to add_interval() does not handle errors. If kmalloc() fails in add_interval(), it could result in a null pointer being inserted into the linked list, leading to illegal memory access when sub_interval() is called next. This patch adds an error handling for the add_interval(). If add_interval() returns an error, the function will return early with the error code. Fixes: 7b4884ca8853 ("pcmcia: validate late-added resources") Signed-off-by: Wentao Liang Signed-off-by: Dominik Brodowski Signed-off-by: Sasha Levin Signed-off-by: Xiaomeng Zhang --- drivers/pcmcia/rsrc_nonstatic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index bf9d070a4496..da494fe451ba 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -375,7 +375,9 @@ static int do_validate_mem(struct pcmcia_socket *s, if (validate && !s->fake_cis) { /* move it to the validated data set */ - add_interval(&s_data->mem_db_valid, base, size); + ret = add_interval(&s_data->mem_db_valid, base, size); + if (ret) + return ret; sub_interval(&s_data->mem_db, base, size); } -- Gitee