From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 5D6063A4505 for ; Sat, 11 Jul 2026 11:50:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783770608; cv=none; b=reH67RNSLuRlDD8q2XXv0cUnuJaZpKfeAsX4ULG4Gj3Igg1LCaPEnG+mumG0/O2tI27pvwjtlqZMzwjxMjfrvFNwqaftDq9KLLGyjIXOmlRCv4KUL2dbkuAr6Lqv8k5djWj5w/Ix+sao1y/Azi1daoYXpkJoPNEUzzcxhT0qwR8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783770608; c=relaxed/simple; bh=16ZCF42qfyfecp4FE6xDMCEwifOTFXd6LvfmvaYgqJU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S1CzInoyrfjYsk76G6ckur9ieW7yFbFnox0aZCecfpOJBh4h6n6D4Zh1GCJYkXr8lBLbFfFO+dgFL8LFNzqCauFGA2Za7oDmcBCIhTCBns9RnLqbxzeCb5SocUdGP3tQ9AzJkt0FbMokvciM+E4xGnvN3FqXHRmQ6F9BsYZoC7Y= 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.50 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-f50.google.com with SMTP id 98e67ed59e1d1-384c94c9414so1732506a91.3 for ; Sat, 11 Jul 2026 04:50:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783770604; x=1784375404; h=content-transfer-encoding:mime-version:references:in-reply-to :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=Hk5V5J+DbPG/Ee/w/hWVnY1n/ftwZsWJmMFAPAEy6a0=; b=diYUPl8isRQAOD9v0emw62bxB09JM5u3KyZCQTAn3tKqcjiJgdHdeOVcs+3h8Vihmb RT+Cl6kA5YT8bEi443OciplJcwjkspo4u5vlwW5NEDSiWUd4SiaeQH6ddc7q7OK/V8ba 8f6FOqSIKBiktzQuJpALmt2ra18eZ2vpMbuZ+0TorB09qF4Q6WyR2/TJzmBwuoGiD98l VOcZ7gH5WLfUck+Rm+r4HzbkS7dsnrqWSAPuphUjxYey+nolBxee4J+yLaHkABCUWjLA C2S2BK9KOhDRsfAvbzQE6XK85f6D7Ohs6VgVWsQVRCFaAi8EDL816+A7MDNzx2LCZlEN uvJQ== X-Forwarded-Encrypted: i=1; AHgh+Rr9ma7Zkn6XosVAmxWXnVWvnIVNWmYNzhfIbuUeWhjqw9szUiirLo/CdJCXCedZ3fETbF8rWDE03Ehsrdw=@vger.kernel.org X-Gm-Message-State: AOJu0YxtMfMutwp/ixg1hTmUNACNZMTKveRxsxwnnvY9aFqQ2fDe3G/n Tm3BeU+QIDicXXgTtDFx7bNWFGYhzqvl7Fc0pGBvTEcOi0pgI1eWiQY= X-Gm-Gg: AfdE7cldrpjQwqwjtCDZbJmNwdmbf8Q/hpK/l+pRiUklurClUjQifAObpgZRkXXjuJP SXAAtT2xLDLTh88W4ryIZjKuRwuwqUF8Jxen27lpknj6i8jM2rK15xCBuugbl3GzLrVnlspZ9wC Y/owh28HPZLz8st/Je0TMwTzI5ITocdmkoGEVIgnTqzgGmu3jvDU8cZrPkdzhNahmV3CK0L4FEe DXjpBzS099eled6miAkpvu0rNNRlziDmMUwxQav4d3zljXjfU+XkwH2tvA6hmVFFTLrxFiCYz1Y ravAfVXwa/CKhRVwbp/4DIieJm5fCfjnE/y92b3KLBnd390PtTdCkoQmXulV7AkEC4gjw2lmZ5b sfmdYhfoRsxl/XJ/p7wsgjTb6UynjkZyvIyzZTeBYKDqAbohx41ux0yTxtyjfeUvwrspzbYKkLQ +NuAShBzAvoeCb2+KyOSj8crNTYLAOezSE/yoKCtTvO68557NDjONmQyIiY+4vYPrWPRXeOxq8L XBrdljOTqucasPLxGSXmMTA6Q== X-Received: by 2002:a17:90b:58f0:b0:387:e0db:bc23 with SMTP id 98e67ed59e1d1-38dc77b82bemr2604555a91.35.1783770603661; Sat, 11 Jul 2026 04:50:03 -0700 (PDT) Received: from penguin.tail0a1999.ts.net (61-228-52-13.dynamic-ip.hinet.net. [61.228.52.13]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38a5506b48bsm3957570a91.1.2026.07.11.04.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jul 2026 04:50:03 -0700 (PDT) From: Shih-Yuan Lee To: Dmitry Torokhov , Mark Brown Cc: Daniel Mack , Haojian Zhuang , Robert Jarzmik , Shih-Yuan Lee , linux-input@vger.kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 2/3] Input: applespi - fix NULL pointer dereference in tp_dim open Date: Sat, 11 Jul 2026 19:49:36 +0800 Message-Id: <20260711114937.16670-3-fourdollars@debian.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260711114937.16670-1-fourdollars@debian.org> References: <20260711055247.5412-1-fourdollars@debian.org> <20260711114937.16670-1-fourdollars@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The tp_dim debugfs file is registered synchronously during driver probe in applespi_probe(). However, the applespi->touchpad_input_dev is initialized and registered asynchronously in the driver's worker thread. If a userspace process opens the debugfs file before the worker thread has completed initialization, applespi_tp_dim_open() will dereference the NULL applespi->touchpad_input_dev pointer, causing a kernel panic. Fix this by using smp_load_acquire() to safely load touchpad_input_dev and return -ENODEV if it is not yet initialized. Signed-off-by: Shih-Yuan Lee --- drivers/input/keyboard/applespi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c index 3bdb9e7cfb8b..4d339445e9c7 100644 --- a/drivers/input/keyboard/applespi.c +++ b/drivers/input/keyboard/applespi.c @@ -963,12 +963,18 @@ static void applespi_debug_update_dimensions(struct applespi_data *applespi, static int applespi_tp_dim_open(struct inode *inode, struct file *file) { struct applespi_data *applespi = inode->i_private; + struct input_dev *touchpad; file->private_data = applespi; + /* Pairs with smp_store_release in applespi_register_touchpad_device() */ + touchpad = smp_load_acquire(&applespi->touchpad_input_dev); + if (!touchpad) + return -ENODEV; + snprintf(applespi->tp_dim_val, sizeof(applespi->tp_dim_val), "0x%.4x %dx%d+%u+%u\n", - applespi->touchpad_input_dev->id.product, + touchpad->id.product, applespi->tp_dim_min_x, applespi->tp_dim_min_y, applespi->tp_dim_max_x - applespi->tp_dim_min_x, applespi->tp_dim_max_y - applespi->tp_dim_min_y); -- 2.39.5