From nobody Fri Jul 24 04:50:33 2026 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 3431A18C2C for ; Fri, 24 Jul 2026 00:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784851816; cv=none; b=TiKB2QM07hpvmJjJ3x+b8SmWryQytAwGdzIIiquI15XKR3Ub7gKH2gF/mW4wMf1Rao8CnBSXWlTJgBVEP9NkSVVopCGmWQTdz4YXmVa9SlT5N+Qp4uZFBd+CYmKwHbA1YAEmDAsfHlTipdNc8xwpeHpGiy2fXN4jQE7FqfS1KeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784851816; c=relaxed/simple; bh=vh/JKGt51BiPqho1O21KWsVulMR0eJ/JWLjQkb/m7SM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=tAVRGUb89cCNqep9zKIvZQkp8sI9uTe836ZK65efwiQCczwSSNhH36hfmhSCLvOL7uPrWdqDZOmkmYEgoAoLBeVxeAtquTyu63GCuxFmnaS8GeV1+iB3Wl+wlOTaen2/JPaccRkzVyGJDadHyvuvLXlSLy8zZLIY8tlmREkGgyw= 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=a9URDAgn; arc=none smtp.client-ip=209.85.221.42 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="a9URDAgn" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-47f6609c657so605941f8f.2 for ; Thu, 23 Jul 2026 17:10:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784851813; x=1785456613; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=nU+jXdKU/lc4CNz9IWGgShjsy/wZZQkGpDW5ftzUhAM=; b=a9URDAgngnRpEDGJdqif6nD1hzcEkF41T02GtG6/TOexUsW3g/Alh7Y3z7RDBiufsd DqTjudzd4GmrHlRi2ueKFqlyplbPzv6uIjYkv/qrBx/PIF2Pn6yDHf/8e3zIFmHSI0oZ VKv4tCjEn5IzJBR4dJlaz+6V8o/O8lZVo/koQm0/D00tnihNcnc/RlfDbxDTRRkXUfQc dYnYBwHKZiuhDG4gM5GkV3zkg5Dd2bbsdHPi2ma9CAN63+aK0YD/H4mlxsM+Y/kWPNwV nRTcJ/DQZh3dXEWPr104h7/slypwlUzNT5pb+WPDmD2EY1Awq4xNlB8HtCvFklORLF8F q6XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784851813; x=1785456613; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nU+jXdKU/lc4CNz9IWGgShjsy/wZZQkGpDW5ftzUhAM=; b=of71HmaO6rL7SPL1ADGCgZ7sUBGgYZpzLwI5TjqcX6Xe9w3ZGT/IPp37gVnY2TzO/R 4S602Uek6N77fcz4obxOCULCObfOHoKetIgIVfHLcbnGJ/Es2s7aqutpenIiIvpLAfiu G/eJw3in5eDgJepHnAlzuz6S5uidfnN6ddkKxQAeKw6cd4gsr+GIvnvJnCTag5JQ8yBv xQcHm3H3Pz5cXfi0WvmKcGQ8lKxVUSlh8+h1tMkPAC9OqnN27kJMog2LNrpaUUIqpfJq AhyiTvJG2/jSswUoKztLnfooPbFDyEnMRou5c/RolEJRHSVCoQFqTQB4yYwk71DU1Z8b hx/w== X-Forwarded-Encrypted: i=1; AHgh+RpUZF0DWgypayGrt4napqQWkS+KltVmy4vkokMdR4X/CG9GDyILlN6QfsChgiihyiVIQmsRi696JvwFcuE=@vger.kernel.org X-Gm-Message-State: AOJu0YyzGjHH1KNYVjnJRZLenIgsEnB/1HwbIed9NUI8m5aNgG5PRE2k xMvsHF/sZecmjujiha/j6vuEiDanS2LvhBgV6QIZw5iRQMErOIkrXesz X-Gm-Gg: AR+sD13E93ldxsyVltuMB53YFPL8UeE7EgWtvkRwUF+VFFNdqUgj6qkxM/0J5oBUCE1 UOOLQNWvJlpXOZhlzjTGSwfyD0BtBdznYsrdJKr7/HzhiEIi2wBQEkdiyu/3alUhRFKeIDm3i/i g1AttbTPp0a1rI3j59KbBbkodynBEU+OLho5ERmMhO3yv+S3C+He8cK0UCrYCKYirxbG9sc3OR6 hAPovhpasGYjG/+2AZA4J/B+aI9Rdh21TPUo40oEWpL0I2vHZ2em+tnI8/TnBSimWD7mp7TKF1o eqy4ihZc5DdOFo+d0so5jLO8THNlXF3OG4peuZKi4eGMAXJ6Tfwpx+E0D56/FpBN5sXvJbH1rja C9oVHdrBAvS2jeXagRzIkMz9iYfv5YfVyq3stiqwoqk3mdalNFaLiH/lcUXd2Afca2Myz7vjeBA == X-Received: by 2002:a05:6000:310e:b0:47f:8b94:19d5 with SMTP id ffacd0b85a97d-47f8dcc4039mr6598984f8f.57.1784851813343; Thu, 23 Jul 2026 17:10:13 -0700 (PDT) Received: from beelink.. ([186.247.163.143]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f85b9a5a2sm21104488f8f.7.2026.07.23.17.10.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 17:10:12 -0700 (PDT) From: Aldo Ariel Panzardo To: linux-input@vger.kernel.org Cc: jikos@kernel.org, bentiss@kernel.org, linux-kernel@vger.kernel.org, Aldo Ariel Panzardo , stable@vger.kernel.org, Sashiko AI review Subject: [PATCH] HID: multitouch: stop the release timer from being rearmed on remove Date: Thu, 23 Jul 2026 21:09:58 -0300 Message-ID: <20260724000958.938675-1-qwe.aldo@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mt_remove() quiesces the sticky-finger timer before stopping the hardware: timer_delete_sync(&td->release_timer); sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group); hid_hw_stop(hdev); timer_delete_sync() waits for a running callback and dequeues the timer, but it does not stop the timer from being armed again. The transport is still delivering reports at that point, and the report path rearms it: if (app->quirks & MT_QUIRK_STICKY_FINGERS) { if (td->mt_io_flags & MT_IO_SLOTS_MASK) mod_timer(&td->release_timer, jiffies + msecs_to_jiffies(100)); A report that arrives after timer_delete_sync() has returned therefore leaves the timer queued. td is allocated with devm_kzalloc() against hdev->dev, so it is freed when the driver is unbound, after mt_remove() returns. When the timer fires afterwards, mt_expired_timeout() dereferences the freed td: struct mt_device *td =3D timer_container_of(td, t, release_timer); struct hid_device *hdev =3D td->hdev; if (test_and_set_bit_lock(MT_IO_FLAGS_RUNNING, &td->mt_io_flags)) Simply moving the teardown after hid_hw_stop() does not fix this on its own, because mt_expired_timeout() calls mt_release_contacts(), which walks hdev->inputs; the timer still has to be quiesced before hid_hw_stop() tears the input devices down. Use timer_shutdown_sync() instead, which additionally makes any later mod_timer() a no-op, so neither ordering constraint has to be traded off against the other. This is the final-teardown pattern the function was introduced for, and hid-wiimote already uses it for the same reason. Fixes: 4f4001bc76fd ("HID: multitouch: fix rare Win 8 cases when the touch = up event gets missing") Cc: stable@vger.kernel.org Reported-by: Sashiko AI review Closes: https://sashiko.dev/#/patchset/20260723224211.613112-1-you@example.= com?part=3D1 Signed-off-by: Aldo Ariel Panzardo --- Found by code inspection after Sashiko AI review flagged the teardown ordering while reviewing an unrelated patch of mine. I have not reproduced the use-after-free at runtime: it needs a report to land in the window between timer_delete_sync() returning and the device being unbound, which I have no way to drive reliably on the hardware I have. The window and the rearm path are visible in the code, and the fix does not depend on the race being hit. drivers/hid/hid-multitouch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 0495152091e3..f25065b9ec66 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -2233,7 +2233,7 @@ static void mt_remove(struct hid_device *hdev) { struct mt_device *td =3D hid_get_drvdata(hdev); =20 - timer_delete_sync(&td->release_timer); + timer_shutdown_sync(&td->release_timer); =20 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group); hid_hw_stop(hdev); --=20 2.43.0