[PATCH v2] Input: fix potential use-after-free in input_devices_seq_show
From: Habil Eren Türker
Date: Mon Sep 28 2026 - 13:13:42 EST
The input_devices_seq_show() function accesses the input_dev structure
while holding input_mutex. However, the device can still be freed
concurrently, leading to a use-after-free.
Fix this by taking a reference to the input device in
input_devices_seq_start() and dropping it in input_devices_seq_stop().
Reported-by: syzbot+bc6b37960b1d13f68f9f@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=bc6b37960b1d13f68f9f
Tested-by: Habil Eren Türker <habilerenturker@xxxxxxxxxxx>
Signed-off-by: Habil Eren Türker <habilerenturker@xxxxxxxxxxx>
---
Changes in v2:
- Added Reported-by and Closes tags for the Syzbot report.
- No functional changes.
drivers/input/input.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/input/input.c b/drivers/input/input.c
index cf6fecea7..14a95e816 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -1051,6 +1051,7 @@ static __poll_t input_proc_devices_poll(struct file *file, poll_table *wait)
static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos)
{
struct input_seq_state *state = seq->private;
+ void *v;
int error;
error = mutex_lock_interruptible(&input_mutex);
@@ -1061,7 +1062,11 @@ static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos)
state->mutex_acquired = true;
- return seq_list_start(&input_dev_list, *pos);
+ v = seq_list_start(&input_dev_list, *pos);
+ if (v)
+ input_get_device(container_of(v, struct input_dev, node));
+
+ return v;
}
static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos)
@@ -1077,6 +1082,17 @@ static void input_seq_stop(struct seq_file *seq, void *v)
mutex_unlock(&input_mutex);
}
+static void input_devices_seq_stop(struct seq_file *seq, void *v)
+{
+ struct input_seq_state *state = seq->private;
+
+ if (v)
+ input_put_device(container_of(v, struct input_dev, node));
+
+ if (state->mutex_acquired)
+ mutex_unlock(&input_mutex);
+}
+
static void input_seq_print_bitmap(struct seq_file *seq, const char *name,
unsigned long *bitmap, int max)
{
@@ -1151,7 +1167,7 @@ static int input_devices_seq_show(struct seq_file *seq, void *v)
static const struct seq_operations input_devices_seq_ops = {
.start = input_devices_seq_start,
.next = input_devices_seq_next,
- .stop = input_seq_stop,
+ .stop = input_devices_seq_stop,
.show = input_devices_seq_show,
};
--
2.47.3