pcmcia: Add error handling for add_interval() in do_validate_mem()
PATCH 1/1 pcmcia: Add error handling for add_interval() in do_validate_mem()
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.
--- drivers/pcmcia/rsrc_nonstatic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pcmcia/rsrc_nonstatic.c +3 -1
@@ -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); }
Signature · 1 line
2.42.0.windows.2
Am Mon, Jan 20, 2025 at 09:10:06PM +0800 schrieb Wentao Liang:
Quoted 21 lines
In the
do_validate_mem(), the call toadd_interval()does not handle errors. Ifkmalloc()fails inadd_interval(), it could result in a null pointer being inserted into the linked list, leading to illegal memory access whensub_interval()is called next.This patch adds an error handling for the
add_interval(). Ifadd_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 <[email protected]>--- drivers/pcmcia/rsrc_nonstatic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/pcmcia/rsrc_nonstatic.c +0
-0
drivers/pcmcia/rsrc_nonstatic.c static int do_validate_mem(struct pcmcia_socket *s, · line 382
Quoted 9 lines
drivers/pcmcia/rsrc_nonstatic.c +3
-1@@ -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); }
Applied to pcmcia-next, thanks.
Best,
Dominik