All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 5/8] perf machine: Don't abort guest map creation on first inaccessible dir
Date: Sun, 26 Jul 2026 23:50:45 +0000	[thread overview]
Message-ID: <20260726235045.AA0E21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260726234014.63111-6-acme@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] errno is checked for ERANGE after calling strtol() without explicitly clearing it to 0 beforehand, causing a logic error where one invalid directory skips all subsequent valid guest directories.
--

--- Patch [5]: [PATCH 5/8] perf machine: Don't abort guest map creation on first inaccessible dir ---
commit 3942aff28b363eb417be58b368d8c95bd54e8551
Author: Arnaldo Carvalho de Melo <acme@redhat.com>

perf machine: Don't abort guest map creation on first inaccessible dir

machines__create_guest_kernel_maps() is modified to use 'continue'
instead of jumping to a failure label when a guest directory's
kallsyms file is inaccessible. This allows the loop to process
remaining valid guest directories rather than aborting early.

> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index 05724277c2a97..83d38637afe34 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -1269,14 +1269,12 @@ int machines__create_guest_kernel_maps(struct machines *machines)

[Severity: High]
This is a pre-existing issue, but does this loop correctly handle errno
after a failed strtol() call?

Looking at machines__create_guest_kernel_maps(), the loop checks errno
for ERANGE after calling strtol(), but there doesn't appear to be an
explicit reset of errno beforehand:

tools/perf/util/machine.c:machines__create_guest_kernel_maps() {
    ...
    pid = (pid_t)strtol(namelist[i]->d_name, &endp, 10);
    if ((*endp != '\0') ||
        (endp == namelist[i]->d_name) ||
        (errno == ERANGE)) {
    ...
}

If a directory name causes an overflow (e.g., exceeding LONG_MAX), strtol()
sets errno to ERANGE. In the next loop iteration, if errno is not cleared
to 0, it will retain the ERANGE value. When strtol() processes a valid PID,
it succeeds, but the (errno == ERANGE) check evaluates to true, causing the
valid directory to be incorrectly skipped.

Since this loop processes directories from guestmount, could an unprivileged
user create a bogus directory to prevent symbol resolution for all subsequent
guests?

>  			snprintf(path, sizeof(path), "%s/%s/proc/kallsyms",
>  				 symbol_conf.guestmount,
>  				 namelist[i]->d_name);
> -			ret = access(path, R_OK);
> -			if (ret) {
> +			if (access(path, R_OK)) {
>  				pr_debug("Can't access file %s\n", path);
> -				goto failure;
> +				continue;
>  			}
>  			machines__create_kernel_maps(machines, pid);
>  		}
> -failure:
>  		free(namelist);
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260726234014.63111-1-acme@kernel.org?part=5

  reply	other threads:[~2026-07-26 23:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-26 23:40 [PATCHES 0/8 v1] perf machine fixes Arnaldo Carvalho de Melo
2026-07-26 23:40 ` [PATCH 1/8] perf machine: Fix fd leak on bounds check in maps__set_modules_path_dir() Arnaldo Carvalho de Melo
2026-07-26 23:40 ` [PATCH 2/8] perf machine: Fix NULL parent dereference in fork event processing Arnaldo Carvalho de Melo
2026-07-26 23:54   ` sashiko-bot
2026-07-26 23:40 ` [PATCH 3/8] perf machine: Guard against NULL strlist in machines__findnew() Arnaldo Carvalho de Melo
2026-07-26 23:40 ` [PATCH 4/8] perf machine: Check snprintf truncation " Arnaldo Carvalho de Melo
2026-07-26 23:51   ` sashiko-bot
2026-07-26 23:40 ` [PATCH 5/8] perf machine: Don't abort guest map creation on first inaccessible dir Arnaldo Carvalho de Melo
2026-07-26 23:50   ` sashiko-bot [this message]
2026-07-26 23:40 ` [PATCH 6/8] perf machine: Reset errno before strtol in guest kernel map creation Arnaldo Carvalho de Melo
2026-07-26 23:49   ` sashiko-bot
2026-07-26 23:40 ` [PATCH 7/8] perf machine: Free scandir entries " Arnaldo Carvalho de Melo
2026-07-26 23:51   ` sashiko-bot
2026-07-26 23:40 ` [PATCH 8/8] perf machine: Check snprintf truncation for guest kallsyms path Arnaldo Carvalho de Melo

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=20260726235045.AA0E21F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acme@kernel.org \
    --cc=linux-perf-users@vger.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 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.