7 Star 0 Fork 28

src-openEuler/kmod

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0003-clear-file-memory-if-map-fails.patch 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
zhangyaqi 提交于 2024-05-10 10:17 . clear file memory if map fails
From 90b271fbd2b9708a8fa79b7e98d90c7919e7ed73 Mon Sep 17 00:00:00 2001
From: Emil Velikov <emil.l.velikov@gmail.com>
Date: Mon, 12 Feb 2024 17:23:05 +0000
Subject: 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>
---
libkmod/libkmod-file.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c
index b6a8cc9..1e1dd35 100644
--- a/libkmod/libkmod-file.c
+++ b/libkmod/libkmod-file.c
@@ -401,8 +401,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;
+ }
file->direct = true;
return 0;
}
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/kmod.git
git@gitee.com:src-openeuler/kmod.git
src-openeuler
kmod
kmod
master

搜索帮助