All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yeoreum Yun" <yeoreum.yun@arm.com>
Cc: linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v11 1/9] coresight: etm4x: prohibit modifying ss_status and cntr_val while session is enabled
Date: Tue, 15 Sep 2026 11:51:15 +0000	[thread overview]
Message-ID: <20260915115115.E6B2A1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260915-separate_etm_cfg_v2-v11-1-d2b258d51747@arm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] coresight: NULL pointer dereference in sysfs stores during device initialization
- [Medium] coresight: TOCTOU race in sysfs store functions bypasses session check
--

commit e0461b6a1ca35a227d37c4654e32e424dc9d60f7
Author: Yeoreum Yun <yeoreum.yun@arm.com>

coresight: etm4x: prohibit modifying ss_status and cntr_val while session is enabled

This commit adds checks to prohibit modifying ss_status and cntr_val via sysfs
while a trace session is enabled. It prevents changes to these values from
being silently overwritten and lost when the session is disabled.

> diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c
> index cc6cdd3ae29d5..8d73248b840a6 100644
> --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c
> +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c
> @@ -1613,6 +1613,8 @@ static ssize_t cntr_val_store(struct device *dev,
>  		return -EINVAL;
>  	if (val > ETM_CNTR_MAX_VAL)
>  		return -EINVAL;
> +	if (coresight_get_mode(drvdata->csdev))

[Severity: High]
Can drvdata->csdev be NULL here if this sysfs attribute is accessed during
device initialization?

If userspace writes to this sysfs attribute immediately upon device creation
(e.g., via udev rules), coresight_register() might not have returned yet to
assign drvdata->csdev in etm4_probe(), leading to a NULL pointer dereference.

Could we use to_coresight_device(dev) instead to avoid this?

> +		return -EBUSY;
>  
>  	raw_spin_lock(&drvdata->spinlock);

[Severity: Medium]
Is there a race condition here since the mode check happens before acquiring
the spinlock?

If Thread A writes to cntr_val and passes the mode check, Thread B could
concurrently enable the session (taking the spinlock, configuring the hardware,
and changing the mode). Thread A would then acquire the spinlock and modify
the software configuration, leaving it out of sync with the active hardware.

Should the mode check be moved inside the spinlock?

>  	idx = config->cntr_idx;
[ ... ]
> @@ -1797,6 +1799,8 @@ static ssize_t sshot_ctrl_store(struct device *dev,
>  
>  	if (kstrtoul(buf, 16, &val))
>  		return -EINVAL;
> +	if (coresight_get_mode(drvdata->csdev))

[Severity: High]
Does this suffer from the same NULL pointer dereference risk during device
initialization as cntr_val_store()?

> +		return -EBUSY;
>  
>  	raw_spin_lock(&drvdata->spinlock);

[Severity: Medium]
Is this check also vulnerable to the same race condition by being outside
the spinlock?

>  	idx = config->ss_idx;
[ ... ]
> @@ -1847,6 +1851,8 @@ static ssize_t sshot_pe_ctrl_store(struct device *dev,
>  
>  	if (kstrtoul(buf, 16, &val))
>  		return -EINVAL;
> +	if (coresight_get_mode(drvdata->csdev))

[Severity: High]
Does this suffer from the same NULL pointer dereference risk during device
initialization as cntr_val_store()?

> +		return -EBUSY;
>  
>  	raw_spin_lock(&drvdata->spinlock);

[Severity: Medium]
Is this check also vulnerable to the same race condition by being outside
the spinlock?

>  	idx = config->ss_idx;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260915-separate_etm_cfg_v2-v11-0-d2b258d51747@arm.com?part=1

  reply	other threads:[~2026-09-15 11:51 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 11:34 [PATCH v11 0/9] fix several inconsistencies with sysfs configuration in etmX Yeoreum Yun
2026-09-15 11:34 ` [PATCH v11 1/9] coresight: etm4x: prohibit modifying ss_status and cntr_val while session is enabled Yeoreum Yun
2026-09-15 11:51   ` sashiko-bot [this message]
2026-09-15 13:26     ` Yeoreum Yun
2026-09-18 11:14   ` Mike Leach
2026-09-18 17:08     ` Yeoreum Yun
2026-09-15 11:34 ` [PATCH v11 2/9] coresight: etm3x: prohibit modifying cntr_val and reset " Yeoreum Yun
2026-09-15 11:48   ` sashiko-bot
2026-09-15 13:30     ` Yeoreum Yun
2026-09-15 13:55       ` Yeoreum Yun
2026-09-18 11:15   ` Mike Leach
2026-09-15 11:34 ` [PATCH v11 3/9] coresight: etm4x: fix inconsistencies with sysfs configuration Yeoreum Yun
2026-09-15 11:53   ` sashiko-bot
2026-09-15 12:36     ` Yeoreum Yun
2026-09-18 13:49   ` Mike Leach
2026-09-18 17:00     ` Yeoreum Yun
2026-09-15 11:34 ` [PATCH v11 4/9] coresight: etm3x: " Yeoreum Yun
2026-09-15 11:47   ` sashiko-bot
2026-09-15 13:42     ` Yeoreum Yun
2026-09-18 13:57   ` Mike Leach
2026-09-18 17:09     ` Yeoreum Yun
2026-09-15 11:34 ` [PATCH v11 5/9] coresight: etm3x: remove redundant cpu online check on etm_enable_sysfs() Yeoreum Yun
2026-09-18 13:58   ` Mike Leach
2026-09-15 11:34 ` [PATCH v11 6/9] coresight: etm4x: introduce struct etm4_caps Yeoreum Yun
2026-09-18 14:01   ` Mike Leach
2026-09-15 11:34 ` [PATCH v11 7/9] coresight: etm4x: exclude ss_status from drvdata->config Yeoreum Yun
2026-09-15 11:49   ` sashiko-bot
2026-09-15 13:35     ` Yeoreum Yun
2026-09-18 14:04   ` Mike Leach
2026-09-18 17:13     ` Yeoreum Yun
2026-09-15 11:34 ` [PATCH v11 8/9] coresight: etm4x: remove s_ex_level from config Yeoreum Yun
2026-09-18 14:05   ` Mike Leach
2026-09-15 11:34 ` [PATCH v11 9/9] coresight: etm3x: introduce struct etm_caps Yeoreum Yun
2026-09-18 14:57   ` Mike Leach
2026-09-24 15:25 ` [PATCH v11 0/9] fix several inconsistencies with sysfs configuration in etmX Leo Yan
2026-09-24 17:28   ` Yeoreum Yun

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