mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 22:14:03 +02:00
perf dso: Guard close() against invalid fd in dso__decompress_kmodule_path()
dso__decompress_kmodule_path() unconditionally calls close(fd) on the
return value of decompress_kmodule(). When decompression fails or the
DSO is not compressed, decompress_kmodule() returns -1. close(-1)
fails with EBADF and clobbers errno, which callers up the chain
(dso__get_filename → __open_dso) depend on for error propagation.
Guard the close() call with fd >= 0 so only valid file descriptors are
closed.
Fixes: 42b3fa6708 ("perf tools: Introduce dso__decompress_kmodule_{fd,path}")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Reviewed-by: Ian Rogers <irogers@google.com>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
parent
51a7a9ddcb
commit
10f452dc2d
|
|
@ -395,7 +395,9 @@ int dso__decompress_kmodule_path(struct dso *dso, const char *name,
|
|||
{
|
||||
int fd = decompress_kmodule(dso, name, pathname, len);
|
||||
|
||||
close(fd);
|
||||
/* decompress_kmodule() returns -1 on failure, don't close(-1) */
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
return fd >= 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user