mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	James Clark <james.clark@linaro.org>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	sashiko-bot <sashiko-bot@kernel.org>
Subject: Re: [PATCH 3/5] perf dso: Use stored fd error instead of stale errno in file_read() and file_size()
Date: Thu, 13 Aug 2026 11:25:54 +0900	[thread overview]
Message-ID: <an0rMidlKOX1LrgV@google.com> (raw)
In-Reply-To: <CAP-5=fX4AC7yPa_6xXoVmAswhUetnvth59mtPpHmX8Qp4bdf5w@mail.gmail.com>

On Wed, Aug 12, 2026 at 04:12:52PM -0700, Ian Rogers wrote:
> On Tue, Aug 11, 2026 at 10:52 AM Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> >
> > From: Arnaldo Carvalho de Melo <acme@redhat.com>
> >
> > file_read() and file_size() use ret = -errno when
> > dso__data(dso)->fd is negative after try_to_open_dso() fails.  By this
> > point errno has been through mutex_lock(), nsinfo__mountns_enter(), and
> > multiple open() attempts inside try_to_open_dso() — it no longer
> > reflects the actual open failure.  If errno happens to be 0, ret = 0
> > looks like EOF rather than an error, and file_size() callers like
> > dso__data_size() would then report a zero-sized file instead of
> > failing.
> >
> > dso__data(dso)->fd is always negative on failure — -errno from
> > __open_dso() when no filename could be built (e.g. -EINVAL, -ENOENT),
> > or -1 when do_open() itself failed — and never 0, so use it directly
> > instead of reading the stale global errno.
> >
> > Fixes: 33bdedcea2d7 ("perf tools: Protect dso cache fd with a mutex")
> > Reported-by: sashiko-bot <sashiko-bot@kernel.org>
> > Cc: Namhyung Kim <namhyung@kernel.org>
> > Assisted-by: Claude:claude-opus-4.6
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > ---
> >  tools/perf/util/dso.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
> > index 124193453675ca18..32ae5c78cdb906e6 100644
> > --- a/tools/perf/util/dso.c
> > +++ b/tools/perf/util/dso.c
> > @@ -1029,7 +1029,8 @@ static ssize_t file_read(struct dso *dso, struct machine *machine,
> >
> >         if (dso__data(dso)->fd < 0) {
> >                 dso__data(dso)->status = DSO_DATA_STATUS_ERROR;
> > -               ret = -errno;
> > +               /* fd is always negative here: -errno or -1, never 0 */
> > +               ret = dso__data(dso)->fd;
> 
> nit: we can "assert(ret < 0);" to verify the comment.

It's already checked in the above if statement.  I'm not sure the
comment or assert is necessary.

Thanks,
Namhyung


  reply	other threads:[~2026-08-13  2:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-11 17:51 [PATCHES v3 0/5] perf DSO hardening series Arnaldo Carvalho de Melo
2026-08-11 17:51 ` [PATCH 1/5] perf dso: Guard against errno==0 when dso__get_filename() returns NULL Arnaldo Carvalho de Melo
2026-08-11 17:51 ` [PATCH 2/5] perf dso: Guard close() against invalid fd in dso__decompress_kmodule_path() Arnaldo Carvalho de Melo
2026-08-11 17:51 ` [PATCH 3/5] perf dso: Use stored fd error instead of stale errno in file_read() and file_size() Arnaldo Carvalho de Melo
2026-08-12 23:12   ` Ian Rogers
2026-08-13  2:25     ` Namhyung Kim [this message]
2026-08-13 14:09       ` Arnaldo Carvalho de Melo
2026-08-11 17:51 ` [PATCH 4/5] perf dso: Guard against cache underflow on short reads in dso_cache__memcpy() Arnaldo Carvalho de Melo
2026-08-11 17:51 ` [PATCH 5/5] perf dso: Replace assert with runtime check in dso__read_symbol() Arnaldo Carvalho de Melo
2026-08-12 17:18 ` [PATCHES v3 0/5] perf DSO hardening series Arnaldo Carvalho de Melo
2026-08-12 23:24   ` Ian Rogers
2026-08-13  0:49 [PATCHES v4 " Arnaldo Carvalho de Melo
2026-08-13  0:49 ` [PATCH 3/5] perf dso: Use stored fd error instead of stale errno in file_read() and file_size() Arnaldo Carvalho de Melo
2026-08-13 15:11 [PATCHES v5 0/5] perf DSO hardening series Arnaldo Carvalho de Melo
2026-08-13 15:11 ` [PATCH 3/5] perf dso: Use stored fd error instead of stale errno in file_read() and file_size() 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=an0rMidlKOX1LrgV@google.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=sashiko-bot@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®