From: Greg KH <gregkh@linuxfoundation.org>
To: Shengzhuo Wei <me@cherr.cc>
Cc: sre@kernel.org, kees@kernel.org, linux-kernel@vger.kernel.org,
Andras Domokos <andras.domokos@nokia.com>,
Carlos Chinea <carlos.chinea@nokia.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] HSI: hsi_char: Fix use-after-free on device removal
Date: Thu, 27 Aug 2026 06:48:26 +0200 [thread overview]
Message-ID: <2026082727-hacker-flaky-2578@gregkh> (raw)
In-Reply-To: <20260827-hsi-char-uaf-v1-1-4f824216a541@cherr.cc>
On Thu, Aug 27, 2026 at 04:43:08AM +0800, Shengzhuo Wei wrote:
> hsc_open() stores a pointer to a channel embedded in the hsc_client_data
> in file->private_data, but hsc_remove() frees the whole hsc_client_data
> right after cdev_del(). If the HSI client device is removed while a
> channel is open, the next access from the file descriptor (a read, an
> ioctl or the final close) dereferences freed memory:
>
> CPU0 CPU1
> hsc_remove hsc_read
> cdev_del(&cl_data->cdev); channel->cl->rx_cfg ...
> kfree(cl_data); // use after free
>
> Fix it by tracking the hsc_client_data with a kref: each open file
> descriptor takes a reference, and hsc_remove() drops the initial one,
> so the object is freed only after the last descriptor is closed.
>
> Fixes: 4e69fc22753f ("HSI: hsi_char: Add HSI char device driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shengzhuo Wei <me@cherr.cc>
> ---
> drivers/hsi/clients/hsi_char.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hsi/clients/hsi_char.c b/drivers/hsi/clients/hsi_char.c
> index a31cc1466dd3ddf73762ce3d0213c96d64a190fd..479e5d6e94c8c03489464c4b39d81d697d104ce0 100644
> --- a/drivers/hsi/clients/hsi_char.c
> +++ b/drivers/hsi/clients/hsi_char.c
> @@ -96,6 +96,7 @@ struct hsc_channel {
> * @usecnt: Use count for claiming the HSI port (mutex protected)
> * @cl: Referece to the HSI client
> * @channels: Array of channels accessible by the client
> + * @kref: Reference count for the client data lifetime
> */
> struct hsc_client_data {
> struct cdev cdev;
> @@ -104,6 +105,7 @@ struct hsc_client_data {
> unsigned int usecnt;
> struct hsi_client *cl;
> struct hsc_channel channels[HSC_DEVS];
> + struct kref kref;
You now have 2 reference counts for the same structure, which is not how
to handle this at all :(
Please either make the cdev be a pointer, or use the correct cdev api
for handling this type of common problem.
thanks,
greg k-h
next prev parent reply other threads:[~2026-08-27 4:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 20:43 Shengzhuo Wei
2026-08-27 4:48 ` Greg KH [this message]
2026-08-27 5:09 ` Shengzhuo Wei
2026-08-27 5:15 ` Greg KH
2026-08-27 5:40 ` Shengzhuo Wei
2026-08-27 5:43 ` Greg KH
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=2026082727-hacker-flaky-2578@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=andras.domokos@nokia.com \
--cc=carlos.chinea@nokia.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=me@cherr.cc \
--cc=sre@kernel.org \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®