Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "ChunAn Wu" <an.wu@canonical.com>, linux-serial@vger.kernel.org
Subject: Re: [PATCH v4 3/3] platform/x86: lenovo-yoga-tab2-pro-1380-fastcharger: Bind through normal serdev matching
Date: Sat, 24 Oct 2026 04:07:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-183538@kernel.org> (raw)
In-Reply-To: <20261024022930.2704030-4-an.wu@canonical.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] serdev: type confusion in serdev_device_match() via driver id_table
--

commit bc4039918b4164f5e3178978c756b91d89a4bde7
Author: ChunAn Wu <an.wu@canonical.com>

platform/x86: lenovo-yoga-tab2-pro-1380-fastcharger: Bind through normal serdev matching

This commit switches the Lenovo Yoga Tab 2 Pro 1380 fastcharger driver from
manual driver attachment via device_driver_attach() to standard serdev modalias
matching by passing KBUILD_MODNAME to serdev_device_add() and adding an
id_table to yt2_1380_fc_serdev_driver.

> diff --git a/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c b/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c
> index 8551ab4d2c7db..d0bd9d4e3137c 100644
> --- a/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c
> +++ b/drivers/platform/x86/lenovo/yoga-tab2-pro-1380-fastcharger.c
> @@ -219,11 +219,17 @@ static int yt2_1380_fc_serdev_probe(struct serdev_device *serdev)
>  	return 0;
>  }
>  
> +static const struct serdev_device_id yt2_1380_fc_serdev_id[] = {
> +	{ KBUILD_MODNAME },
> +	{ }
> +};
> +
>  static struct serdev_device_driver yt2_1380_fc_serdev_driver = {
>  	.probe = yt2_1380_fc_serdev_probe,
>  	.driver = {
>  		.name = KBUILD_MODNAME,
>  	},
> +	.id_table = yt2_1380_fc_serdev_id,
>  };

[Severity: High]
Does adding id_table to yt2_1380_fc_serdev_driver trigger a type confusion and
out-of-bounds read in serdev_device_match() when matching against
serdev_controller devices on serdev_bus_type?

In drivers/tty/serdev/core.c, serdev_controller_alloc() places controller
devices on serdev_bus_type:

    device_initialize(&ctrl->dev);
    ctrl->dev.type = &serdev_ctrl_type;
    ctrl->dev.bus = &serdev_bus_type;

When yt2_1380_fc_module_init() calls serdev_device_driver_register() for
yt2_1380_fc_serdev_driver (or when a new serdev_controller is added), the
driver core runs serdev_device_match() against every device on
serdev_bus_type, including struct serdev_controller instances:

static int serdev_device_match(struct device *dev, const struct device_driver *drv)
{
	const struct serdev_device *serdev = to_serdev_device(dev);
	const struct serdev_device_driver *sdrv = to_serdev_device_driver(drv);

	if (acpi_driver_match_device(dev, drv))
		return 1;

	if (of_driver_match_device(dev, drv))
		return 1;

	return !!serdev_match_id(sdrv->id_table, serdev->modalias);
}

Because serdev_device_match() does not check is_serdev_device(dev) before
casting dev with to_serdev_device(dev), and yt2_1380_fc_serdev_driver has no
ACPI or OF match table, serdev_device_match() falls through to
serdev_match_id(sdrv->id_table, serdev->modalias) on struct serdev_controller
devices.

In struct serdev_device, modalias[SERDEV_NAME_SIZE] starts at offset
sizeof(struct device) + 4, which in struct serdev_controller overlaps the
struct device *host pointer, ctrl->nr, ctrl->serdev, ctrl->ops, and extends 12
bytes past sizeof(struct serdev_controller). When the overlapping byte at
modalias[0] is non-zero, serdev_match_id() passes that non-string memory and
trailing out-of-bounds bytes to strcmp().

Should serdev_device_match() verify is_serdev_device(dev) before casting dev
to struct serdev_device?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261024022930.2704030-1-an.wu@canonical.com?part=3

  reply	other threads:[~2026-10-24  4:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-24  2:29 [PATCH v4 0/3] serdev: handle devices without an ACPI or device tree node ChunAn Wu
2026-10-24  2:29 ` [PATCH v4 1/3] " ChunAn Wu
2026-10-24  4:09   ` sashiko-bot
2026-10-24  2:29 ` [PATCH v4] platform/x86: dell-uart-backlight: Bind through normal serdev matching ChunAn Wu
2026-10-24  2:35   ` sashiko-bot
2026-10-24 11:59   ` kernel test robot
2026-10-24 12:03     ` Markus Probst
2026-10-24 17:42   ` kernel test robot
2026-10-24  2:29 ` [PATCH v4 3/3] platform/x86: lenovo-yoga-tab2-pro-1380-fastcharger: " ChunAn Wu
2026-10-24  4:07   ` sashiko-bot [this message]
2026-10-24  3:50 ` [PATCH v4 2/3] platform/x86: dell-uart-backlight: " ChunAn Wu
2026-10-24  4:02   ` sashiko-bot
2026-10-24  8:40 ` [PATCH v4 0/3] serdev: handle devices without an ACPI or device tree node An Wu
2026-10-24 11:48   ` Markus Probst

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=sashiko-outbox-183538@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=an.wu@canonical.com \
    --cc=linux-serial@vger.kernel.org \
    --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