Skip to content

ql_syscall_shmat is dummy implementation and sometimes returns 0 address #1331

@SRSG

Description

@SRSG

Is your feature request related to a problem? Please describe.
When I simulated the Tenda /bin/webs program, I found that while qiling has successfully implemented shmget, shmat was just dummy implementation.This has been written as a comment at line 246,https://github.com/qilingframework/qiling/blob/master/qiling/os/posix/syscall/mman.py.

During the simulation process, at first ,I got an error "syscall ql_syscall_ipc number = 0x1015(4117) not implemented".Before long I wrote my_syscall_ipc(code as below and only part of real syscall_ipc) to solve it.

def my_syscall_ipc(ql:Qiling, call: int, first: int, second: int, third: int, ptr: int, fifth: int):
    version = call >> 16
    call &= 0xffff
    if call == 23:
        return ql_syscall_shmget(ql, first, second, third)
    elif call == 21:
        if version != 1:
            ret = ql_syscall_shmat(ql, first, ptr, second)
            return ret
        elif version == 1:
            return -EINVAL
    else:
        return -ENOSYS

This syscall_ipc will call another 2 syscalls--shmget and shmat.Then an new error occured.shmat returned address 0 which cannot be used.Possible error part of qiling_syscall_shmat are as below:

 if shmaddr == 0:
        addr = ql.mem.map_anywhere(size)
else:
        addr = ql.mem.map(shmaddr, size, info="[shm]")
return addr

When the second argument shmaddr is 0,ql.mem.map_anywhere will return 0 address.

Describe the solution you'd like
Generally, most programs might check return value like if(ret) report error;else rigth step.So does qiling plan to correctly implement shmat or check why it return 0?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions