Skip to content

Commit 2abc119

Browse files
committed
Merge: CVE-2024-38541: of: module: add buffer overflow check in of_modalias()
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4571 JIRA: https://issues.redhat.com/browse/RHEL-44273 CVE: CVE-2024-38541 ``` 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: bc57506 ("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> (cherry picked from commit cf7385c) ``` Signed-off-by: cki-backport-bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com> Approved-by: Mark Salter <msalter@redhat.com> Approved-by: Charles Mirabile <cmirabil@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Rado Vrbovsky <rvrbovsk@redhat.com>
2 parents b774030 + 089ea95 commit 2abc119

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/of/module.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len)
2929
csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',
3030
of_node_get_device_type(np));
3131
tsize = csize;
32+
if (csize >= len)
33+
csize = len > 0 ? len - 1 : 0;
3234
len -= csize;
33-
if (str)
34-
str += csize;
35+
str += csize;
3536

3637
of_property_for_each_string(np, "compatible", p, compat) {
3738
csize = strlen(compat) + 1;
3839
tsize += csize;
39-
if (csize > len)
40+
if (csize >= len)
4041
continue;
4142

4243
csize = snprintf(str, len, "C%s", compat);

0 commit comments

Comments
 (0)