[RISC-V/Linux] getrandom with a zero-length buffer triggers an assertion

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

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

評価

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

調査の方向性

バグは qiling/os/posix/syscall/random.py の ql_syscall_getrandom にあります。この関数は、サイズが正であることをアサートするマップ済みメモリ書き込みヘルパーに、サイズ 0 を渡しています。まずこの関数と、そこから呼び出されるヘルパーを読んでください。その後、buflen=0 でサンプルプローブを実行し、AssertionError を再現します。ゼロ長の getrandom がバッファに触れずに 0 を返し、正の長さの場合は引き続き 8 を返せば完了です。

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

説明

Describe the bug

An RV64 Linux guest that calls getrandom() with a valid mapped buffer and buflen=0 triggers an AssertionError in Qiling. Linux defines a zero-length request as a successful call returning zero.

Sample Code

#define _GNU_SOURCE
#include <errno.h>
#include <stdio.h>
#include <sys/syscall.h>
#include <unistd.h>

int main(void)
{
    unsigned char buf[8];
    long first = syscall(SYS_getrandom, buf, sizeof(buf), 0);
    printf("positive=%zd\n", first);
    fflush(stdout);
    errno = 0;
    long zero = syscall(SYS_getrandom, buf, 0, 0);
    printf("zero=%zd errno=%d\n", zero, errno);
    return 0;
}
riscv64-linux-gnu-gcc -static -O2 -Wall -Wextra probe.c -o probe.elf
mkdir -p rootfs
python3 - <<'PY'
from qiling import Qiling
ql = Qiling(["./probe.elf"], "./rootfs")
ql.run()
PY

Expected behavior

The first call returns 8; the zero-length call returns 0 without accessing the buffer. QEMU-user and native Linux produce {8, 0}. With the current Qiling dev build, the first call prints 8 and the second raises AssertionError.

Additional context

Reproduced on Qiling commit 23ad4fd369a360ad7992d90cb7577f0241061c2b under RV64 Linux. The current ql_syscall_getrandom passes the zero size to the mapped-memory helper, which asserts that the requested size is positive.

主要言語
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 を短くまとめたダイジェスト。