Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Doruk Tan Ozturk" <doruk@0sec.ai>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v3 2/2] HID: uclogic: fix desc_ptr leak in probe error path
Date: Mon, 13 Jul 2026 22:12:39 +0000	[thread overview]
Message-ID: <20260713221240.103E61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260713215950.24193-2-doruk@0sec.ai>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Use-After-Free of `drvdata->pen_input` in `uclogic_inrange_timeout()` when `hidinput_connect()` fails during probe.
--

--- Patch [2]: [PATCH v3 2/2] HID: uclogic: fix desc_ptr leak in probe error path ---
commit b37d55bfcac132529f188bc93436f75e1da9c66f
Author: Doruk Tan Ozturk <doruk@0sec.ai>

HID: uclogic: fix desc_ptr leak in probe error path

This commit fixes a memory leak in the uclogic_probe() error path. It
ensures that drvdata->desc_ptr is explicitly freed when probe fails, since
the normal cleanup in uclogic_remove() is not called in this scenario.

> diff --git a/drivers/hid/hid-uclogic-core.c b/drivers/hid/hid-uclogic-core.c
> index d74f98efa8794..ad9914ed0c717 100644
> --- a/drivers/hid/hid-uclogic-core.c
> +++ b/drivers/hid/hid-uclogic-core.c
> @@ -265,8 +265,10 @@ static int uclogic_probe(struct hid_device *hdev,
>  	return 0;
>  failure:

[Severity: High]
This is a pre-existing issue, but is there a use-after-free risk involving
drvdata->pen_input if hidinput_connect() fails during hid_hw_start()?

During probe, uclogic_input_configured() (drivers/hid/hid-uclogic-core.c)
stores a pointer to the input device before registration completes:

		/* Remember the input device so we can simulate events */
		drvdata->pen_input = hi->input;

If a subsequent input registration fails in hidinput_connect()
(drivers/hid/hid-input.c), the code unwinds and frees all inputs:

out_unwind:
	/* unwind the ones we already registered */
	hidinput_disconnect(hid);

	return -1;

Because the driver sets .raw_event, hid_connect() ignores this -1 return
value. As a result, hid_hw_start() returns 0, the driver binds successfully,
and this failure block is bypassed.

When a pen report later arrives and arms drvdata->inrange_timer, the timer
callback uclogic_inrange_timeout() dereferences the freed pointer:

	struct input_dev *input = drvdata->pen_input;

	if (input == NULL)
		return;
	input_report_abs(input, ABS_PRESSURE, 0);

Could this sequence lead to a dangling pointer being dereferenced?

>  	/* Assume "remove" might not be called if "probe" failed */
> -	if (params_initialized)
> +	if (params_initialized) {
> +		kfree(drvdata->desc_ptr);
>  		uclogic_params_cleanup(&drvdata->params);
> +	}
>  	/*
>  	 * If hid_hw_start() started I/O and then failed, raw_event may have
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260713215950.24193-1-doruk@0sec.ai?part=2

  reply	other threads:[~2026-07-13 22:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13 21:59 [PATCH v3 1/2] HID: uclogic: fix UAF on inrange_timer at teardown and probe error Doruk Tan Ozturk
2026-07-13 21:59 ` [PATCH v3 2/2] HID: uclogic: fix desc_ptr leak in probe error path Doruk Tan Ozturk
2026-07-13 22:12   ` sashiko-bot [this message]
2026-07-13 22:17 ` [PATCH v3 1/2] HID: uclogic: fix UAF on inrange_timer at teardown and probe error sashiko-bot

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=20260713221240.103E61F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=doruk@0sec.ai \
    --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