mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Basavaraj Natikar <bnatikar@amd.com>
To: Jiri Kosina <jikos@kernel.org>, Olivier Sobrie <olivier@sobrie.be>
Cc: Basavaraj Natikar <basavaraj.natikar@amd.com>,
	Benjamin Tissoires <bentiss@kernel.org>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] HID: amd_sfh: free driver_data after destroying hid device
Date: Fri, 2 Aug 2024 16:25:33 +0530	[thread overview]
Message-ID: <d1c3ab42-107d-4ce0-9d47-9870084c9514@amd.com> (raw)
In-Reply-To: <nycvar.YFH.7.76.2408021247560.12664@cbobk.fhfr.pm>



On 8/2/2024 4:18 PM, Jiri Kosina wrote:
> On Tue, 23 Jul 2024, Olivier Sobrie wrote:
>
>> HID driver callbacks aren't called anymore once hid_destroy_device() has
>> been called. Hence, hid driver_data should be freed only after the
>> hid_destroy_device() function returned as driver_data is used in several
>> callbacks.
>>
>> I observed a crash with kernel 6.10.0 on my T14s Gen 3, after enabling
>> KASAN to debug memory allocation, I got this output:
> [ ... snip ... ]
>> KASAN reports a use-after-free of hid->driver_data in function
>> amd_sfh_get_report(). The backtrace indicates that the function is called
>> by amdtp_hid_request() which is one of the callbacks of hid device.
>> The current make sure that driver_data is freed only once
>> hid_destroy_device() returned.
>>
>> Note that I observed the crash both on v6.9.9 and v6.10.0. The
>> code seems to be as it was from the early days of the driver.
>>
>> Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
>> ---
>>  drivers/hid/amd-sfh-hid/amd_sfh_hid.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_hid.c b/drivers/hid/amd-sfh-hid/amd_sfh_hid.c
>> index 705b52337068..81f3024b7b1b 100644
>> --- a/drivers/hid/amd-sfh-hid/amd_sfh_hid.c
>> +++ b/drivers/hid/amd-sfh-hid/amd_sfh_hid.c
>> @@ -171,11 +171,13 @@ int amdtp_hid_probe(u32 cur_hid_dev, struct amdtp_cl_data *cli_data)
>>  void amdtp_hid_remove(struct amdtp_cl_data *cli_data)
>>  {
>>  	int i;
>> +	struct amdtp_hid_data *hid_data;
>>  
>>  	for (i = 0; i < cli_data->num_hid_devices; ++i) {
>>  		if (cli_data->hid_sensor_hubs[i]) {
>> -			kfree(cli_data->hid_sensor_hubs[i]->driver_data);
>> +			hid_data = cli_data->hid_sensor_hubs[i]->driver_data;
>>  			hid_destroy_device(cli_data->hid_sensor_hubs[i]);
>> +			kfree(hid_data);
>>  			cli_data->hid_sensor_hubs[i] = NULL;
>>  		}

Looks good to me.

Acked-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>

Thanks,
--
Basavaraj

> This seems reasonable. Basavaraj, can you please provide your Ack for 
> this? Thanks,
>


  reply	other threads:[~2024-08-02 10:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-23  8:44 Olivier Sobrie
2024-08-02 10:48 ` Jiri Kosina
2024-08-02 10:55   ` Basavaraj Natikar [this message]
2024-08-02 10:58     ` Jiri Kosina

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=d1c3ab42-107d-4ce0-9d47-9870084c9514@amd.com \
    --to=bnatikar@amd.com \
    --cc=basavaraj.natikar@amd.com \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olivier@sobrie.be \
    /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®