Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
klemmm opened this issue Sep 13, 2023 · 0 comments
Open

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

klemmm opened this issue Sep 13, 2023 · 0 comments

Comments

@klemmm
Copy link

klemmm commented Sep 13, 2023

*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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant