Skip to content
Commit ea33f838 authored by Sergey Shtylyov's avatar Sergey Shtylyov Committed by GONG, Ruiqi
Browse files

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

mainline inclusion
from mainline-v6.10-rc1
commit cf7385cb26ac4f0ee6c7385960525ad534323252
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IA6SDQ
CVE: CVE-2024-38541

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cf7385cb26ac4f0ee6c7385960525ad534323252



---------------------------

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: bc575064 ("of/device: use of_property_for_each_string to parse compatible strings")
Signed-off-by: default avatarSergey Shtylyov <s.shtylyov@omp.ru>
Link: https://lore.kernel.org/r/bbfc6be0-c687-62b6-d015-5141b93f313e@omp.ru


Signed-off-by: default avatarRob Herring <robh@kernel.org>
Conflicts:
	drivers/of/module.c
[of_modalias() was in drivers/of/device.c before commit bd7a7ed7
("of: Move of_modalias() to module.c") and was named as
of_device_get_modalias() before commit 5c3d15e1 ("of: Update
of_device_get_modalias()"). Both commits are in v6.4.]
Signed-off-by: default avatarGONG, Ruiqi <gongruiqi1@huawei.com>
parent 886c09dc
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment