[Linux/RISC-V64] pread64 on an O_WRONLY descriptor returns EPERM instead of EBADF
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 80/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- reverse-engineering
Hướng nghiên cứu
Lỗi nằm ở trình xử lý pread64 trong qiling/os/posix/syscall/unistd.py, khoảng dòng 373-400, nơi OSError của máy chủ bị bắt và trả về -1 thô mà không kèm errno. Hãy bắt đầu bằng cách biên dịch đoạn probe C trong issue cho riscv64 và chạy nó dưới Qiling với probe.bin trong rootfs để xác nhận EPERM. Hoàn thành khi pread64 với O_WRONLY báo EBADF, đối chứng có thể đọc vẫn đọc được một byte và byte đầu ra không thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- Python
- Star
- 6.2k
- Fork
- 806
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của qilingframework/qiling
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
qilingframework/qiling#1690 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
qilingframework/qiling#1689 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
qilingframework/qiling#1688 ·
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 82/100
qilingframework/qiling#1640 ·
-
Linked to wiki installation instructions from source are incorrectCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
qilingframework/qiling#1628 ·
Tất cả issue của qilingframework/qiling
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
huggingface/datasets#9128 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
priority:low ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
OpenHands/extensions#975 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Function/dict state handlers can't supply provider-state injected values (`generate.provider_state`)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pact-foundation/pact-python#1789 ·
Maintainer thường phản hồi trong vòng 9 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
juandresrodca/AdminForge#66 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày