[Linux/RISC-V64] pread64 on an O_WRONLY descriptor returns EPERM instead of EBADF

オープン 初心者向け
#1,686 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
80/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, python

調査の方向性

バグは qiling/os/posix/syscall/unistd.py の pread64 ハンドラ、373〜400行目付近にあります。ここではホストの OSError を捕捉し、errno を付けずに生の -1 を返しています。まず issue の C プローブを riscv64 向けにコンパイルし、rootfs 内に probe.bin を置いて Qiling 上で実行し、EPERM を確認してください。O_WRONLY の pread64 が EBADF を報告し、読み取り可能な対照ケースが引き続き 1 バイト読め、出力バイトが変わらなければ完了です。

索引モデルが 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 ファイルあり
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

qilingframework/qiling のほかの issue

qilingframework/qiling の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。