All of lore.kernel.org
 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-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: Re: [PATCH v12 03/14] coresight: etm3x: prohibit modifying cntr_val and reset while session is enabled
Date: Fri, 2 Oct 2026 18:22:48 +0100	[thread overview]
Message-ID: <ar_oaMevzmxSxNwN@e129823.arm.com> (raw)
In-Reply-To: <20260924175814.9AFC01F000FF@smtp.kernel.org>

On Thu, Sep 24, 2026 at 05:58:14PM +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 bypasses session-enabled check in sysfs stores
> --
> 
> commit 0c7e96565d9330c7133fb31d646be9050f666c48
> Author: Yeoreum Yun <yeoreum.yun@arm.com>
> 
> coresight: etm3x: prohibit modifying cntr_val and reset while session is enabled
> 
> This commit prevents cntr_val and reset from being modified while a
> Coresight ETM session is enabled. Changes to cntr_val would be lost when
> the session is disabled, and reset should not be invoked during an active
> session.
> 
> > diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
> > index b3c67e96a82a4..cdb70a4382eb8 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
> > @@ -75,6 +75,10 @@ static ssize_t reset_store(struct device *dev,
> >  	if (ret)
> >  		return ret;
> >  
> > +	if (IS_ERR_OR_NULL(drvdata->csdev) ||
> > +	    coresight_get_mode(drvdata->csdev))
> > +		return -EBUSY;
> > +
> 
> [Severity: Medium]
> Is there a race condition here since the mode check happens outside the
> spinlock?
> 
> If thread A executes this check and sees the mode is disabled, thread B
> could then enable tracing (acquiring drvdata->spinlock, applying config to
> hardware, and updating the mode). 
> 
> When thread A proceeds, it will acquire the spinlock and zero the
> configuration while the hardware is actively using it. When thread B later
> disables tracing, it would partially overwrite the zeroed configuration with
> hardware register values.
> 
> Should the coresight_get_mode() check be moved inside the spinlock to
> prevent this time-of-check to time-of-use race?

TBH, reset interface seems awful and the same problem already pre-exists.
But this kinda was relief we don't think user wouldn't try to enable
before finishing the reset and return its result.

So this is ignorable.

> 
> >  	if (val) {
> >  		spin_lock(&drvdata->spinlock);
> >  		memset(config, 0, sizeof(struct etm_config));
> 
> [ ... ]
> 
> > @@ -744,6 +748,9 @@ static ssize_t cntr_val_store(struct device *dev,
> >  	ret = kstrtoul(buf, 16, &val);
> >  	if (ret)
> >  		return ret;
> > +	if (IS_ERR_OR_NULL(drvdata->csdev) ||
> > +	    coresight_get_mode(drvdata->csdev))
> > +		return -EBUSY;
> 
> [Severity: Medium]
> Does this have the same vulnerability as reset_store()?
> 
> The configuration could be corrupted if tracing is enabled by another thread
> immediately after coresight_get_mode() returns but before the spinlock is
> acquired.
> 
> >  
> >  	spin_lock(&drvdata->spinlock);
> >  	config->cntr_val[config->cntr_idx] = val;

Same above and others

> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20260924-separate_etm_cfg_v2-v12-0-a2b41d2f7c2b@arm.com?part=3

-- 
Sincerely,
Yeoreum Yun

  reply	other threads:[~2026-10-02 17:22 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24 17:33 [PATCH v12 00/14] fix several inconsistencies with sysfs configuration in etmX Yeoreum Yun
2026-09-24 17:33 ` [PATCH v12 01/14] coresight: etm4x: read-back TRCSEQSTR at disabling and prohibit modifying seq_state while enabling Yeoreum Yun
2026-09-24 17:46   ` sashiko-bot
2026-10-02 17:02     ` Yeoreum Yun
2026-09-29 10:40   ` Mike Leach
2026-09-24 17:33 ` [PATCH v12 02/14] coresight: etm4x: prohibit modifying cntr_val while session is enabled Yeoreum Yun
2026-09-29 10:40   ` Mike Leach
2026-09-24 17:33 ` [PATCH v12 03/14] coresight: etm3x: prohibit modifying cntr_val and reset " Yeoreum Yun
2026-09-24 17:58   ` sashiko-bot
2026-10-02 17:22     ` Yeoreum Yun [this message]
2026-09-24 17:33 ` [PATCH v12 04/14] coresight: etm4x: fix inconsistencies with sysfs configuration Yeoreum Yun
2026-09-29 10:48   ` Mike Leach
2026-09-24 17:33 ` [PATCH v12 05/14] coresight: etm3x: " Yeoreum Yun
2026-09-29 10:49   ` Mike Leach
2026-09-24 17:33 ` [PATCH v12 06/14] coresight: etm3x: remove redundant cpu online check on etm_enable_sysfs() Yeoreum Yun
2026-09-24 17:33 ` [PATCH v12 07/14] coresight: etm4x: introduce struct etm4_caps Yeoreum Yun
2026-09-24 17:33 ` [PATCH v12 08/14] coresight: etm4x: exclude ss_status from drvdata->config Yeoreum Yun
2026-09-24 18:21   ` sashiko-bot
2026-10-02 17:15     ` Yeoreum Yun
2026-09-29 10:53   ` Mike Leach
2026-09-24 17:33 ` [PATCH v12 09/14] coresight: etm4x: remove s_ex_level from config Yeoreum Yun
2026-09-24 17:33 ` [PATCH v12 10/14] coresight: etm4x: rename local config as curr_config referring drvdata->curr_config Yeoreum Yun
2026-09-29 10:54   ` Mike Leach
2026-09-24 17:33 ` [PATCH v12 11/14] coresight: etm4x: rename drvdata->config to sysfs_config Yeoreum Yun
2026-09-29 10:55   ` Mike Leach
2026-09-24 17:33 ` [PATCH v12 12/14] coresight: etm3x: introduce struct etm_caps Yeoreum Yun
2026-09-24 17:33 ` [PATCH v12 13/14] coresight: etm3x: rename local config as curr_config referring drvdata->curr_config Yeoreum Yun
2026-09-29 10:55   ` Mike Leach
2026-09-24 17:33 ` [PATCH v12 14/14] coresight: etm3x: rename drvdata->config to sysfs_config Yeoreum Yun
2026-09-24 18:36   ` sashiko-bot
2026-10-02 17:16     ` Yeoreum Yun
2026-09-29 10:55   ` Mike Leach

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=ar_oaMevzmxSxNwN@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.