[RISC-V/Linux] newfstatat ignores unsupported flags

未关闭
#1,684 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
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 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

qilingframework/qiling 的其他 Issue

查看 qilingframework/qiling 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。