qiling icon indicating copy to clipboard operation
qiling copied to clipboard

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

Open klemmm opened this issue 1 year ago • 0 comments

*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

klemmm avatar Sep 13 '23 14:09 klemmm