From: sashiko-bot@kernel.org
To: "Michael Zaidman" <michael.zaidman@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH 09/13] HID: ft260: gpio: group sysfs attrs per HID interface
Date: Sat, 22 Aug 2026 21:54:17 +0000 [thread overview]
Message-ID: <20260822215417.F1B781F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260822213941.98882-10-michael.zaidman@gmail.com>
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
New issues:
- [Medium] The `i2c_enable` sysfs attribute is unintentionally removed for dual-mode devices.
- [Medium] The `i2c_reset` sysfs attribute is incorrectly exposed on the UART interface group.
Pre-existing issues:
- [High] Premature free of `dev` in `ft260_remove()` leads to multiple Use-After-Free conditions.
- [High] Double free and Use-After-Free of the `dev` structure in the probe error paths.
- [High] Missing and incorrectly ordered teardown of timer and workqueue leads to Use-After-Free.
- [High] On device hot-unplug, the driver frees critical resources before the TTY port is completely hung up, allowing concurrent TTY operations to trigger Use-After-Free.
- [High] Race condition Use-After-Free due to manual `kfree(dev)` before `devres` cleans up the registered gpiochip.
--
--- Patch [9]: [PATCH 09/13] HID: ft260: gpio: group sysfs attrs per HID interface ---
commit c899807eb1ab1f737fe08c45424f6b6a6de53615
Author: Michael Zaidman <michael.zaidman@gmail.com>
HID: ft260: gpio: group sysfs attrs per HID interface
Split the single sysfs attribute group into per-interface groups based
on chip mode (DCNF0/DCNF1).
> diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c
> index 554d8e3ddb6db..0a1875a1a7eca 100644
> --- a/drivers/hid/hid-ft260.c
> +++ b/drivers/hid/hid-ft260.c
[ ... ]
> @@ -1603,11 +1603,35 @@ static const struct attribute_group ft260_attr_group = {
> &dev_attr_gpio2_func.attr,
> &dev_attr_gpioa_func.attr,
> &dev_attr_gpiog_func.attr,
> + &dev_attr_clock_ctl.attr,
> + &dev_attr_i2c_reset.attr,
> + &dev_attr_clock.attr,
> + NULL
> + }
> +};
> +
> +static const struct attribute_group ft260_i2c_chip_mode_0_3_attr_group = {
> + .attrs = (struct attribute *[]) {
> + &dev_attr_hid_over_i2c_en.attr,
> + &dev_attr_i2c_reset.attr,
> + &dev_attr_clock.attr,
> + NULL
> + }
> +};
[Severity: Medium]
Is the omission of the dev_attr_i2c_enable.attr intentional for dual-mode
devices?
The commit message mentions splitting the groups per interface based on chip
mode, but it looks like the i2c_enable attribute was completely dropped from
the dual-mode I2C group here.
Could this silently break userspace applications relying on this sysfs entry?
> +
> +static const struct attribute_group ft260_uart_chip_mode_0_2_3_attr_group = {
> + .attrs = (struct attribute *[]) {
> + &dev_attr_chip_mode.attr,
> + &dev_attr_pwren_status.attr,
> + &dev_attr_suspend_status.attr,
> + &dev_attr_power_saving_en.attr,
> + &dev_attr_gpio2_func.attr,
> + &dev_attr_gpioa_func.attr,
> + &dev_attr_gpiog_func.attr,
> &dev_attr_uart_mode.attr,
> &dev_attr_uart_dcd_ri.attr,
> &dev_attr_clock_ctl.attr,
> &dev_attr_i2c_reset.attr,
[Severity: Medium]
Does this unintentionally expose the I2C reset attribute on the UART
interface?
According to the patch description, the UART interface should only contain
GPIO and UART attributes, but dev_attr_i2c_reset.attr is included here.
> - &dev_attr_clock.attr,
> NULL
> }
> };
[ ... ]
> @@ -2306,12 +2339,14 @@ static int ft260_uart_probe(struct ft260_device *dev,
> cfg->uart_mode = FT260_UART_CFG_FLOW_CTRL_NONE;
>
> if (dev->chip_mode & FT260_MODE_UART ||
> - dev->chip_mode == FT260_MODE_ALL) {
> + dev->chip_mode == FT260_MODE_ALL ||
> + dev->chip_mode == FT260_MODE_BOTH) {
> ret = ft260_gpio_init(dev, cfg);
> if (ret)
> goto err_hid_report;
>
> - ret = sysfs_create_group(&hdev->dev.kobj, &ft260_attr_group);
> + ret = sysfs_create_group(&hdev->dev.kobj,
> + &ft260_uart_chip_mode_0_2_3_attr_group);
> if (ret < 0) {
> hid_err(hdev, "failed to create sysfs attrs\n");
> goto err_hid_report;
[Severity: High]
This is a pre-existing issue, but can jumping to err_hid_report lead to a
double free or use-after-free of the dev structure?
If sysfs_create_group() fails, the error path goes to err_hid_report, which
calls ft260_uart_port_remove(dev). This drops the TTY port reference via
tty_port_put().
If the TTY is not open, the refcount drops to 0, and the port destructor
frees dev immediately. The function then returns the error code back to
ft260_probe(), which unconditionally jumps to hid_fail and executes
kfree(dev).
Also, does this error path bypass workqueue cancellation?
The error path here deletes the timer but appears to completely omit calling
cancel_work_sync(), which could trigger a use-after-free if the timer had
already scheduled the work before dev is freed.
Finally, does the manual kfree(dev) in ft260_probe() race with devres?
The ft260_gpio_init() function registers a gpiochip using
devm_gpiochip_add_data(). The devres cleanup won't run until after the probe
function fully returns, leaving a window where the active gpiochip can be
accessed by userspace while its private data (dev) has already been freed.
> }
[ ... ]
> @@ -2418,12 +2453,19 @@ static void ft260_remove(struct hid_device *hdev)
> ft260_uart_port_remove(dev);
> /* dev is still needed, so we will free it in _destroy func */
> if (dev->chip_mode & FT260_MODE_UART ||
> - dev->chip_mode == FT260_MODE_ALL)
> - sysfs_remove_group(&hdev->dev.kobj, &ft260_attr_group);
> + dev->chip_mode == FT260_MODE_ALL ||
> + dev->chip_mode == FT260_MODE_BOTH)
> + sysfs_remove_group(&hdev->dev.kobj,
> + &ft260_uart_chip_mode_0_2_3_attr_group);
[Severity: High]
This is a pre-existing issue, but does checking dev->chip_mode here risk
dereferencing a freed pointer?
When ft260_uart_port_remove(dev) is called just above this block, it drops
the TTY port reference. If the port isn't open, the port destructor runs
and immediately frees dev. Accessing dev->chip_mode and removing the sysfs
group afterward would then be a use-after-free.
Does the order of operations in ft260_remove() also leave the device
vulnerable to incoming USB events after it is freed?
Because hid_hw_stop() is called much later in this function, there is a
window where incoming HID reports can trigger ft260_raw_event() on a
freed dev.
Are there concurrent teardown risks during device hot-unplug?
Looking at ft260_uart_port_remove(), kfifo_free() is called before the
asynchronous tty_port_tty_hangup(). If userspace writes to the TTY during
this window, ft260_uart_write() could push data into the explicitly
freed xmit_fifo.
Could the workqueue also be incorrectly rescheduled during unbind?
Earlier in ft260_remove(), cancel_work_sync(&dev->wakeup_work) is called
before timer_delete_sync() (which happens inside ft260_uart_port_remove).
This allows the timer to expire after the work is canceled, rescheduling
the work to execute after dev is freed.
>
> } else {
> if (dev->chip_mode == FT260_MODE_I2C)
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260822213941.98882-1-michael.zaidman@gmail.com?part=9
next prev parent reply other threads:[~2026-08-22 21:54 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-22 21:39 [PATCH 00/13] HID: ft260: add UART and GPIO support, plus I2C fixes Michael Zaidman
2026-08-22 21:39 ` [PATCH 01/13] HID: ft260: add serial driver Michael Zaidman
2026-08-22 22:00 ` sashiko-bot
2026-08-25 7:49 ` Linus Walleij
2026-08-25 8:12 ` Linus Walleij
2026-08-27 19:16 ` Michael Zaidman
2026-08-22 21:39 ` [PATCH 02/13] HID: ft260: uart: bring-up fixes Michael Zaidman
2026-08-22 21:56 ` sashiko-bot
2026-08-22 21:39 ` [PATCH 03/13] HID: ft260: add GPIO support on top of UART Michael Zaidman
2026-08-22 21:56 ` sashiko-bot
2026-08-25 7:44 ` Linus Walleij
2026-08-27 20:39 ` Michael Zaidman
2026-08-22 21:39 ` [PATCH 04/13] HID: ft260: i2c: reduce driver module loading time Michael Zaidman
2026-08-22 21:51 ` sashiko-bot
2026-08-22 21:39 ` [PATCH 05/13] HID: ft260: i2c: silence sysfs store big-numbers Michael Zaidman
2026-08-22 21:51 ` sashiko-bot
2026-08-22 21:39 ` [PATCH 06/13] HID: ft260: i2c: reduce bus-error message severity Michael Zaidman
2026-08-22 21:52 ` sashiko-bot
2026-08-22 21:39 ` [PATCH 07/13] HID: ft260: uart: enable flow control Michael Zaidman
2026-08-22 21:52 ` sashiko-bot
2026-08-22 21:39 ` [PATCH 08/13] HID: ft260: uart: add modem pins control via ioctl Michael Zaidman
2026-08-22 21:54 ` sashiko-bot
2026-08-25 8:08 ` Linus Walleij
2026-08-27 22:08 ` Michael Zaidman
2026-08-22 21:39 ` [PATCH 09/13] HID: ft260: gpio: group sysfs attrs per HID interface Michael Zaidman
2026-08-22 21:54 ` sashiko-bot [this message]
2026-08-25 8:13 ` Linus Walleij
2026-08-27 20:50 ` Michael Zaidman
2026-08-22 21:39 ` [PATCH 10/13] HID: ft260: uart: fix active-low RTS/CTS/DTR/DSR polarity Michael Zaidman
2026-08-22 22:03 ` sashiko-bot
2026-08-25 8:16 ` Linus Walleij
2026-08-27 21:08 ` Michael Zaidman
2026-08-22 21:39 ` [PATCH 11/13] HID: ft260: i2c: fix large write transaction failure Michael Zaidman
2026-08-22 22:02 ` sashiko-bot
2026-08-22 21:39 ` [PATCH 12/13] HID: ft260: workaround for TN_189 errata endpoint STALL after enumeration Michael Zaidman
2026-08-22 22:03 ` sashiko-bot
2026-08-22 21:39 ` [PATCH 13/13] HID: ft260: i2c: abort in-flight transfers with STOP before reset Michael Zaidman
2026-08-22 22:12 ` sashiko-bot
2026-08-25 8:21 ` [PATCH 00/13] HID: ft260: add UART and GPIO support, plus I2C fixes Linus Walleij
2026-08-27 13:27 ` Lee Jones
2026-08-27 18:53 ` Michael Zaidman
2026-08-27 20:51 ` Lee Jones
2026-08-27 22:25 ` Michael Zaidman
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=20260822215417.F1B781F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=michael.zaidman@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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