qilingframework / qilingframework/qiling

[ARM 32-bits] Unexpected EOVERFLOW error on stat() library call

Open
#1,381 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
6.1k
Forks
798
Avg merge
1d 1h
Merged PRs (30d)
9

Description

*Describe the bug

When emulating a binary that does a stat() library call, there is always a -1 result with errno set to EOVERFLOW.

The same binary, ran with qemu-arm, exhibit no problem (stat() returns 0)

Sample Code

from qiling import *
binary = r'./rootfs/bin'
rootfs = r'./rootfs/'
ql = Qiling(["./rootfs/myprog"], "./rootfs")
ql.run()

Emulated program:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
int main(void) { 
        struct stat buf;
        if (stat("somefile.txt", &buf) < 0) {
                perror("stat");
        }
} 

Emulated program compiled with:

arm-linux-gnueabi-gcc -static -o myprog myprog.c

Emulated program binary is put in directory "rootfs", along with "somefile.txt"

Expected behavior

stat() returns 0 in emulated program.

Additional context

The stat() library call, in turn, calls the statx() syscall. It seems that the structure for the statx() ( https://github.com/qilingframework/qiling/blob/master/qiling/os/posix/syscall/stat.py#L1361 ) does not correspond to the documentation ( https://man7.org/linux/man-pages/man2/statx.2.html ), this causes a failure in a check in the fstatat libc function (called by stat).

distro version: ubuntu 22.04
ARM libc version: libc6-armel-cross (package 2.35-0ubuntu1cross3)
ARM gcc version: gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)
qiling version: 1.4.6
python version: 3.10.12

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with qiling/os/posix/syscall/stat.py around line 1361 and compare the statx structure mapping with the linked statx documentation. Reproduce the ARM example using the provided sample program and rootfs, then verify that stat() returns 0 without EOVERFLOW after the mapping is corrected.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
operating-systems, reverse-engineering
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.