From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 591D52E7381 for ; Thu, 18 Jun 2026 07:06:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781766402; cv=none; b=ER1Y4kyywXveL5WWJBJUiOrJVr4PYupjhhNitnk8st8L/r00t8YBYzM1Jovasdsysi7hUj6vCevcMnCyO0och+G8DMCBEPi2AXX4hOoEBqgObaV/J5LEYAsu7wnCUWKJy5anROY+jb9SEo0H69rnAojqZvIFUCxe5sn7ad0H6io= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781766402; c=relaxed/simple; bh=pOB0N7oC3zaT1BpMk1Zxc2ZumaX/k1RMNsTJW57uJKg=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=ZBBrUxSI1+QWWe7JeYUWCiQVV03HEEqVsfuoQQePO7X6/s0v3njpt4Gv5eTBer0tpQzDYvU1PC/ZlNQ84Sr4osDvgMr6we7T4uZeAbQ+7cLJGP1ISEmHxBZs+AtnAPspIqwzgMxss96jonwy48WVlmfOZGUjjVTeriyWCh41K5E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=agGtNkpY; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="agGtNkpY" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-c8894387780so281870a12.2 for ; Thu, 18 Jun 2026 00:06:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781766401; x=1782371201; darn=vger.kernel.org; h=mime-version:content-transfer-encoding:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4w489f812sOCalQuTrE1vmKCysqhU1b+dFQi+eqawKk=; b=agGtNkpYqxj+rIjWs4GVlEYzHxYcklwvNsJLaJSHnWms68bzZ6Uubegq/AHYpaKrQS 9MWfPH+RVMpOcCnOgF2kaqCiIXVl7o83g/BdThYip4kscFFbev4c0WIMBnvljC/bUlCI w31hi0q3jkyKtz5QyWelEoNIDR4jsFI5ERfzphnoxeUEymKMxifpvc1msqCd+hfwJOTD c8wt0Z9oMse2+BxGZ6b8nfUIHhYxEXPvrAA4iE7nZAowF3Hy/uY3HtL5W3hIYgmOiD3C 75fll+o2h3nLAz5RnhAoLei1unPXV7Xv48QltcsqI1BLVSaaRdUfGtLPGMJhLcAYvJ58 kUIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781766401; x=1782371201; h=mime-version:content-transfer-encoding:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4w489f812sOCalQuTrE1vmKCysqhU1b+dFQi+eqawKk=; b=Rq+Nq00ULMYEDQAaWJt1IfYPNSCPW0fJ+A5o51UpSBCyr8LLaoPsJG9isrTh7cRio6 Kc3bIskgxG22PzawR9EoAXBzbkVyD1g6H0GqFlEdS22vD+COyn7pEzdD07raRV5lRTm9 NWkhpQPQ77hRES9chDDhhmAn2wUZiVEdjW1zunvZicGTdS4YXkYnIbSFiILZmzEYo8aX aTabXwiVHlqeBL02fpkj3iM51FeswNvxs7vO7dW+LcGrX+08G/xogkHDLgR6InfTThl6 oVwjzgnzeHaUlTOxSvhzYTpwvT6Ix9nBXtojJUDWc24hDTlAygFcj//S+ionwbwP+BZq p/Sg== X-Forwarded-Encrypted: i=1; AFNElJ+EeZGmUf56++rM9ZaPge+qT2rTuy3lHDbJ/kTWivT2CQQMDPPBA04CHg+Q+CwGAymB3hgOJ1irgfBYi7E=@vger.kernel.org X-Gm-Message-State: AOJu0YxcOebiVlgzKdY793EV17sXgtWH9awQVqhskezzbdwZH+coJMdB +PI2j3X+FUnJLecHWDSqMM49rkht8VjerwL/h+S6TAT5CnUXmlHdzOxO X-Gm-Gg: Acq92OErmHfiLs5p5Qb9OPV5vvVu4dSOESGNZ5Ag2H8o3Oy/YACzDt648lqoojEICVP 8nweEDRpzx+QtFPg3wOHHofc3gWOoqm1LqRKrWpWSQuX9pwxec5fdDu1hPi8jbHc7H/71h3Vzm9 hI8bLD5NTx3nNSGbkZpnllxh3Z3QUwfVxCso9ALlHyw6S/i20543l8/w6AbSu5hnYdjYxdCQnyL 7w4U8KXrbNOQ2D3deqO56S9pyqVnWjXzoGMcB2CyHp/6x5ga4GBlpStuodehGiqTpLfKP4Uz3mQ F2Ug485LtbXOZVYflt+O8ISUdygiGm7XbsJ2sIhbkSMIhWQiEfN4FcsnKMynKrQKfR/43SXzr1D G/TH+3UYS6TEQ3E6N+V0pysE7nTE/6wvWGULT2CyicZqByUcz0XDQkh3fmJN+MQZKuM+/cXwKqq L8J2forjg2rLK3l9GE2T6xAzDImZjnobyoP7Ew6g== X-Received: by 2002:a05:6a20:d497:b0:39c:cdb:5d81 with SMTP id adf61e73a8af0-3b8b77ef2f8mr8266487637.32.1781766400332; Thu, 18 Jun 2026 00:06:40 -0700 (PDT) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c8664586b3csm16018741a12.14.2026.06.18.00.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2026 00:06:39 -0700 (PDT) From: Maoyi Xie To: Hans de Goede , Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: lg-g15: cancel pending work on remove to fix a use-after-free Date: Thu, 18 Jun 2026 15:06:35 +0800 Message-ID: <178176639579.3377656.12792307991044339915@maoyixie.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- drivers/hid/hid-lg-g15.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/hid/hid-lg-g15.c b/drivers/hid/hid-lg-g15.c index 1a88bc44ada4..02ef3e2094b4 100644 --- a/drivers/hid/hid-lg-g15.c +++ b/drivers/hid/hid-lg-g15.c @@ -1374,11 +1374,27 @@ static const struct hid_device_id lg_g15_devices[] = { }; 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); -- 2.34.1