From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 30FC242BE92; Thu, 16 Jul 2026 14:10:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784211021; cv=none; b=TFbYTwo7N7Sa3B502u1qX3Cnj4j969yRmdNOr5+Jr8NHkjGY3qaeWH1h3YHzh+GebbXQuqhreROOE7bjkHRdJTSLTxzamdMnhsN3GnGtbOxobB8secTm6sQGWuFL2bLO3S8A/3G2SQZyz2WRVBxPKDH1619/DQIZSdqFIIfM0A4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784211021; c=relaxed/simple; bh=I+tWFIk8GTr+7h4OAFtMIHJi4pifQ8s96wMYGOTf4vY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hRkZI5vHva/2okEJgT8eqGVLURUWLQqhqxqThVHbwTQkEqC7FUsHJ799icFGXv/RvzN3TFQkqFK6sOfNDIiRKV7di4CnAoq6fgV5LFP2isTqStwRMl0acOw5dHXqUWcrhsuo37rQ4dG3a6CYopFh6cnBniKXK35+2jO8He45+9Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=q6qQ3i+o; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="q6qQ3i+o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97FE01F000E9; Thu, 16 Jul 2026 14:10:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784211020; bh=/BHuglfUGtcceOytN0km8FDvokmetLdzt+C1pb7HWJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=q6qQ3i+oXzb6xOgwyd6k3POlhuYgE8kkv87JLIl3d/lxfwJ5lz4VtQUaLubOIrVTH +9BpGekfgB7pLHPguB7fkKG+tBpaYGM7Uoqp+GV6ODu3klF7Z8NqGgKVO8H/6UNSL2 fqkbC3/oT28sQLc8lF3Jso58KxZKNQ/yppQG/Q+w= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hans de Goede , Maoyi Xie , Hans de Goede , Jiri Kosina Subject: [PATCH 6.18 268/480] HID: lg-g15: cancel pending work on remove to fix a use-after-free Date: Thu, 16 Jul 2026 15:30:15 +0200 Message-ID: <20260716133050.617142669@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260716133044.672218725@linuxfoundation.org> References: <20260716133044.672218725@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Maoyi Xie commit 7705b4140d188ce22656f6e541ae7ef834c7e11a upstream. lg_g15_data is allocated with devm and holds a work item. The report handlers schedule that work straight from device input. lg_g15_event() and lg_g15_v2_event() do it on the backlight cycle key, and lg_g510_leds_event() does it too. The worker dereferences the lg_g15_data back through container_of. The driver had no remove callback and never cancelled the work. So if a report scheduled the work and the keyboard was then unplugged, devres freed lg_g15_data while the work was still pending or running, and the worker touched freed memory. This is a use-after-free. It is reachable as a race on device unplug. Add a remove callback that cancels the work before devres frees the state. g15->work is only initialized for the models that schedule it (G15, G15 v2, G510). The G13 and Z-10 leave it zeroed, so guard the cancel on g15->work.func to avoid cancelling a work that was never set up. The g15 NULL test mirrors the one already in lg_g15_raw_event(). Fixes: 97b741aba918 ("HID: lg-g15: Add keyboard and LCD backlight control") Cc: stable@vger.kernel.org Suggested-by: Hans de Goede Signed-off-by: Maoyi Xie Reviewed-by: Hans de Goede Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-lg-g15.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) --- a/drivers/hid/hid-lg-g15.c +++ b/drivers/hid/hid-lg-g15.c @@ -929,11 +929,27 @@ static const struct hid_device_id lg_g15 }; MODULE_DEVICE_TABLE(hid, lg_g15_devices); +static void lg_g15_remove(struct hid_device *hdev) +{ + struct lg_g15_data *g15 = hid_get_drvdata(hdev); + + /* + * g15->work is only initialized for the models that schedule it + * (G15, G15 v2, G510). The G13 and Z-10 leave it zeroed, so only + * cancel it when it was set up. + */ + if (g15 && g15->work.func) + cancel_work_sync(&g15->work); + + hid_hw_stop(hdev); +} + static struct hid_driver lg_g15_driver = { .name = "lg-g15", .id_table = lg_g15_devices, .raw_event = lg_g15_raw_event, .probe = lg_g15_probe, + .remove = lg_g15_remove, }; module_hid_driver(lg_g15_driver);