From: sashiko-bot@kernel.org
To: "Svyatoslav Ryhel" <clamor95@gmail.com>
Cc: devicetree@vger.kernel.org, linux-input@vger.kernel.org,
mfd@lists.linux.dev, linux-leds@vger.kernel.org, robh@kernel.org,
conor+dt@kernel.org, dmitry.torokhov@gmail.com, lee@kernel.org
Subject: Re: [PATCH v13 3/7] input: serio: Add driver for ASUS Transformer dock keyboard and touchpad
Date: Wed, 04 Nov 2026 12:39:16 +0000 [thread overview]
Message-ID: <sashiko-outbox-197277@kernel.org> (raw)
In-Reply-To: <20261104122606.215629-4-clamor95@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] input: serio: notifier order in asus_ec_kbc_probe() causes NULL deref or UAF
--
commit 8f5c105d6df4708eb2c002e7fe58ff80a2a0fb84
Author: Michał Mirosław <mirq-linux@rere.qmqm.pl>
input: serio: Add driver for ASUS Transformer dock keyboard and touchpad
This commit adds a serio driver for the keyboard and touchpad on the ASUS
Transformer dock, registering two serio ports and a notifier on the parent
EC to forward and remap incoming PS/2 data.
> diff --git a/drivers/input/serio/asus-transformer-ec-kbc.c b/drivers/input/serio/asus-transformer-ec-kbc.c
> new file mode 100644
> index 0000000000000..cff18da6d59d7
> --- /dev/null
> +++ b/drivers/input/serio/asus-transformer-ec-kbc.c
[ ... ]
> +static int asus_ec_kbc_notify(struct notifier_block *nb,
> + unsigned long action, void *data_)
> +{
[ ... ]
> + while (n--)
> + serio_interrupt(priv->sdev[port_idx], *data++, 0);
> +
> + return NOTIFY_OK;
> +}
[ ... ]
> +static int asus_ec_register_serio(struct platform_device *pdev, int idx, const char *name, int cmd)
> +{
> + struct asus_ec_kbc_data *priv = platform_get_drvdata(pdev);
> + struct i2c_client *parent = priv->parent;
> + struct serio *port = kzalloc_obj(*port);
> +
> + if (!port)
> + return -ENOMEM;
> +
> + priv->sdev[idx] = port;
> + port->dev.parent = &pdev->dev;
> + port->id.type = SERIO_8042;
> + port->id.extra = cmd & 0xFF;
> + port->write = asus_ec_serio_write;
> + port->port_data = (void *)priv;
> + snprintf(port->name, sizeof(port->name), "%s %s", priv->ec->model, name);
> + snprintf(port->phys, sizeof(port->phys), "i2c-%u-%04x/serio%d",
> + i2c_adapter_id(parent->adapter), parent->addr, idx);
> +
> + serio_register_port(port);
> +
> + return devm_add_action_or_reset(&pdev->dev, asus_ec_serio_remove, port);
> +}
> +
> +static void asus_ec_notifier_chain_unregister(void *data)
> +{
> + struct asus_ec_kbc_data *priv = data;
> + struct asusec_core *ec = priv->ec;
> +
> + blocking_notifier_chain_unregister(&ec->notify_list, &priv->nb);
> +}
> +
> +static int asus_ec_kbc_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct asusec_core *ec = dev_get_drvdata(dev->parent);
> + struct asus_ec_kbc_data *priv;
> + int error;
> +
> + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + platform_set_drvdata(pdev, priv);
> +
> + priv->ec = ec;
> + priv->parent = to_i2c_client(dev->parent);
> +
> + priv->nb.notifier_call = asus_ec_kbc_notify;
> + error = blocking_notifier_chain_register(&ec->notify_list, &priv->nb);
> + if (error)
> + return dev_err_probe(dev, error, "Failed to register blocking notifier chain");
> +
> + error = devm_add_action_or_reset(dev, asus_ec_notifier_chain_unregister, priv);
> + if (error)
> + return error;
> +
> + error = asus_ec_register_serio(pdev, 0, "Keyboard", 0);
> + if (error)
> + return error;
> +
> + error = asus_ec_register_serio(pdev, 1, "Touchpad", I8042_CMD_AUX_SEND);
> + if (error)
> + return error;
[Severity: High]
As reported by Dmitry Torokhov on v12 [1], registering the notifier before
initializing the serio ports and without checking whether the ports are ready
can lead to a null pointer dereference during probe or a use-after-free
during teardown.
In the parent MFD driver, asus_ec_probe() enables the threaded IRQ handler
asus_ec_interrupt() before adding the child MFD devices. Once
asus_ec_kbc_probe() calls blocking_notifier_chain_register(), an incoming EC
keyboard or touchpad interrupt can invoke asus_ec_kbc_notify() while
priv->sdev[0] and priv->sdev[1] are still NULL (or after priv->sdev[idx] =
port in asus_ec_register_serio(), before serio_register_port() initializes
port->lock). Passing priv->sdev[port_idx] to serio_interrupt() will then
dereference NULL or lock an uninitialized spinlock.
Additionally, because devm_add_action_or_reset() for
asus_ec_notifier_chain_unregister() is registered before the
asus_ec_serio_remove() actions in asus_ec_register_serio(), devm teardown runs
in reverse order:
asus_ec_serio_remove()
serio_unregister_port()
serio_disconnect_port()
serio_destroy_port() -> frees struct serio
...
asus_ec_notifier_chain_unregister()
During serio_disconnect_port(), the attached PS/2 driver sends disable/reset
commands over I2C, causing the EC to generate ACK interrupts while priv->nb
is still registered and priv->sdev[] holds dangling pointers to the freed
serio ports. Can the notifier be registered after the serio ports (or gated
on port readiness under a lock via serio start/stop or open/close callbacks)
so that interrupts cannot reach serio_interrupt() before registration or
after unregistration?
[1] https://lore.kernel.org/r/ate5K6ZdrSoBUI08@google.com
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261104122606.215629-1-clamor95@gmail.com?part=3
next prev parent reply other threads:[~2026-11-04 12:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 12:25 [PATCH v13 0/7] mfd: Add support for Asus Transformer embedded controller Svyatoslav Ryhel
2026-11-04 12:26 ` [PATCH v13 1/7] dt-bindings: embedded-controller: document ASUS Transformer EC Svyatoslav Ryhel
2026-11-04 12:26 ` [PATCH v13 2/7] mfd: Add driver for ASUS Transformer embedded controller Svyatoslav Ryhel
2026-11-04 12:43 ` sashiko-bot
2026-11-04 12:26 ` [PATCH v13 3/7] input: serio: Add driver for ASUS Transformer dock keyboard and touchpad Svyatoslav Ryhel
2026-11-04 12:39 ` sashiko-bot [this message]
2026-11-04 12:26 ` [PATCH v13 4/7] input: keyboard: Add driver for ASUS Transformer dock multimedia keys Svyatoslav Ryhel
2026-11-04 12:40 ` sashiko-bot
2026-11-04 12:26 ` [PATCH v13 5/7] leds: Add driver for ASUS Transformer LEDs Svyatoslav Ryhel
2026-11-04 12:33 ` sashiko-bot
2026-11-04 12:26 ` [PATCH v13 6/7] power: supply: Add driver for ASUS Transformer battery Svyatoslav Ryhel
2026-11-04 12:26 ` [PATCH v13 7/7] power: supply: Add charger driver for Asus Transformers Svyatoslav Ryhel
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-197277@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=clamor95@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=lee@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=mfd@lists.linux.dev \
--cc=robh@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