]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-6.6/gpio-cdev-check-for-null-labels-when-sanitizing-them-for-irqs.patch
0cd1c3fb4f7991900e9b7a07bbc3e57437d8428d
[thirdparty/kernel/stable-queue.git] / queue-6.6 / gpio-cdev-check-for-null-labels-when-sanitizing-them-for-irqs.patch
1 From b3b95964590a3d756d69ea8604c856de805479ad Mon Sep 17 00:00:00 2001
2 From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
3 Date: Thu, 4 Apr 2024 11:33:27 +0200
4 Subject: gpio: cdev: check for NULL labels when sanitizing them for irqs
5
6 From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
7
8 commit b3b95964590a3d756d69ea8604c856de805479ad upstream.
9
10 We need to take into account that a line's consumer label may be NULL
11 and not try to kstrdup() it in that case but rather pass the NULL
12 pointer up the stack to the interrupt request function.
13
14 To that end: let make_irq_label() return NULL as a valid return value
15 and use ERR_PTR() instead to signal an allocation failure to callers.
16
17 Cc: stable@vger.kernel.org
18 Fixes: b34490879baa ("gpio: cdev: sanitize the label before requesting the interrupt")
19 Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
20 Closes: https://lore.kernel.org/lkml/20240402093534.212283-1-naresh.kamboju@linaro.org/
21 Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
22 Tested-by: Anders Roxell <anders.roxell@linaro.org>
23 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24 ---
25 drivers/gpio/gpiolib-cdev.c | 19 ++++++++++++++-----
26 1 file changed, 14 insertions(+), 5 deletions(-)
27
28 --- a/drivers/gpio/gpiolib-cdev.c
29 +++ b/drivers/gpio/gpiolib-cdev.c
30 @@ -1012,7 +1012,16 @@ static u32 gpio_v2_line_config_debounce_
31
32 static inline char *make_irq_label(const char *orig)
33 {
34 - return kstrdup_and_replace(orig, '/', ':', GFP_KERNEL);
35 + char *new;
36 +
37 + if (!orig)
38 + return NULL;
39 +
40 + new = kstrdup_and_replace(orig, '/', ':', GFP_KERNEL);
41 + if (!new)
42 + return ERR_PTR(-ENOMEM);
43 +
44 + return new;
45 }
46
47 static inline void free_irq_label(const char *label)
48 @@ -1086,8 +1095,8 @@ static int edge_detector_setup(struct li
49 irqflags |= IRQF_ONESHOT;
50
51 label = make_irq_label(line->req->label);
52 - if (!label)
53 - return -ENOMEM;
54 + if (IS_ERR(label))
55 + return PTR_ERR(label);
56
57 /* Request a thread to read the events */
58 ret = request_threaded_irq(irq, edge_irq_handler, edge_irq_thread,
59 @@ -2194,8 +2203,8 @@ static int lineevent_create(struct gpio_
60 goto out_free_le;
61
62 label = make_irq_label(le->label);
63 - if (!label) {
64 - ret = -ENOMEM;
65 + if (IS_ERR(label)) {
66 + ret = PTR_ERR(label);
67 goto out_free_le;
68 }
69