1 Star 0 Fork 32

wangyuhang/dracut

forked from src-openEuler/dracut 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-fix-dracut-install-protect-against-broken-links-poin.patch 3.32 KB
一键复制 编辑 原始数据 按行查看 历史
Venland 提交于 2023-09-25 17:49 . backport update stream
From 32f6f364ddeb706bf8741f2895d60022aee264e7 Mon Sep 17 00:00:00 2001
From: Antonio Alvarez Feijoo <antonio.feijoo@suse.com>
Date: Thu, 10 Aug 2023 09:22:28 +0200
Subject: [PATCH] fix(dracut-install): protect against broken links pointing to
themselves
`readlink` does not return an error if a symbolic link points to itself, which
can cause a stack overflow due to infinite recursion in the `get_real_file`
function.
Although this type of recursive links should not exist, we discovered this
issue on a real system. It can be reproduced as follows:
```
> ls -l /lib64/libblkid.so
-rwxr-xr-x 1 root root 224368 Aug 9 15:13 /lib64/libblkid.so
> rm -f /lib64/libblkid.so
> ln -s /lib64/libblkid.so /lib64/libblkid.so
> ls -l /lib64/libblkid.so
lrwxrwxrwx 1 root root 18 Aug 9 15:06 /lib64/libblkid.so -> /lib64/libblkid.so
> dracut -f -I "/lib64/libblkid.so" test.img
...
dracut-install: Handle '/lib64/libblkid.so'
dracut-install: dracut_install('/lib64/libblkid.so', '/lib64/libblkid.so', 0, 0, 1)
dracut-install: get_real_file('/lib64/libblkid.so')
dracut-install: get_real_file: readlink('/lib64/libblkid.so') returns '/lib64/libblkid.so'
dracut-install: get_real_file('/lib64/libblkid.so') => '/lib64/libblkid.so'
...
[infinite recursion]
...
dracut-install: dracut_install('/lib64/libblkid.so', '/lib64/libblkid.so', 0, 0, 1)
dracut-install: get_real_file('/lib64/libblkid.so')
dracut-install: get_real_file: readlink('/lib64/libblkid.so') returns '/lib64/libblkid.so'
dracut-install: get_real_file('/lib64/libblkid.so') => '/lib64/libblkid.so'
dracut-install: dracut_install('/lib64/libblkid.so', '/lib64/libblkid.so', 0, 0, 1)
/usr/lib/dracut/dracut-init.sh: line 298: 20949 Segmentation fault (core dumped) $DRACUT_INSTALL ${dracutsysrootdir:+-r "$dracutsysrootdir"} ${initdir:+-D "$initdir"} -a ${loginstall:+-L "$loginstall"} ${DRACUT_RESOLVE_DEPS:+-l} ${DRACUT_FIPS_MODE:+-f} ${_hostonly_install:+-H} "$@"
dracut: FAILED: /usr/lib/dracut/dracut-install --debug -D /var/tmp/dracut.dqLmOS/initramfs -a /lib64/libblkid.so
...
```
After applying this patch:
```
> dracut -f -I "/lib64/libblkid.so" test.img
...
dracut-install: Handle '/lib64/libblkid.so'
dracut-install: dracut_install('/lib64/libblkid.so', '/lib64/libblkid.so', 0, 0, 1)
dracut-install: get_real_file('/lib64/libblkid.so')
dracut-install: get_real_file: readlink('/lib64/libblkid.so') returns '/lib64/libblkid.so'
dracut-install: ERROR: '/lib64/libblkid.so' is pointing to itself.
dracut-install: ERROR: installing '/lib64/libblkid.so'
dracut: FAILED: /usr/lib/dracut/dracut-install --debug -D /var/tmp/dracut.4w8FVL/initramfs -a /lib64/libblkid.so
...
```
---
src/install/dracut-install.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/install/dracut-install.c b/src/install/dracut-install.c
index 5cfcf5170..485143a58 100644
--- a/src/install/dracut-install.c
+++ b/src/install/dracut-install.c
@@ -480,6 +480,11 @@ static char *get_real_file(const char *src, bool fullyresolve)
log_debug("get_real_file: readlink('%s') returns '%s'", fullsrcpath, linktarget);
+ if (streq(fullsrcpath, linktarget)) {
+ log_error("ERROR: '%s' is pointing to itself", fullsrcpath);
+ return NULL;
+ }
+
if (linktarget[0] == '/') {
_asprintf(&abspath, "%s%s", (sysrootdirlen ? sysrootdir : ""), linktarget);
} else {
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangyuhang27/dracut.git
git@gitee.com:wangyuhang27/dracut.git
wangyuhang27
dracut
dracut
master

搜索帮助