firmware: stratix10-svc: fix a missing check on list iterator
Subsystems (2)
PATCH RESEND 1/1 firmware: stratix10-svc: fix a missing check on list iterator
The bug is here:
pmem->vaddr = NULL;
The list iterator 'pmem' will point to a bogus position containing HEAD if the list is empty or no element is found. This case must be checked before any use of the iterator, otherwise it will lead to a invalid memory access.
To fix this bug, just gen_pool_free/set NULL/list_del() and return when found, otherwise list_del HEAD and return;
--- drivers/firmware/stratix10-svc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/firmware/stratix10-svc.c +6 -6
@@ -941,17 +941,17 @@ EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory);void stratix10_svc_free_memory (struct stratix10_svc_chan *chan,void *kaddr) {struct stratix10_svc_data_mem *pmem; -size_t size =0 ;list_for_each_entry (pmem, &svc_data_mem, node)if (pmem->vaddr == kaddr) { - size = pmem->size; -break ; +gen_pool_free (chan->ctrl->genpool, + (unsigned long )kaddr, pmem->size); + pmem->vaddr =NULL ; +list_del (&pmem->node); +return ; } -gen_pool_free (chan->ctrl->genpool, (unsigned long )kaddr, size); - pmem->vaddr =NULL ; -list_del (&pmem->node); +list_del (&svc_data_mem); }EXPORT_SYMBOL_GPL (stratix10_svc_free_memory);
Signature · 1 line
2.17.1
Quoted 36 lines · Xiaomeng Tong
The bug is here:
pmem->vaddr = NULL;The list iterator 'pmem' will point to a bogus position containing HEAD if the list is empty or no element is found. This case must be checked before any use of the iterator, otherwise it will lead to a invalid memory access.
To fix this bug, just gen_pool_free/set NULL/list_del() and return when found, otherwise
list_delHEAD and return;Fixes 7ca5ce896524f ("firmware: add Intel Stratix10 service layer driver")Signed-off-by Xiaomeng Tong <[email protected]>--- drivers/firmware/stratix10-svc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/firmware/stratix10-svc.c +4
-3@@ -941,17 +941,17 @@ EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory);void stratix10_svc_free_memory (struct stratix10_svc_chan *chan,void *kaddr) {struct stratix10_svc_data_mem *pmem; -size_t size =0 ;list_for_each_entry (pmem, &svc_data_mem, node)if (pmem->vaddr == kaddr) { - size = pmem->size; -break ; +gen_pool_free (chan->ctrl->genpool, + (unsigned long )kaddr, pmem->size); + pmem->vaddr =NULL ; +list_del (&pmem->node);
drivers/firmware/stratix10-svc.c EXPORT_SYMBOL_GPL(stratix10_svc_allocate_memory); · line 957
Quoted 10 lines
drivers/firmware/stratix10-svc.c +2
-3+return ; } -gen_pool_free (chan->ctrl->genpool, (unsigned long )kaddr, size); - pmem->vaddr =NULL ; -list_del (&pmem->node); +list_del (&svc_data_mem); }EXPORT_SYMBOL_GPL (stratix10_svc_free_memory);