of: cpu: add check in __of_find_n_match_cpu_property()
PATCH 1/1 of: cpu: add check in __of_find_n_match_cpu_property()
In __of_find_n_match_cpu_property(), checking the variable ac for 0 won't prevent a possible overflow when multiplying it by sizeof(*cell). Besides, of_read_number() (called in the *for* loop) can't return correct result if that variable (which equals the #address-cells prop's value) exceeds 2, so additionally checking for that seems logical...
Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.
---
The patch is against the dt/linus branch of Rob Herring's linux.git repo...
drivers/of/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/cpu.c +1 -1
@@ -60,7 +60,7 @@ static bool __of_find_n_match_cpu_property(struct device_node *cpun, cell =of_get_property (cpun, prop_name, &prop_len);if (!cell && !ac &&arch_match_cpu_phys_id (cpu,0 ))return true; -if (!cell || !ac) +if (!cell || !ac || ac >2 )return false; prop_len /=sizeof (*cell) * ac;for (tid =0 ; tid < prop_len; tid++) {
Signature · 1 line
2.53.0
Quoted 9 lines · Sergey Shtylyov
In
__of_find_n_match_cpu_property(), checking the variable ac for 0 won't prevent a possible overflow when multiplying it bysizeof(*cell). Besides,of_read_number()(called in the *for* loop) can't return correct result if that variable (which equals the #address-cells prop's value) exceeds 2, so additionally checking for that seems logical...Found by Linux Verification Center (linuxtesting.org) with the Svace static analysis tool.
Quoted 9 lines
Fixes f3cea45a77c8 ("of: Fix iteration bug over CPU reg properties")Signed-off-by Sergey Shtylyov <[email protected]>---
The patch is against the dt/linus branch of Rob Herring's linux.git repo...drivers/of/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks!