]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.6/of-module-prevent-null-pointer-dereference-in-vsnprintf.patch
a03dbbdb9fb5569b42f0ce0c063e843633f69573
[thirdparty/kernel/stable-queue.git] / queue-6.6 / of-module-prevent-null-pointer-dereference-in-vsnprintf.patch
1 From a1aa5390cc912934fee76ce80af5f940452fa987 Mon Sep 17 00:00:00 2001
2 From: Sergey Shtylyov <s.shtylyov@omp.ru>
3 Date: Wed, 27 Mar 2024 19:52:49 +0300
4 Subject: of: module: prevent NULL pointer dereference in vsnprintf()
5
6 From: Sergey Shtylyov <s.shtylyov@omp.ru>
7
8 commit a1aa5390cc912934fee76ce80af5f940452fa987 upstream.
9
10 In of_modalias(), we can get passed the str and len parameters which would
11 cause a kernel oops in vsnprintf() since it only allows passing a NULL ptr
12 when the length is also 0. Also, we need to filter out the negative values
13 of the len parameter as these will result in a really huge buffer since
14 snprintf() takes size_t parameter while ours is ssize_t...
15
16 Found by Linux Verification Center (linuxtesting.org) with the Svace static
17 analysis tool.
18
19 Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
20 Cc: stable@vger.kernel.org
21 Link: https://lore.kernel.org/r/1d211023-3923-685b-20f0-f3f90ea56e1f@omp.ru
22 Signed-off-by: Rob Herring <robh@kernel.org>
23 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24 ---
25 drivers/of/module.c | 8 ++++++++
26 1 file changed, 8 insertions(+)
27
28 --- a/drivers/of/module.c
29 +++ b/drivers/of/module.c
30 @@ -16,6 +16,14 @@ ssize_t of_modalias(const struct device_
31 ssize_t csize;
32 ssize_t tsize;
33
34 + /*
35 + * Prevent a kernel oops in vsnprintf() -- it only allows passing a
36 + * NULL ptr when the length is also 0. Also filter out the negative
37 + * lengths...
38 + */
39 + if ((len > 0 && !str) || len < 0)
40 + return -EINVAL;
41 +
42 /* Name & Type */
43 /* %p eats all alphanum characters, so %c must be used here */
44 csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T',