Re: [PATCH v2] coresight: etm4x: Fix PID tracing when perf is run in an init PID namespace

From: Leo Yan
Date: Sun Oct 13 2024 - 10:55:36 EST


On Tue, Oct 08, 2024 at 10:02:25PM +0200, Julien Meunier wrote:
> The previous implementation limited the tracing capabilities when perf
> was run in the init PID namespace, making it impossible to trace
> applications in non-init PID namespaces.
>
> This update improves the tracing process by verifying the event owner.
> This allows us to determine whether the user has the necessary
> permissions to trace the application.
>
> Cc: stable@xxxxxxxxxxxxxxx
> Fixes: aab473867fed ("coresight: etm4x: Don't trace PID for non-root PID namespace")
> Signed-off-by: Julien Meunier <julien.meunier@xxxxxxxxx>

Reviewed-by: Leo Yan <leo.yan@xxxxxxxxx>

> ---
> Changes in v2:
> * Update comments
> ---
> drivers/hwtracing/coresight/coresight-etm4x-core.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> index 66d44a404ad0..cf41c42399e1 100644
> --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> @@ -693,9 +693,9 @@ static int etm4_parse_event_config(struct coresight_device *csdev,
> config->cfg |= TRCCONFIGR_TS;
> }
>
> - /* Only trace contextID when runs in root PID namespace */
> + /* Only trace contextID when the event owner is in root PID namespace */
> if ((attr->config & BIT(ETM_OPT_CTXTID)) &&
> - task_is_in_init_pid_ns(current))
> + task_is_in_init_pid_ns(event->owner))
> /* bit[6], Context ID tracing bit */
> config->cfg |= TRCCONFIGR_CID;
>
> @@ -709,8 +709,8 @@ static int etm4_parse_event_config(struct coresight_device *csdev,
> ret = -EINVAL;
> goto out;
> }
> - /* Only trace virtual contextID when runs in root PID namespace */
> - if (task_is_in_init_pid_ns(current))
> + /* Only trace virtual contextID when the event owner is in root PID namespace */
> + if (task_is_in_init_pid_ns(event->owner))
> config->cfg |= TRCCONFIGR_VMID | TRCCONFIGR_VMIDOPT;
> }
>
> --
> 2.34.1
>