Compare

28d2905d77bc2e7c20260a6bc6b4179bdf95cb06..bd22f7e63509fa758cf500d9af3e88a3d3df96be

gpio: shared: fix use-after-free bug when adding shared proxies

The GPIO lookup table can stay alive for longer than the kobject whose
name string's address we're assigning to lookup->dev_id. Fix a potential
UAF by duplicating the string.

Cc: stable@vger.kernel.org
Fixes: a060b8c511ab ("gpiolib: implement low-level, shared GPIO support")
Reviewed-by: Linus Walleij <linusw@kernel.org>
Link: https://patch.msgid.link/20261014-gpio-shared-fwnode-lookup-v4-1-2253ad645fd6@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com> · 2026-10-14 09:38 UTC

Browse files
8 files changed, +20 −15
modified drivers/gpio/gpio-nct6694.c
@@ -444,7 +444,7 @@ static int nct6694_gpio_probe(struct platform_device *pdev)
444 444 data->gpio.set_config = nct6694_set_config;
445 445 data->gpio.init_valid_mask = nct6694_init_valid_mask;
446 446 data->gpio.base = -1;
447 - data->gpio.can_sleep = false;
447 + data->gpio.can_sleep = true;
448 448 data->gpio.owner = THIS_MODULE;
449 449 data->gpio.ngpio = NCT6694_NR_GPIO;
450 450
modified drivers/gpio/gpiolib-shared.c
@@ -450,7 +450,6 @@ int gpio_shared_add_proxy_lookup(struct device *consumer, struct fwnode_handle *
450 450 const char *con_id, unsigned long lflags)
451 451 {
452 452 const char *dev_id = dev_name(consumer);
453 - struct gpiod_lookup_table *lookup;
454 453 struct gpio_shared_entry *entry;
455 454 struct gpio_shared_ref *ref;
456 455
@@ -480,18 +479,22 @@ int gpio_shared_add_proxy_lookup(struct device *consumer, struct fwnode_handle *
480 479 if (!key)
481 480 return -ENOMEM;
482 481
483 - lookup = kzalloc_flex(*lookup, table, 2);
482 + struct gpiod_lookup_table *lookup __free(kfree) =
483 + kzalloc_flex(*lookup, table, 2);
484 484 if (!lookup)
485 485 return -ENOMEM;
486 486
487 487 pr_debug("Adding machine lookup entry for a shared GPIO for consumer %s, with key '%s' and con_id '%s'\n",
488 488 dev_id, key, ref->con_id ?: "none");
489 489
490 - lookup->dev_id = dev_id;
490 + lookup->dev_id = kstrdup(dev_id, GFP_KERNEL);
491 + if (!lookup->dev_id)
492 + return -ENOMEM;
493 +
491 494 lookup->table[0] = GPIO_LOOKUP(no_free_ptr(key), 0,
492 495 ref->con_id, lflags);
493 496
494 - ref->lookup = lookup;
497 + ref->lookup = no_free_ptr(lookup);
495 498 gpiod_add_lookup_table(ref->lookup);
496 499
497 500 return 0;
@@ -611,6 +614,7 @@ void gpio_device_teardown_shared(struct gpio_device *gdev)
611 614 if (ref->lookup) {
612 615 gpiod_remove_lookup_table(ref->lookup);
613 616 kfree(ref->lookup->table[0].key);
617 + kfree(ref->lookup->dev_id);
614 618 kfree(ref->lookup);
615 619 ref->lookup = NULL;
616 620 }
modified fs/ocfs2/dlm/dlmcommon.h
@@ -435,8 +435,6 @@ enum {
435 435 DLM_DEREF_LOCKRES_DONE = 522,
436 436 };
437 437
438 - extern spinlock_t dlm_reco_state_lock;
439 -
440 438 struct dlm_reco_node_data
441 439 {
442 440 int state;
modified fs/ocfs2/dlm/dlmdebug.c
@@ -736,11 +736,8 @@ static int debug_state_print(struct dlm_ctxt *dlm, char *buf, int len)
736 736 buf + out, len - out);
737 737 out += scnprintf(buf + out, len - out, "\n");
738 738
739 - spin_unlock(&dlm->spinlock);
740 -
741 739 /* Recovery Node State: */
742 740 out += scnprintf(buf + out, len - out, "Recovery Node State:\n");
743 - spin_lock(&dlm_reco_state_lock);
744 741 list_for_each_entry(node, &dlm->reco.node_data, list) {
745 742 switch (node->state) {
746 743 case DLM_RECO_NODE_DATA_INIT:
@@ -772,7 +769,7 @@ static int debug_state_print(struct dlm_ctxt *dlm, char *buf, int len)
772 769 node->node_num, state);
773 770 }
774 771
775 - spin_unlock(&dlm_reco_state_lock);
772 + spin_unlock(&dlm->spinlock);
776 773
777 774 return out;
778 775 }
modified fs/ocfs2/dlm/dlmrecovery.c
@@ -80,7 +80,7 @@ static int dlm_lockres_master_requery(struct dlm_ctxt *dlm,
80 80
81 81 static u64 dlm_get_next_mig_cookie(void);
82 82
83 - DEFINE_SPINLOCK(dlm_reco_state_lock);
83 + static DEFINE_SPINLOCK(dlm_reco_state_lock);
84 84 static DEFINE_SPINLOCK(dlm_mig_cookie_lock);
85 85 static u64 dlm_mig_cookie = 1;
86 86
modified include/linux/sched/signal.h
@@ -130,8 +130,8 @@ struct signal_struct {
130 130 * process will inherit a flag if they should look for a
131 131 * child_subreaper process at exit.
132 132 */
133 - bool is_child_subreaper;
134 - bool has_child_subreaper;
133 + unsigned int is_child_subreaper:1;
134 + unsigned int has_child_subreaper:1;
135 135 unsigned int autoreap:1;
136 136
137 137 #ifdef CONFIG_POSIX_TIMERS
modified samples/pidfd/Makefile
@@ -1,4 +1,4 @@
1 1 # SPDX-License-Identifier: GPL-2.0
2 - userprogs-always-y += pidfd-metadata
2 + usertprogs-always-y += pidfd-metadata
3 3
4 4 userccflags += -I usr/include
modified tools/gpio/Makefile
@@ -7,7 +7,13 @@ bindir ?= /usr/bin
7 7 # isn't set and when invoked from selftests build, where srctree
8 8 # is set to ".". building_out_of_srctree is undefined for in srctree
9 9 # builds
10 + ifeq ($(srctree),)
11 + update_srctree := 1
12 + endif
10 13 ifndef building_out_of_srctree
14 + update_srctree := 1
15 + endif
16 + ifeq ($(update_srctree),1)
11 17 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
12 18 srctree := $(patsubst %/,%,$(dir $(srctree)))
13 19 endif