* [PATCH] platform/x86: hdaps: Hold hdaps_mtx when changing the axis inversion
@ 2026-12-04 18:48 Praneeth Balasubramanian
0 siblings, 0 replies; only message in thread
From: Praneeth Balasubramanian @ 2026-12-04 18:48 UTC (permalink / raw)
To: Hans de Goede, Ilpo Järvinen
Cc: Frank Seidel, platform-driver-x86, linux-kernel,
Praneeth Balasubramanian, stable
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-04 18:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:48 [PATCH] platform/x86: hdaps: Hold hdaps_mtx when changing the axis inversion Praneeth Balasubramanian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox