Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

of: module: add buffer overflow check in of_modalias()

In of_modalias(), if the buffer happens to be too small even for the 1st
snprintf() call, the len parameter will become negative and str parameter
(if not NULL initially) will point beyond the buffer's end. Add the buffer
overflow check after the 1st snprintf() call and fix such check after the
strlen() call (accounting for the terminating NUL char).

Fixes: bc575064d688 ("of/device: use of_property_for_each_string to parse compatible strings")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Link: https://lore.kernel.org/r/bbfc6be0-c687-62b6-d015-5141b93f313e@omp.ru
Signed-off-by: Rob Herring <robh@kernel.org>

authored by

Sergey Shtylyov and committed by
Rob Herring (Arm)
cf7385cb 649bad67

+4 -3
+4 -3
drivers/of/module.c
··· 21 21 csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T', 22 22 of_node_get_device_type(np)); 23 23 tsize = csize; 24 + if (csize >= len) 25 + csize = len > 0 ? len - 1 : 0; 24 26 len -= csize; 25 - if (str) 26 - str += csize; 27 + str += csize; 27 28 28 29 of_property_for_each_string(np, "compatible", p, compat) { 29 30 csize = strlen(compat) + 1; 30 31 tsize += csize; 31 - if (csize > len) 32 + if (csize >= len) 32 33 continue; 33 34 34 35 csize = snprintf(str, len, "C%s", compat);