[RISC-V64/Linux] ftruncate succeeds on an O_RDONLY descriptor
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 66/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
Start in the ftruncate handler in qiling/os/posix/syscall/unistd.py, which passes the host path to a path-based truncate helper. Check how the guest fd is mapped to its open file and whether its access mode is available there. Reproduce with the C probe from the issue on an RV64 rootfs. Done when ftruncate on an O_RDONLY descriptor returns EBADF and leaves the file size unchanged.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
On an RV64 Linux guest, ftruncate(fd, 0) succeeds when fd was opened with O_RDONLY, and the file is truncated. Linux returns EBADF for ftruncate on a descriptor that is not open for writing and leaves the file unchanged.
Sample Code
Create rootfs/scratch with the contents abc, then run this static RV64 guest:
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
int main(void)
{
int fd = open("/scratch", O_RDONLY);
if (fd < 0)
return 2;
errno = 0;
int rc = ftruncate(fd, 0);
int err = errno;
struct stat st;
if (stat("/scratch", &st) != 0)
return 3;
printf("rc=%d errno=%d size=%ld\n", rc, err, (long)st.st_size);
return 0;
}
riscv64-linux-gnu-gcc -static -O2 -Wall -Wextra ftruncate_probe.c -o probe.elf
mkdir -p rootfs
printf abc > rootfs/scratch
cp probe.elf rootfs/probe.elf
python3 -c 'from qiling import Qiling; Qiling(["./rootfs/probe.elf"], "./rootfs").run()'
Linux returns -1/EBADF and leaves the size at 3. Qiling returns success and the size becomes 0.
Expected behavior
Qiling should check that the guest descriptor is open for writing before changing the file length. The current ftruncate handler passes the host path to a path-based truncate helper, which does not check the guest descriptor's access mode.
Additional context
Reproduced on Qiling v1.4.11 and the development snapshot for RV64 Linux. Current dev commit 23ad4fd369a360ad7992d90cb7577f0241061c2b still has the same ftruncate path. The current source was checked statically; full upstream CI has not been run.
- 主要语言
- Python
- 星标
- 6.2k
- 派生
- 806
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
qilingframework/qiling 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
qilingframework/qiling#1690 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
qilingframework/qiling#1689 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
qilingframework/qiling#1688 ·
-
难度 2/5 1-3 小时 新手友好度 80/100
qilingframework/qiling#1686 ·
-
难度 2/5 半天 新手友好度 82/100
qilingframework/qiling#1640 ·
查看 qilingframework/qiling 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
huggingface/datasets#9128 ·
维护者通常 1 天内回复
-
priority:low ready-for-dev
难度 2/5 1-3 小时 新手友好度 68/100
OpenHands/extensions#975 ·
维护者通常 1 天内回复
-
Function/dict state handlers can't supply provider-state injected values (`generate.provider_state`)未关闭
难度 2/5 1-3 小时 新手友好度 78/100
pact-foundation/pact-python#1789 ·
维护者通常 9 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 82/100
juandresrodca/AdminForge#66 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复