Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mayuresh Chitale" <mayuresh.chitale@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v6 04/14] gtrace: Add functions to create/destroy a trace component path
Date: Thu, 01 Oct 2026 05:36:00 +0000	[thread overview]
Message-ID: <20261001053601.12C121F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261001052243.3042627-5-mayuresh.chitale@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] gtrace: lockless driver callbacks lead to unmapped memory execution
- [High] gtrace: gtrace_cpu_source returns component without holding reference
--

commit aae09d737c66acc0654dfd58c7118f63245ce4b1
Author: Anup Patel <anup.patel@oss.qualcomm.com>

gtrace: Add functions to create/destroy a trace component path

This patch adds functions to create and destroy a trace component path.
A trace component path represents a chain of trace components connected
to each other, which will be used by gtrace perf support.

> diff --git a/drivers/hwtracing/gtrace/gtrace-core.c b/drivers/hwtracing/gtrace/gtrace-core.c
> index d374c679a6498..f750025104ec9 100644
> --- a/drivers/hwtracing/gtrace/gtrace-core.c
> +++ b/drivers/hwtracing/gtrace/gtrace-core.c

[ ... ]

>  struct gtrace_component *gtrace_cpu_source(unsigned int cpu)
>  {
>  	if (!cpu_present(cpu))
>  		return NULL;
>  
>  	return per_cpu(gtrace_cpu_source_comp, cpu);
>  }

[Severity: High]
Does this return the component without holding a reference to it?

If a caller operates on this pointer without pinning it, and the component is
concurrently unregistered via gtrace_unregister_component(), could this lead
to a use-after-free? When the caller later passes this pointer to
gtrace_create_path(), it would be dereferenced during the walk of output
components.

Should this hold gtrace_mutex or take a reference via get_device() before
returning the component?

[ ... ]

> +static int gtrace_assign_trace_id(struct gtrace_path *path)
> +{
> +	const struct gtrace_driver *gtdrv;
> +	struct gtrace_component *comp;
> +	struct gtrace_path_node *node;
> +	int trace_id;
> +
> +	list_for_each_entry(node, &path->comp_list, head) {
> +		comp = node->comp;
> +		gtdrv = to_gtrace_driver(comp->dev.driver);
> +
> +		if (!gtdrv || !gtdrv->get_trace_id)
> +			continue;
> +
> +		trace_id = gtdrv->get_trace_id(comp, path->mode);

[Severity: High]
Can this locklessly access the driver and execute unmapped memory?

Taking a device reference during path creation prevents the device memory from
being freed, but does it prevent the module from unloading? If the component
module is unloaded concurrently, comp->dev.driver is cleared and the module
code is freed.

If a racing thread fetches the driver pointer just prior to unbind, could it
subsequently invoke gtdrv->get_trace_id() after the function has been unmapped,
resulting in a kernel panic?

> +		if (trace_id > 0) {
> +			path->trace_id = trace_id;
> +			return 0;
> +		} else if (trace_id < 0) {

[ ... ]

> +static bool gtrace_path_ready(struct gtrace_path *path)
> +{
> +	struct gtrace_comp_priv *cpriv;
> +	struct gtrace_path_node *node;
> +
> +	list_for_each_entry(node, &path->comp_list, head) {
> +		cpriv = to_gtrace_comp_priv(node->comp);
> +		if (!cpriv->ready)
> +			return false;

[Severity: High]
Is it safe to read cpriv->ready here without holding the device_lock?

If the driver is concurrently unbound, could this be reading a value that is
no longer protected against modification?

> +	}
> +
> +	return true;
> +}

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261001052243.3042627-1-mayuresh.chitale@oss.qualcomm.com?part=4

  reply	other threads:[~2026-10-01  5:36 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01  5:22 [PATCH v6 00/14] Linux RISC-V trace framework and drivers Mayuresh Chitale
2026-10-01  5:22 ` [PATCH v6 01/14] dt-bindings: Add RISC-V trace component bindings Mayuresh Chitale
2026-10-01  5:33   ` sashiko-bot
2026-10-01  5:22 ` [PATCH v6 02/14] hwtracing: gtrace: Initial implementation of gtrace framework Mayuresh Chitale
2026-10-01  5:37   ` sashiko-bot
2026-10-01  5:22 ` [PATCH v6 03/14] gtrace: Add RISC-V platform driver for the " Mayuresh Chitale
2026-10-01  5:36   ` sashiko-bot
2026-10-01  5:22 ` [PATCH v6 04/14] gtrace: Add functions to create/destroy a trace component path Mayuresh Chitale
2026-10-01  5:36   ` sashiko-bot [this message]
2026-10-01  5:22 ` [PATCH v6 05/14] gtrace: Add functions to start/stop tracing on a " Mayuresh Chitale
2026-10-01  5:36   ` sashiko-bot
2026-10-01  5:22 ` [PATCH v6 06/14] gtrace: Add RISC-V Trace encoder driver Mayuresh Chitale
2026-10-01  5:34   ` sashiko-bot
2026-10-01  5:22 ` [PATCH v6 07/14] gtrace: Add function to copy into perf AUX buffer Mayuresh Chitale
2026-10-01  5:40   ` sashiko-bot
2026-10-01  5:22 ` [PATCH v6 08/14] perf: Add gtrace AUX buffer trace format type Mayuresh Chitale
2026-10-01  5:22 ` [PATCH v6 09/14] gtrace: Add RISC-V Trace ramsink driver Mayuresh Chitale
2026-10-01  5:42   ` sashiko-bot
2026-10-01  5:22 ` [PATCH v6 10/14] riscv: Enable DMA_RESTRICTED_POOL in defconfig Mayuresh Chitale
2026-10-01  5:22 ` [PATCH v6 11/14] gtrace: Add perf driver for tracing using perf tool Mayuresh Chitale
2026-10-01  5:44   ` sashiko-bot
2026-10-01  5:22 ` [PATCH v6 12/14] perf tools: Add RISC-V trace PMU record capabilities Mayuresh Chitale
2026-10-01  5:22 ` [PATCH v6 13/14] perf tools: Initial support for gtrace decoder Mayuresh Chitale
2026-10-01  5:35   ` sashiko-bot
2026-10-01  5:22 ` [PATCH v6 14/14] MAINTAINERS: Add entry for RISC-V trace framework Mayuresh Chitale

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=20261001053601.12C121F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=mayuresh.chitale@oss.qualcomm.com \
    --cc=robh@kernel.org \
    --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