From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 E3AF143D502 for ; Mon, 20 Jul 2026 16:22:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784564553; cv=none; b=UZ7lbbH44X6Lyo4kWH2dkXA5Lzeyw4rHv0M8Z6/bgM8CNw4s+/O0/iv7ZcBkXdXUnUyIlyBTFx+cxXnesGB7XhFLJzlIPSs4Kr0shtLj5bD/BMN9pmBIFinYfi0Z+LcrN3p3Qqkb0n2zqX+seXyTl8D7oN58fsqZNtZaZociA/M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784564553; c=relaxed/simple; bh=dUMQFB2Z8XBwxm+Ex5oVkHqrvsU+GntbvkgsqLzWw58=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=siAsWcSwqPeF7ZbimxK+ZN+sgYm6bsKbaLPlXzWQ8bN9Iw/AQWSUsB0YPrDaaQkjz933Yhj9k2LwTufGFAaDovL1f+xVi6WyFT4/zj5rgSZ7akVeNLMEMojRD6Hb7KBEcSTKMYtdm1G2M+uMNDvdjE20MrZ9zSkuEXS5IP2dGaM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-381b831d535so8128344a91.0 for ; Mon, 20 Jul 2026 09:22:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784564544; x=1785169344; 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=kPuVUYzIwyEbuq5A3FBqqRsMv8Klcyr/+mTheieV1ls=; b=bGSPpxtgEVKlpVuYFrb7USEmfdCj2OljkrAFNyABnOafLSZfC9bckl5sd1L88gD/Gt tUlXt8urrG5jqa+sYfLuKLFaAZ2DBmPKCOdou1STWWLmMK9ft06YXb+5WwlXysyv2bnV etGgY82Xa897C6ubIo8qjw4AHYHcLE4JFPEXjqmspccAvRHGgeyWo6epT1VhZKKvoUqz R3/peXDFwo8OEpnxK9f6nvICLuCJ401mk5XNAXvttmbh/mCfn80P+i3L6VXw1xjLjELL ZiDyl94GbDuJ/Wni88ceQZODTrTNiCmv+gqfxBTSg1NsxvuX1aXVO4SgdNSigxb/0goH 1Ffg== X-Forwarded-Encrypted: i=1; AHgh+RpL6wpFnb4THAfDm8EAD1Co84KlWyxeq9VDwNayL+AH4+FHW9Mdvj0lDeivJjr8kCIq8aAUYyrDXkzKVQA=@vger.kernel.org X-Gm-Message-State: AOJu0YxB+gqz5KU346apbKcQAldUZSE+kXBqGZ3VBEaXvoLDXiMC9OQu ufMMvawAjvbWa2wGF61RHgkki3AQXy7hXtBURBsV7gLs6im+jxtL6NI= X-Gm-Gg: AR+sD11aMXAAMyYlvvFf8iIYgNU6hfgTwyGSsrJEIRtcGCo+/079kATKZFyfbXodUkc I5YNcnAi0of+XePCDja4JqH1eeBP3Ks+9FFtmjdxCRMxLANLJ5V3gxk4421KPDgI2109eDTz9bX mXDwPBpfgmqc7obiA6LbF6fQnW9XTwz3BlENq5Nmo1RUDacDPmLUrGDvGnZt4nq413bhbdzaKcV HL0J63VoXsM+Xhgxr/KwaUB3NqqXxUkMI5J4zx0UTQmFQNunKKu/olWCJOeOk35Chk04JrVYUP8 +qucxlNWlRwknwimpiM8Ma/ytZPRiQWBYvhfRXfxLu6Kno+Yfx1U79zFO1l04zls7ez0Ogds/C/ 49RxpdeXbDlXFtGPgUS4MFqOIywNmUshpD4olchh+IXoc4zHMNnLryhHx5ZhURExp9EkJlPIzgD ADCk4jbYrxsvW5aOGF626Bcaxq3DXEvpjkmGO3jz8wdo/cbiqAhxYEOWOwWA3mcObS48sYiRuL5 67In2TJCUbxNtIeMg== X-Received: by 2002:a17:90b:3d4f:b0:381:bc4c:da74 with SMTP id 98e67ed59e1d1-38e4b594ea6mr15397998a91.32.1784564544181; Mon, 20 Jul 2026 09:22:24 -0700 (PDT) Received: from penguin.tail0a1999.ts.net (61-228-16-100.dynamic-ip.hinet.net. [61.228.16.100]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38e9205d358sm29366a91.3.2026.07.20.09.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 09:22:23 -0700 (PDT) From: Shih-Yuan Lee To: Dmitry Torokhov Cc: Mark Brown , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Shih-Yuan Lee Subject: [PATCH v3 0/5] Input: applespi - Fix probe timeout and use-after-free bugs Date: Tue, 21 Jul 2026 00:22:14 +0800 Message-Id: <20260720162219.32324-1-fourdollars@debian.org> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This 5-patch series refactors the applespi driver for Apple SPI keyboards and touchpads, eliminating use-after-free (UAF) race conditions during driver unbind, kernel panics in debugfs, level-triggered ACPI GPE interrupt storms, and data races. Specifically, this series: - Replaces separate drain helpers with a unified wait queue and 3-second timeout barrier, falling back to unconditional completion waiting if transfers remain active to prevent premature driver unbind and DMA memory corruption. - Tracks in-flight asynchronous SPI transfers using a completion tracking array and cancel_spi flag, ensuring inner completion callbacks execute prior to waking wait queue waiters to guarantee teardown safety. - Converts touchpad detection and registration from an asynchronous workqueue worker to a synchronous probe sequence, while protecting against NULL pointer dereferences in debugfs during keyboard-only fallback mode. - Corrects driver unbind sequence by disabling ACPI GPE handlers before marking the driver as shutting down, avoiding level-triggered interrupt storms on unhandled reads. Changes in v3: - Addressed feedback from Sashiko review on the v2 patchset: - Fixed Use-After-Free in applespi_drain_writes() and applespi_drain_reads() on timeout by falling back to unconditional wait (wait_event_lock_irq()) if transfers are still active upon 3-second timeout expiry. - Activated cancel_spi tracking flag by setting cancel_spi = true in drain functions under cmd_msg_lock to reject new async requests (-ESHUTDOWN) and trigger wait queue wakeups. - Fixed completion callback race in applespi_async_complete() by invoking inner complete(applespi) callback BEFORE clearing tracking slot and waking waiters on wait_queue. - Fixed NULL pointer dereference in applespi_tp_dim_open() when touchpad registration fails or times out, returning -ENODEV if touchpad_input_dev is NULL. - Protected rcvd_tp_info from data races in probe by making a safe local copy under cmd_msg_lock before passing to applespi_register_touchpad_device(). - Fixed GPE Interrupt Storm during unbind in applespi_remove() by disabling and removing GPE handler BEFORE setting cancel_spi = true and waiting for transfers to drain. Changes since v1: - Split the large touchpad registration patch into 4 distinct, single-purpose commits (wait queue consolidation & timeouts, async queue slots tracking, synchronous registration, and async probe preference) for better readability. - Fixed a self-deadlock in applespi_async() where it attempted to acquire cmd_msg_lock while already held by applespi_notify() and other callers. - Updated applespi_async() to assert the lock is held by the caller. - Protected touchpad info flags under cmd_msg_lock in response handling. - Simplified applespi_tp_dim_open() by removing redundant NULL checks. - Overhauled GPE disabling and teardown order in applespi_remove() to prevent GPE interrupt storms and unbind deadlocks. - Addressed reviewer feedback from Sashiko. Shih-Yuan Lee (5): Input: applespi - use unified wait queue with timeouts for drain Input: applespi - track asynchronous SPI transfers in flight Input: applespi - register touchpad synchronously in probe Input: applespi - prefer asynchronous driver probing Input: applespi - fix use-after-free in applespi_remove() drivers/input/keyboard/applespi.c | 208 +++++++++++++++++++++++++----- 1 file changed, 175 insertions(+), 33 deletions(-) -- 2.39.5