From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: "Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Frank Seidel <frank@f-seidel.de>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org,
Praneeth Balasubramanian <praneethb2002@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] platform/x86: hdaps: Hold hdaps_mtx when changing the axis inversion
Date: Fri, 4 Dec 2026 10:48:25 -0800 [thread overview]
Message-ID: <20261204184825.1686301-1-praneethb2002@gmail.com> (raw)
hdaps_invert_store() sets hdaps_invert and calls hdaps_calibrate()
without hdaps_mtx. The comment above hdaps_calibrate() says that callers
must hold the mutex, and hdaps_calibrate_store() and
hdaps_mousedev_poll() do. hdaps_calibrate() reads the axes with
__hdaps_read_pair(), which runs a refresh/read/complete sequence on the
embedded controller's I/O ports and then applies hdaps_invert.
A write to the invert attribute can therefore interleave its port
accesses with those of the input poller. The poller can also use
rest_x/rest_y while they are being recalibrated, or together with an
hdaps_invert value they were not measured with. Both lead to wrong
position reports.
Take hdaps_mtx around the update, as hdaps_calibrate_store() does.
The missing lock was found by a static check that turns the locking rule
in a function's comment into a Clang context-analysis requirement on its
callers.
Fixes: 860e1d6b46bd ("[PATCH] updated hdaps driver.")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
This was found by a compiler-based check, part of research at UCSB SecLab.
The locking rule stated in the kernel-doc comment of the called function
was turned into a Clang context-analysis requirement (__must_hold) on that
function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every
caller. An LLM was used only to turn the comment into a machine-readable
rule; the report itself comes from the compiler. The patch and changelog
were drafted with Claude Opus 5.5. I reviewed the patch and take
responsibility for it.
Testing: builds without new warnings with W=1 (x86_64, clang 23,
allmodconfig). Not runtime-tested; I do not have this hardware, and I
have not observed the race myself.
drivers/platform/x86/hdaps.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/platform/x86/hdaps.c b/drivers/platform/x86/hdaps.c
index f11f726d2062..993d9889fbf9 100644
--- a/drivers/platform/x86/hdaps.c
+++ b/drivers/platform/x86/hdaps.c
@@ -435,8 +435,10 @@ static ssize_t hdaps_invert_store(struct device *dev,
invert < 0 || invert > HDAPS_BOTH_AXES)
return -EINVAL;
+ mutex_lock(&hdaps_mtx);
hdaps_invert = invert;
hdaps_calibrate();
+ mutex_unlock(&hdaps_mtx);
return count;
}
--
2.25.1
reply other threads:[~2026-12-04 18:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204184825.1686301-1-praneethb2002@gmail.com \
--to=praneethb2002@gmail.com \
--cc=frank@f-seidel.de \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox