[RISC-V/Linux] newfstatat ignores unsupported flags

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

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

評価

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

調査の方向性

The newfstatat handler lives in qiling/os/posix/syscall/stat.py; start there and check how the flags argument is read and whether unknown bits are rejected before the stat buffer is written. The reproducer is the C program in the issue, built as a static RV64 binary and run with Qiling against a rootfs containing a file named probe. Done means the invalid-flag call returns -1 with EINVAL and leaves the guest buffer untouched, while the flags-zero control call still succeeds.

索引モデルが issue の本文から書いたものです。

説明

Describe the bug

On an RV64 Linux guest, Qiling v1.4.11 accepts an unknown newfstatat flag bit and returns success. Linux returns EINVAL for the same request. Qiling also writes a stat structure to the guest buffer even though the request should fail.

Sample Code

Place a regular file named probe in the guest rootfs and run this static RV64 guest:

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <unistd.h>

int main(void)
{
    struct stat st;
    long control = syscall(SYS_newfstatat, AT_FDCWD, "probe", &st, 0);
    if (control != 0)
        return 2;
    memset(&st, 0xaa, sizeof(st));
    errno = 0;
    long rc = syscall(SYS_newfstatat, AT_FDCWD, "probe", &st, 0x40000000);
    int invalid_errno = errno;
    printf("control=%ld invalid=%ld errno=%d mode=%o\n",
           control, rc, invalid_errno, st.st_mode);
    return !(rc == -1 && invalid_errno == EINVAL &&
             st.st_mode == (mode_t)0xaaaaaaaa);
}
mkdir -p rootfs
riscv64-linux-gnu-gcc -static -O2 probe.c -o probe.elf
touch rootfs/probe

Run it with the current Qiling dev checkout:

from qiling import Qiling

ql = Qiling(["./probe.elf"], "./rootfs")
ql.run()
Expected behavior

The syscall should return -1 with errno EINVAL before writing the output structure. Qiling v1.4.11 returns success and modifies the buffer.

Additional context

Reproduced with Qiling v1.4.11. The current dev source was checked at commit 23ad4fd369a360ad7992d90cb7577f0241061c2b; that exact commit was not dynamically re-run. Its handler is in stat.py; Linux's supported flag set is described by fstatat(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 を短くまとめたダイジェスト。