From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9539B233725; Mon, 10 Mar 2025 17:12:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741626726; cv=none; b=Q5ldCToPFTf3uRUWP8flpNurBzSbhAA4z8V+1rGjVYz96BHqaTkKS+FP+ucMYmN0dwaI6SjTb/FaES52QF5hrVsZm2LInfb8GxnoHJRm5mtirnpip40ZdvDbCk21RVv2PH+Xf/Kje9GN24BzHuKYh2t7cb1DyJm6xNZWNzJNKTo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741626726; c=relaxed/simple; bh=h+J+/j4lzh22j1c2yHL5Co4IhKLs9WZOsddMfeEITjc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E5BIGNU/iGl2CQmnHqju3czGY3evUPzF/6OaZJrxdgc8zgQtx4ETbtK5jqG8U3aw16d3l+AeF2ihtmf51X+dt9KwdnvplE+s42SFBF8udoX9AO7Lr9UbQ4/mCGJwwNMSgBYqn8xVxoaNrnyGvJKrPYzzRFfMX3Sh7csFj6HnFIc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Nsl5mdke; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Nsl5mdke" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 124ECC4CEEB; Mon, 10 Mar 2025 17:12:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741626726; bh=h+J+/j4lzh22j1c2yHL5Co4IhKLs9WZOsddMfeEITjc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nsl5mdkenfCCsK6xNWnY5BIx6Ry/vuVjsJw603SAs91f5S7pbkSknkoAmZLQW43S9 Hb60FcbT8aBZqm+jwXdcs3apljQHy/pj07YLctJF8FMQW5SixKgs4vnO42cap/DegO daf8ncEWR3dLnoXoR945hHC/NG2MPU1k95Lvm6Xg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhang Lixu , Srinivas Pandruvada , Jiri Kosina , Sasha Levin Subject: [PATCH 6.13 091/207] HID: intel-ish-hid: Fix use-after-free issue in ishtp_hid_remove() Date: Mon, 10 Mar 2025 18:04:44 +0100 Message-ID: <20250310170451.379438162@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250310170447.729440535@linuxfoundation.org> References: <20250310170447.729440535@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.13-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhang Lixu [ Upstream commit 07583a0010696a17fb0942e0b499a62785c5fc9f ] The system can experience a random crash a few minutes after the driver is removed. This issue occurs due to improper handling of memory freeing in the ishtp_hid_remove() function. The function currently frees the `driver_data` directly within the loop that destroys the HID devices, which can lead to accessing freed memory. Specifically, `hid_destroy_device()` uses `driver_data` when it calls `hid_ishtp_set_feature()` to power off the sensor, so freeing `driver_data` beforehand can result in accessing invalid memory. This patch resolves the issue by storing the `driver_data` in a temporary variable before calling `hid_destroy_device()`, and then freeing the `driver_data` after the device is destroyed. Fixes: 0b28cb4bcb17 ("HID: intel-ish-hid: ISH HID client driver") Signed-off-by: Zhang Lixu Acked-by: Srinivas Pandruvada Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/intel-ish-hid/ishtp-hid.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/hid/intel-ish-hid/ishtp-hid.c b/drivers/hid/intel-ish-hid/ishtp-hid.c index 00c6f0ebf3563..be2c62fc8251d 100644 --- a/drivers/hid/intel-ish-hid/ishtp-hid.c +++ b/drivers/hid/intel-ish-hid/ishtp-hid.c @@ -261,12 +261,14 @@ int ishtp_hid_probe(unsigned int cur_hid_dev, */ void ishtp_hid_remove(struct ishtp_cl_data *client_data) { + void *data; int i; for (i = 0; i < client_data->num_hid_devices; ++i) { if (client_data->hid_sensor_hubs[i]) { - kfree(client_data->hid_sensor_hubs[i]->driver_data); + data = client_data->hid_sensor_hubs[i]->driver_data; hid_destroy_device(client_data->hid_sensor_hubs[i]); + kfree(data); client_data->hid_sensor_hubs[i] = NULL; } } -- 2.39.5