From: Wei Jie Law <98lawweijie@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Andrew Duggan <aduggan@synaptics.com>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH] Input: synaptics-rmi4 - remove the F34 sysfs group when probe fails
Date: Mon, 24 Aug 2026 20:27:51 +0800 [thread overview]
Message-ID: <20260824122751.76415-1-98lawweijie@gmail.com> (raw)
rmi_driver_probe() creates the F34 firmware attribute group directly on
the rmi_device's kobject:
retval = rmi_f34_create_sysfs(rmi_dev);
if (retval)
goto err;
but rmi_f34_remove_sysfs() is only ever called from
rmi_driver_remove(), which does not run when probe fails. Every error
path taken after that point -- input_register_device(), rmi_irq_init(),
rmi_enable_sensor() -- therefore leaves the group in place on a device
that never finished binding.
The driver core clears the device's driver data when probe fails, so
what is left behind is a set of world-readable attributes whose show()
handlers dereference that now-NULL pointer:
static ssize_t rmi_driver_bootloader_id_show(struct device *dev, ...)
{
struct rmi_driver_data *data = dev_get_drvdata(dev);
struct rmi_function *fn;
fn = data->f34_container;
bootloader_id, configuration_id and update_fw_status are all mode 0444,
so any local user can dereference it. Reaching the failure does not
need privileges either: a device that simply stops answering a register
read makes rmi_enable_sensor() fail, which is past the group creation.
An emulated RMI4 touchpad over /dev/uhid that leaves the second read of
the F01 interrupt-status register unanswered, on v6.12.105 with
CONFIG_KASAN=y:
rmi4_physical rmi4-00: Failed to read irqs, code=-11
rmi4_physical rmi4-00: probe with driver rmi4_physical failed with error -11
and then, from an ordinary user:
$ cat /sys/bus/rmi4/devices/rmi4-00/bootloader_id
Oops: general protection fault, probably for non-canonical address
0xdffffc0000000004: 0000 [#1] PREEMPT SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000020-0x0000000000000027]
CPU: 0 UID: 1000 PID: 1851 Comm: cat Tainted: G E
RIP: 0010:rmi_driver_bootloader_id_show+0x4d/0x1b0 [rmi_core]
dev_attr_show+0x46/0xc0
sysfs_kf_seq_show+0x1f1/0x3c0
seq_read_iter+0x2f8/0x1150
vfs_read+0x699/0xa00
one oops per attribute.
Add an err_remove_sysfs label that drops the group, and route the error
paths below rmi_f34_create_sysfs() through it. rmi_f34_create_sysfs()
failing on its own account goes to err_destroy_functions instead, which
also repairs a second leak on that path: it used to "goto err" and skip
rmi_free_function_list() entirely, leaving the function devices
registered on the RMI bus with a parent whose driver data is gone. The
resulting order matches rmi_driver_remove().
After this change the same device leaves no attributes behind, the reads
fail with -ENOENT, and no oops is reported; a well-behaved device still
probes and keeps its F34 group.
Fixes: 29fd0ec2bdbe ("Input: synaptics-rmi4 - add support for F34 device reflash")
Cc: stable@vger.kernel.org
Signed-off-by: Wei Jie Law <98lawweijie@gmail.com>
---
drivers/input/rmi4/rmi_driver.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index 5d49a9021c7d..144b203e636a 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -1255,7 +1255,7 @@ static int rmi_driver_probe(struct device *dev)
retval = rmi_f34_create_sysfs(rmi_dev);
if (retval)
- goto err;
+ goto err_destroy_functions;
if (data->input) {
rmi_driver_set_input_name(rmi_dev, data->input);
@@ -1264,14 +1264,14 @@ static int rmi_driver_probe(struct device *dev)
if (retval) {
dev_err(dev, "%s: Failed to register input device.\n",
__func__);
- goto err_destroy_functions;
+ goto err_remove_sysfs;
}
}
}
retval = rmi_irq_init(rmi_dev);
if (retval < 0)
- goto err_destroy_functions;
+ goto err_remove_sysfs;
if (data->f01_container->dev.driver) {
/* Driver already bound, so enable ATTN now. */
@@ -1284,6 +1284,8 @@ static int rmi_driver_probe(struct device *dev)
err_disable_irq:
rmi_disable_irq(rmi_dev, false);
+err_remove_sysfs:
+ rmi_f34_remove_sysfs(rmi_dev);
err_destroy_functions:
rmi_free_function_list(rmi_dev);
err:
--
2.43.0
next reply other threads:[~2026-08-24 12:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 12:27 Wei Jie Law [this message]
2026-08-24 12:41 ` [PATCH] Input: synaptics-rmi4 - remove the F34 sysfs group when probe fails sashiko-bot
2026-08-25 10:38 ` Wei Jie LAW
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260824122751.76415-1-98lawweijie@gmail.com \
--to=98lawweijie@gmail.com \
--cc=aduggan@synaptics.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox