diff options
author | Emil Velikov <emil.l.velikov@gmail.com> | 2024-02-12 17:23:05 +0000 |
---|---|---|
committer | Lucas De Marchi <lucas.de.marchi@gmail.com> | 2024-04-30 12:33:52 -0500 |
commit | 90b271fbd2b9708a8fa79b7e98d90c7919e7ed73 (patch) | |
tree | 3e5e244448be171bf33376659aa34a9243b43aef | |
parent | 03da2db1358f5ae3b50596f04e5e05bcf7a48fee (diff) | |
download | kmod-90b271fbd2b9708a8fa79b7e98d90c7919e7ed73.tar.gz |
libkmod: clear file->memory if map fails
On mmap failure file->memory is set to -1, which we'll happily pass down
to munmap later on.
More importantly, since we do a NULL check in kmod_file_load_contents()
we will exit the function without (re)attempting the load again.
Since we ignore the return code for the load function(s), one can end up
calling kmod_elf_get_memory() and feed that -1 into init_module.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
-rw-r--r-- | libkmod/libkmod-file.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index abd4723..b408aed 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -392,8 +392,10 @@ static int load_reg(struct kmod_file *file) file->size = st.st_size; file->memory = mmap(NULL, file->size, PROT_READ, MAP_PRIVATE, file->fd, 0); - if (file->memory == MAP_FAILED) + if (file->memory == MAP_FAILED) { + file->memory = NULL; return -errno; + } return 0; } |