[Linux/RISC-V64] pread64 on an O_WRONLY descriptor returns EPERM instead of EBADF
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 80/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Área
- reverse-engineering
Línea de trabajo
El error está en el manejador de pread64 en qiling/os/posix/syscall/unistd.py, alrededor de las líneas 373-400, donde se captura el OSError del host y se devuelve un -1 sin su errno. Empieza compilando la sonda en C del issue para riscv64 y ejecutándola bajo Qiling con un probe.bin en el rootfs para confirmar el EPERM. Está terminado cuando el pread64 con O_WRONLY informa EBADF, el control de lectura sigue leyendo un byte y el byte de salida no cambia.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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).
- Lenguaje dominante
- Python
- Estrellas
- 6.2k
- Forks
- 806
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de qilingframework/qiling
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
qilingframework/qiling#1690 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
qilingframework/qiling#1689 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
qilingframework/qiling#1688 ·
-
Dificultad 2/5 Medio día Aptitud para principiantes 82/100
qilingframework/qiling#1640 ·
-
Linked to wiki installation instructions from source are incorrectPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
qilingframework/qiling#1628 ·
Todos los issues de qilingframework/qiling
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
huggingface/datasets#9128 ·
Los mantenedores suelen responder en 1 día
-
priority:low ready-for-dev
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
OpenHands/extensions#975 ·
Los mantenedores suelen responder en 1 día
-
Function/dict state handlers can't supply provider-state injected values (`generate.provider_state`)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
pact-foundation/pact-python#1789 ·
Los mantenedores suelen responder en 9 días
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
juandresrodca/AdminForge#66 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día