[Linux/RISC-V64] pread64 on an O_WRONLY descriptor returns EPERM instead of EBADF
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 80/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
问题出在 qiling/os/posix/syscall/unistd.py 中 pread64 处理函数的第 373-400 行附近,那里捕获了宿主机的 OSError,却只返回裸的 -1,没有附带 errno。请先为 riscv64 编译 issue 中的 C 探针,并在 rootfs 中放入 probe.bin,用 Qiling 运行,以确认 EPERM。完成的标准是:O_WRONLY 的 pread64 报告 EBADF,可读的对照用例仍能读取一个字节,且输出字节保持不变。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
For a valid file descriptor opened with O_WRONLY, Linux pread64 returns EBADF because the descriptor is not open for reading. Qiling catches the host OSError but returns raw -1, which the RV64 guest observes as EPERM.
Sample Code
Place a file named probe.bin in the guest rootfs and run this static RV64 guest:
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/syscall.h>
#include <unistd.h>
int main(void)
{
char byte = 0x55;
int write_only = open("/probe.bin", O_WRONLY);
if (write_only < 0)
return 2;
errno = 0;
long bad = syscall(SYS_pread64, write_only, &byte, 1, 0);
int bad_errno = errno;
char after_bad = byte;
int readable = open("/probe.bin", O_RDONLY);
if (readable < 0)
return 3;
long good = syscall(SYS_pread64, readable, &byte, 1, 0);
printf("write_only=%ld errno=%d after_bad=%02x readable=%ld byte=%02x\n",
bad, bad_errno, (unsigned char)after_bad, good,
(unsigned char)byte);
return 0;
}
riscv64-linux-gnu-gcc -static -O2 -Wall -Wextra pread64_probe.c -o probe.elf
mkdir -p rootfs
printf X > rootfs/probe.bin
cp probe.elf rootfs/probe.elf
python3 -c 'from qiling import Qiling; Qiling(["./rootfs/probe.elf"], "./rootfs").run()'
The readable descriptor is a success control and should read one byte. The O_WRONLY call should leave the output byte unchanged and report EBADF.
Expected behavior
The guest should observe -1 with errno=EBADF for the O_WRONLY descriptor. Qiling v1.4.11 returns raw -1, which becomes EPERM in the guest. The affected handler catches OSError without preserving its errno in unistd.py.
Additional context
The baseline behavior was reproduced on RV64 Linux with Qiling v1.4.11. The current dev commit 23ad4fd369a360ad7992d90cb7577f0241061c2b has the same exception path; this current-head check was static. The read-only/write-only semantics are covered by Linux pread64(2).
- 主要语言
- 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 半天 新手友好度 82/100
qilingframework/qiling#1640 ·
-
Linked to wiki installation instructions from source are incorrect可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 1/5 1-3 小时 新手友好度 78/100
qilingframework/qiling#1628 ·
查看 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 天内回复