From: Jonathan Cameron <jic23@kernel.org>
To: Maxwell Doose <m32285159@gmail.com>
Cc: sashiko <sashiko-bot@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Daniel Baluta" <daniel.baluta@intel.com>,
linux-iio@vger.kernel.org (open list:IIO SUBSYSTEM AND DRIVERS),
linux-kernel@vger.kernel.org (open list)
Subject: Re: [PATCH v2] iio: imu: kmx61: Fix potential time-of-check to time-of-use race
Date: Sat, 16 May 2026 13:54:58 +0100 [thread overview]
Message-ID: <20260516135458.7a4c3b8f@jic23-huawei> (raw)
In-Reply-To: <20260513013638.147606-1-m32285159@gmail.com>
On Tue, 12 May 2026 20:36:38 -0500
Maxwell Doose <m32285159@gmail.com> wrote:
> A time-of-check to time-of-use race condition exists in
> kmx61_write_event_config(). If two threads enter the function at the
> same time, both threads may pass the check and get to the lock. Thus,
> when the first thread releases the lock allowing the second thread to
> start execution after the first thread modifies data->ev_enable_state to
> force returning from the function, the second thread continues execution
> regardless. Fix this by moving the data->ev_enable_state check inside of
> the critical section.
>
> Fixes: fd3ae7a9f21c ("iio: imu: kmx61: Add support for any motion trigger")
> Reported-by: sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/patchset/20260507223337.48437-1-m32285159%40gmail.com
> Signed-off-by: Maxwell Doose <m32285159@gmail.com>
Sashiko has more to say.. Please take a look. I'm rather nervous
about trying to fix the bugs it's finding around reference counting
without anyone testing.
Maybe we can get enough confidence with emulation or stubbing.
https://sashiko.dev/#/patchset/20260513013638.147606-1-m32285159%40gmail.com
> ---
> drivers/iio/imu/kmx61.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c
> index 3cd91d8a89ee..3afa369de3cf 100644
> --- a/drivers/iio/imu/kmx61.c
> +++ b/drivers/iio/imu/kmx61.c
> @@ -942,11 +942,11 @@ static int kmx61_write_event_config(struct iio_dev *indio_dev,
> struct kmx61_data *data = kmx61_get_data(indio_dev);
> int ret = 0;
>
> - if (state && data->ev_enable_state)
> - return 0;
> -
> mutex_lock(&data->lock);
>
> + if (state && data->ev_enable_state)
> + goto err_unlock;
> +
> if (!state && data->motion_trig_on) {
> data->ev_enable_state = false;
> goto err_unlock;
next prev parent reply other threads:[~2026-05-16 12:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 1:36 Maxwell Doose
2026-05-13 1:39 ` Maxwell Doose
2026-05-13 7:35 ` Joshua Crofts
2026-05-13 11:25 ` Andy Shevchenko
2026-05-13 15:00 ` Maxwell Doose
2026-05-16 12:54 ` Jonathan Cameron [this message]
2026-05-17 16:55 ` Maxwell Doose
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=20260516135458.7a4c3b8f@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=daniel.baluta@intel.com \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m32285159@gmail.com \
--cc=nuno.sa@analog.com \
--cc=sashiko-bot@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
all inboxes | Powered by JetHome®