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 07/14] gtrace: Add function to copy into perf AUX buffer
Date: Thu, 01 Oct 2026 05:40:11 +0000 [thread overview]
Message-ID: <20261001054011.7A8171F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261001052243.3042627-8-mayuresh.chitale@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] gtrace: wild pointer and UAF during concurrent driver unbind
- [Medium] gtrace: lock mismatch by iterating over path in gtrace_path_copyto_auxbuf()
--
commit 727fcf662499fff522c570fa7a02e693a5593303
Author: Anup Patel <anup.patel@oss.qualcomm.com>
gtrace: Add function to copy into perf AUX buffer
The RISC-V trace ramsink will need a mechanism to copy trace data
into the perf AUX buffer. Add gtrace_path_copyto_auxbuf() function
and corresponding trace driver callback copyto_auxbuf() for this
purpose.
> diff --git a/drivers/hwtracing/gtrace/gtrace-core.c b/drivers/hwtracing/gtrace/gtrace-core.c
> index d7f1df90aa31d..acbeb3df21354 100644
> --- a/drivers/hwtracing/gtrace/gtrace-core.c
> +++ b/drivers/hwtracing/gtrace/gtrace-core.c
> @@ -715,6 +715,47 @@ int gtrace_path_stop(struct gtrace_path *path)
> }
> EXPORT_SYMBOL_GPL(gtrace_path_stop);
>
> +int gtrace_path_copyto_auxbuf(struct gtrace_path *path,
> + struct gtrace_perf_auxbuf *buf,
> + size_t *bytes_copied, u64 *format)
> +{
> + struct gtrace_comp_priv *sink = to_gtrace_comp_priv(gtrace_path_sink(path));
> + const struct gtrace_driver *gtdrv;
> + struct gtrace_component *comp;
> + struct gtrace_path_node *node;
> + int ret = -EOPNOTSUPP;
> + unsigned long flags;
> +
> + /*
> + * Copy only after every path using the sink has stopped; otherwise the
> + * hardware may overwrite data being copied, or the same data may be copied
> + * to aux buffer twice. The last path to stop does the copy. Holding the
> + * sink's lock also stops another path from starting the sink before copy
> + * completes.
> + */
> + raw_spin_lock_irqsave(&sink->lock, flags);
> + if (sink->start_count) {
> + *bytes_copied = 0;
> + ret = 0;
> + goto out;
> + }
> +
> + list_for_each_entry(node, &path->comp_list, head) {
[Severity: Medium]
Will this loop cause a lock mismatch if an intermediate component implements
copyto_auxbuf?
The function acquires sink->lock, but iterates over path->comp_list to find
and execute the callback. If a non-sink component is matched, its callback
will run under the sink's lock rather than its own, which may allow data races
with concurrent start or stop operations on that intermediate component.
> + comp = node->comp;
> + gtdrv = to_gtrace_driver(comp->dev.driver);
[Severity: High]
Does this code allow concurrent driver unbind to cause a use-after-free or
NULL pointer offset dereference?
The to_gtrace_driver() macro double-evaluates comp->dev.driver. If it is set
to NULL by a concurrent unbind between evaluations, the macro yields a negative
offset rather than NULL. This bypasses the !gtdrv check and dereferences an
invalid pointer.
Additionally, since no device lock or module reference is held here, can the
driver be unloaded while the callback is executing?
> + if (!gtdrv || !gtdrv->copyto_auxbuf)
> + continue;
> +
> + *bytes_copied = gtdrv->copyto_auxbuf(comp, buf, format);
> + ret = 0;
> + break;
> + }
> +out:
> + raw_spin_unlock_irqrestore(&sink->lock, flags);
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(gtrace_path_copyto_auxbuf);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261001052243.3042627-1-mayuresh.chitale@oss.qualcomm.com?part=7
next prev parent reply other threads:[~2026-10-01 5:40 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
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 [this message]
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=20261001054011.7A8171F000FF@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