From: sashiko-bot@kernel.org
To: "Karlos Abel" <kabel@voidship.net>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH 2/2] Input: test state seeding across device registration
Date: Sat, 10 Oct 2026 18:08:49 +0000 [thread overview]
Message-ID: <sashiko-outbox-166792@kernel.org> (raw)
In-Reply-To: <20261010180031.7-3-kabel@voidship.net>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] input: missing absinfo allocation check in input_set_abs_params causes NULL pointer dereference
- [Medium] input: dangling pointer match in test teardown allows accidental binding to unrelated devices
--
commit 2e31a0267a25d47a7a2da67f7fbb5534d7ebbae1
Author: Karlos Abel <kabel@voidship.net>
Input: test state seeding across device registration
This commit adds KUnit coverage for input events used to initialize device
state before registration. It exercises both original event buffers and larger
resizing buffers, verifying the correct retention and delivery of states.
> diff --git a/drivers/input/tests/input_test.c b/drivers/input/tests/input_test.c
> index e105ce71a920a..889d9e7ec922f 100644
> --- a/drivers/input/tests/input_test.c
> +++ b/drivers/input/tests/input_test.c
[ ... ]
> @@ -161,11 +161,179 @@ static void input_test_grab(struct kunit *test)
[ ... ]
> +static bool input_seed_match(struct input_handler *handler,
> + struct input_dev *dev)
> +{
> + struct input_seed_test *seed = container_of(handler, struct input_seed_test,
> + handler);
> +
> + return seed->dev == dev;
> +}
[ ... ]
> + /* An ABS axis also raises the estimated event-buffer size. */
> + if (resize) {
> + input_set_abs_params(seed->dev, ABS_X, 0, 100, 0, 0);
> + seed->dev->hint_events_per_packet = 128;
> + }
[Severity: High]
Does this code risk a NULL pointer dereference if the internal allocation
for `absinfo` fails?
Functions like `input_set_abs_params()` set `EV_ABS` in `dev->evbit` and the
specific axis in `dev->absbit` before calling `input_alloc_absinfo()`. If this
allocation fails (e.g., due to memory pressure), they return silently, leaving
the capability bits permanently set while `dev->absinfo` remains NULL.
[ ... ]
> + /* Initialize state before registration, without a SYN_REPORT. */
> + input_set_timestamp(seed->dev, seed_timestamp);
> + input_report_switch(seed->dev, SW_DOCK, 1);
> + if (resize)
> + input_report_abs(seed->dev, ABS_X, 42);
Because this test explicitly relies on seeding initial absolute axis state via
`input_report_abs()` before registration, if the allocation failed during
`input_set_abs_params()`, this subsequent event injection causes
`input_handle_abs_event()` to unconditionally dereference
`dev->absinfo[code].value`. This results in a NULL pointer dereference
regression before the delayed missing-absinfo check in
`input_register_device()` can catch it.
Should the failure state of `input_set_abs_params()` be checked here, or
should `input_alloc_absinfo()` be verified to have succeeded before
continuing?
[ ... ]
> +unregister_device:
> + input_unregister_device(seed->dev);
> + input_unregister_handler(&seed->handler);
[Severity: Medium]
Can this sequence lead to a use-after-free regression and accidental binding
to unrelated devices?
In this teardown path of `input_test_seed_events()`,
`input_unregister_device()` is called before `input_unregister_handler()`.
For a non-devres device, unregistering calls `input_put_device()`, dropping
the final reference and immediately freeing the device memory. However, the
custom test handler remains on the global `input_handler_list`.
If another input device registers concurrently during this window, the input
core iterates all handlers and calls `input_seed_match()`. This function
evaluates `seed->dev == dev` using the freed memory. If the slab allocator
reused that exact memory address for the newly registered device, the match
will incorrectly return true, and the test handler will erroneously attempt
to bind to the unrelated device.
Should `input_unregister_handler()` be called before
`input_unregister_device()` to avoid this race condition?
> + return;
> +
> +unregister_handler:
> + input_unregister_handler(&seed->handler);
> +free_device:
> + input_free_device(seed->dev);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261010180031.7-1-kabel@voidship.net?part=2
next prev parent reply other threads:[~2026-10-10 18:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 18:00 [PATCH 0/2] Input: discard pre-registration events and test state seeding Karlos Abel
2026-10-10 18:00 ` [PATCH 1/2] Input: discard pre-registration events before attaching handlers Karlos Abel
2026-10-10 18:00 ` [PATCH 2/2] Input: test state seeding across device registration Karlos Abel
2026-10-10 18:08 ` sashiko-bot [this message]
2026-10-11 4:45 ` [PATCH 0/2] Input: discard pre-registration events and test state seeding Dmitry Torokhov
2026-10-11 22:30 ` Karlos Abel
2026-10-12 6:12 ` Dmitry Torokhov
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-166792@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=kabel@voidship.net \
--cc=linux-input@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