mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yeoreum Yun <yeoreum.yun@arm.com>
To: sashiko-reviews@lists.linux.dev
Cc: Yeoreum Yun <yeoreum.yun@arm.com>,
	linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND v13 01/14] coresight: etm4x: read-back TRCSEQSTR at disabling and prohibit modifying seq_state while enabling.
Date: Sat, 3 Oct 2026 04:44:38 +0100	[thread overview]
Message-ID: <asB6JgDE6S6JQr4r@e129823.arm.com> (raw)
In-Reply-To: <20261003030811.B35331F000FF@smtp.kernel.org>

On Sat, Oct 03, 2026 at 03:08:11AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] coresight: TOCTOU race in seq_state_store bypasses active-session guard
> --
> 
> commit 750a64ecfab03057a253043e06b3def402bb7137
> Author: Yeoreum Yun <yeoreum.yun@arm.com>
> 
> coresight: etm4x: read-back TRCSEQSTR at disabling and prohibit modifying seq_state while enabling.
> 
> TRCSEQSTR can be changed by the ETM while a session is active. Its value
> therefore needs to be preserved when a sysfs session is disabled so that
> users can read the current sequence state after the session ends.
> 
> > diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c
> > --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c
> > @@ -1435,6 +1435,8 @@ static ssize_t seq_state_store(struct device *dev,
> >  
> >  	if (kstrtoul(buf, 16, &val))
> >  		return -EINVAL;
> > +	if (IS_ERR_OR_NULL(drvdata->csdev) || coresight_get_mode(drvdata->csdev))
> > +		return -EBUSY;
> >  	if (val >= drvdata->nrseqstate)
> >  		return -EINVAL;
> >  
> >  	config->seq_state = val;
>         ^^^^^^^^^^^^^^^^^^^^^^^^
> 
> [Severity: Medium]
> Could this active-session guard be bypassed due to a Time-of-Check to
> Time-of-Use race?
> 
> If a user-space write to seq_state and an enable_source call occur
> concurrently, is it possible for enable_source to succeed immediately
> after this mode check passes?
> 
> If coresight_take_mode() succeeds in the racing enable_source call, it
> would take drvdata->spinlock to copy the configuration for the active
> session. This seq_state_store() write would then proceed without a lock,
> modifying the configuration after it was already checked.
> 
> When the sysfs session is later disabled, wouldn't the old state read
> from hardware overwrite the user's new value?
> 
> Should raw_spin_lock(&drvdata->spinlock) be taken around this mode check
> and the configuration assignment?

No. seq_state_store() does not update any user configuration.
It only clears the STATUS and PENDING bits.

The other bits in TRCSSCSRn are RO or RES fields, so there is no
user-programmed state here that can be lost or overwritten by a
later hardware readback.

Therefore, the race described above does not result in a lost
configuration update.

-- 
Sincerely,
Yeoreum Yun

  reply	other threads:[~2026-10-03  3:44 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-03  2:52 [PATCH RESEND v13 00/14] fix several inconsistencies with sysfs configuration in etmX Yeoreum Yun
2026-10-03  2:52 ` [PATCH RESEND v13 01/14] coresight: etm4x: read-back TRCSEQSTR at disabling and prohibit modifying seq_state while enabling Yeoreum Yun
2026-10-03  3:08   ` sashiko-bot
2026-10-03  3:44     ` Yeoreum Yun [this message]
2026-10-03  6:07   ` Suzuki K Poulose
2026-10-03  2:52 ` [PATCH RESEND v13 02/14] coresight: etm4x: prohibit modifying cntr_val while session is enabled Yeoreum Yun
2026-10-03  3:06   ` sashiko-bot
2026-10-03  4:29     ` Yeoreum Yun
2026-10-03  2:52 ` [PATCH RESEND v13 03/14] coresight: etm3x: prohibit modifying cntr_val and reset " Yeoreum Yun
2026-10-03  3:06   ` sashiko-bot
2026-10-03  4:34     ` Yeoreum Yun
2026-10-03  6:10   ` Suzuki K Poulose
2026-10-03  2:52 ` [PATCH RESEND v13 04/14] coresight: etm4x: fix inconsistencies with sysfs configuration Yeoreum Yun
2026-10-03  3:06   ` sashiko-bot
2026-10-03  4:40     ` Yeoreum Yun
2026-10-03  2:52 ` [PATCH RESEND v13 05/14] coresight: etm3x: " Yeoreum Yun
2026-10-03  2:52 ` [PATCH RESEND v13 06/14] coresight: etm3x: remove redundant cpu online check on etm_enable_sysfs() Yeoreum Yun
2026-10-03  2:52 ` [PATCH RESEND v13 07/14] coresight: etm4x: introduce struct etm4_caps Yeoreum Yun
2026-10-03  2:52 ` [PATCH RESEND v13 08/14] coresight: etm4x: exclude ss_status from drvdata->config Yeoreum Yun
2026-10-03  2:52 ` [PATCH RESEND v13 09/14] coresight: etm4x: remove s_ex_level from config Yeoreum Yun
2026-10-03  6:14   ` Suzuki K Poulose
2026-10-03  2:52 ` [PATCH RESEND v13 10/14] coresight: etm4x: rename local config as curr_config referring drvdata->curr_config Yeoreum Yun
2026-10-03  2:52 ` [PATCH RESEND v13 11/14] coresight: etm4x: rename drvdata->config to sysfs_config Yeoreum Yun
2026-10-03  2:52 ` [PATCH RESEND v13 12/14] coresight: etm3x: introduce struct etm_caps Yeoreum Yun
2026-10-03  2:52 ` [PATCH RESEND v13 13/14] coresight: etm3x: rename local config as curr_config referring drvdata->curr_config Yeoreum Yun
2026-10-03  2:52 ` [PATCH RESEND v13 14/14] coresight: etm3x: rename drvdata->config to sysfs_config Yeoreum Yun
2026-10-03  6:56 ` [PATCH RESEND v13 00/14] fix several inconsistencies with sysfs configuration in etmX Suzuki K Poulose

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=asB6JgDE6S6JQr4r@e129823.arm.com \
    --to=yeoreum.yun@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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®