All of lore.kernel.org
 help / color / mirror / Atom feed
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 03/13] HID: ft260: add GPIO support on top of UART
Date: Sat, 22 Aug 2026 21:56:09 +0000	[thread overview]
Message-ID: <20260822215609.75EBF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260822213941.98882-4-michael.zaidman@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Uninitialized GPIO shadow state (`dev->gpio`) corrupts the hardware configuration of unrelated pins during updates.
- [High] Unvalidated `cfg->uart_mode` read from the device is used as an array index, leading to an out-of-bounds read.
- [Medium] Setting a GPIO direction to output introduces a hardware glitch by splitting the operation into two non-atomic USB requests.
- [Medium] Setting the UART mode to OFF unintentionally disables all non-UART GPIOs.
--

--- Patch [3]: [PATCH 03/13] HID: ft260: add GPIO support on top of UART ---
commit d5e8f3410c2633ba90471af57e3193f95d3193d4
Author: Michael Zaidman <michael.zaidman@gmail.com>
    
HID: ft260: add GPIO support on top of UART
    
Add gpiochip support for the FT260 multifunctional pins, including
GPIO2/GPIOA/GPIOG function selection via sysfs, and enable the
available GPIOs according to the active UART mode.
    
Link: https://lore.kernel.org/lkml/20230211115752.26276-2-michael.zaidman@gmail.com/

> diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c
> index b6c408267a685..cc3b8f5791dea 100644
> --- a/drivers/hid/hid-ft260.c
> +++ b/drivers/hid/hid-ft260.c
[ ... ]
> @@ -906,6 +1023,322 @@ static const struct i2c_algorithm ft260_i2c_algo = {
>  	.functionality = ft260_functionality,
>  };
>  
> +static void ft260_gpio_en_set(struct ft260_device *dev, u16 bitmap)
> +{
> +	dev->gpio_en |= bitmap & FT260_GPIO_MASK;
> +}
> +
> +static void ft260_gpio_en_clr(struct ft260_device *dev, u16 bitmap)
> +{
> +	dev->gpio_en &= ~bitmap & FT260_GPIO_MASK;
> +}
> +
> +static void ft260_gpio_en_update(struct hid_device *hdev, u8 req, u8 value)
> +{
> +	u16 bitmap;
> +	struct ft260_device *dev = hid_get_drvdata(hdev);
> +
> +	switch (req) {
> +
> +	case FT260_SET_I2C_MODE:
> +		bitmap = FT260_GPIO_I2C_DEFAULT;
> +		break;
> +	case FT260_SET_UART_MODE:
> +		switch (value) {
> +		case FT260_UART_CFG_FLOW_CTRL_OFF:
> +			bitmap = (u16)FT260_GPIO_MASK;
> +			break;
[ ... ]
> +		}
> +		ft260_gpio_en_clr(dev, bitmap);
> +		bitmap = dev->gpio_uart_mode[value];
> +		ft260_gpio_en_set(dev, bitmap);
> +		goto exit;

[Severity: Medium]
Does setting the UART flow control to OFF unintentionally disable all non-UART
GPIOs? 

When value is FT260_UART_CFG_FLOW_CTRL_OFF (0), bitmap is set to
FT260_GPIO_MASK, which represents all 14 GPIO bits. Calling
ft260_gpio_en_clr() inadvertently clears all of these bits from dev->gpio_en.
Subsequently, only the FT260_GPIO_UART_MODE_0_SET bits are restored, which
permanently disables I2C and other multi-function GPIOs until they are
manually re-enabled.

[ ... ]
> +static int ft260_gpio_set(struct gpio_chip *gc, u32 offset, int value)
> +{
> +	int ret = 0;
> +	struct ft260_gpio_write_request_report rep;
> +	struct ft260_device *dev = gpiochip_get_data(gc);
> +	struct hid_device *hdev = dev->hdev;
> +
> +	if (offset >= FT260_GPIO_TOTAL) {
> +		hid_err(hdev, "%s: invalid offset %d\n", __func__, offset);
> +		return -EINVAL;
> +	}
> +
> +	ft260_dbg("offset %d val %d\n", offset, value);
> +
> +	mutex_lock(&dev->lock);
> +
> +	if (!(dev->gpio_en & (1 << offset))) {
> +		hid_err(hdev, "%s: wrong pin function %d\n", __func__, offset);
> +		ret = -EINVAL;
> +		goto exit;
> +	}
> +
> +	rep.report = FT260_GPIO;
> +	rep.gpio = dev->gpio;
> +
> +	if (offset < FT260_GPIO_MAX) {
[ ... ]
> +	ret = ft260_hid_feature_report_set(hdev, (u8 *)&rep, sizeof(rep));

[Severity: High]
Does this corrupt the hardware configuration of unrelated pins?

The shadow state dev->gpio is zero-initialized via kzalloc during device
allocation and is never synced with the actual hardware state during
ft260_gpio_init(). Because the entire dev->gpio struct is written to the
device here, won't all unmodified pins be unintentionally configured to input
mode with value 0?

> +	if (unlikely(ret < 0)) {
> +		hid_err(hdev, "%s: cannot set GPIO: %d\n", __func__, ret);
> +		goto exit;
> +	}
> +
> +	dev->gpio = rep.gpio;
> +	ret = 0;
> +exit:
> +	mutex_unlock(&dev->lock);
> +	return ret;
> +}
> +
> +static int ft260_gpio_direction_set(struct gpio_chip *gc, u32 offset,
> +				    int value, int direction)
> +{
> +	int ret;
> +	struct ft260_gpio_read_request_report buf;
> +	struct ft260_gpio_write_request_report *rep;
> +	struct ft260_device *dev = gpiochip_get_data(gc);
> +	struct hid_device *hdev = dev->hdev;
> +
[ ... ]
> +	ret = ft260_hid_feature_report_set(hdev, (u8 *)rep, sizeof(*rep));
> +	if (unlikely(ret < 0)) {
> +		hid_err(hdev, "%s: cannot set GPIO: %d\n", __func__, ret);
> +		goto exit;
> +	}
> +
> +	dev->gpio = rep->gpio;
> +	mutex_unlock(&dev->lock);
> +
> +	if (direction == FT260_GPIO_DIR_OUTPUT)
> +		ft260_gpio_set(gc, offset, value);

[Severity: Medium]
Could this introduce a hardware glitch when changing a pin's direction to
output? 

The code updates the direction bits to output without setting the corresponding
value bits, and writes this immediately to the device via
ft260_hid_feature_report_set(). Then it sends a second USB request via
ft260_gpio_set() to set the desired output value. During the window between
these two USB transfers, will the pin assert an unintended logic level?

> +
> +	return 0;
> +exit:
> +	mutex_unlock(&dev->lock);
> +	return ret;
> +}
[ ... ]
> +static int ft260_gpio_init(struct ft260_device *dev,
> +			   struct ft260_get_system_status_report *cfg)
> +{
> +	int ret;
> +	int label_sz;
> +	char *label;
> +	struct ft260_get_chip_version_report ver;
> +	struct hid_device *hdev = dev->hdev;
> +	char prefix[] = "ft260_";
> +	u8 mode = cfg->chip_mode;
> +
> +	hid_info(hdev, "initialize gpio chip\n");
> +
> +	dev->gpio_uart_mode[0] = (u16)FT260_GPIO_UART_MODE_0_SET;
> +	dev->gpio_uart_mode[1] = (u16)FT260_GPIO_UART_MODE_1_SET;
> +	dev->gpio_uart_mode[2] = (u16)FT260_GPIO_UART_MODE_2_SET;
> +	dev->gpio_uart_mode[3] = (u16)FT260_GPIO_UART_MODE_3_SET;
> +	dev->gpio_uart_mode[4] = (u16)FT260_GPIO_UART_MODE_4_SET;
> +
> +	if (mode == FT260_MODE_ALL)
> +		mode = FT260_MODE_BOTH;
> +
> +	if (mode & FT260_MODE_UART)
> +		dev->gpio_en |= dev->gpio_uart_mode[cfg->uart_mode];

[Severity: High]
Can this read out of bounds? 

cfg->uart_mode is read directly from the device via a USB feature report in
ft260_get_system_config(). If a malicious or malfunctioning USB device returns
a uart_mode >= 5, won't this leak kernel heap data into dev->gpio_en or crash
since dev->gpio_uart_mode only has 5 elements?

> +	else
> +		dev->gpio_en |= FT260_GPIO_UART_DEFAULT;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260822213941.98882-1-michael.zaidman@gmail.com?part=3

  reply	other threads:[~2026-08-22 21:56 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 [this message]
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
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=20260822215609.75EBF1F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.