]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf dso: Set standard errno on decompression failure
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 13 Jun 2026 18:55:33 +0000 (15:55 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 17 Jun 2026 12:21:03 +0000 (09:21 -0300)
dso__get_filename() sets errno to a negative custom DSO_LOAD_ERRNO
value when kernel module decompression fails:

  errno = *dso__load_errno(dso);  /* e.g. -9996 */

The caller __open_dso() then computes fd = -errno, producing a large
positive value (9996) that looks like a valid file descriptor.  This
can cause close_data_fd() to close an unrelated fd used by another
subsystem.

Set errno to EIO instead.  The detailed error code is already stored
in dso__load_errno(dso) for diagnostic messages.

Fixes: 1d6b3c9ba756a513 ("perf tools: Decompress kernel module when reading DSO data")
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

index 79f1a30f3683d6b32321d4dbca964b9b468e376d..2309196d8df3111c47ba924390ab968f6d259995 100644 (file)
@@ -600,7 +600,13 @@ static char *dso__get_filename(struct dso *dso, const char *root_dir,
                size_t len = sizeof(newpath);
 
                if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) {
-                       errno = *dso__load_errno(dso);
+                       /*
+                        * Use a standard errno value, not the negative custom
+                        * DSO_LOAD_ERRNO stored in dso__load_errno(dso):
+                        * __open_dso() computes fd = -errno, so a negative
+                        * errno produces a positive fd that looks valid.
+                        */
+                       errno = EIO;
                        goto out;
                }