qiling icon indicating copy to clipboard operation
qiling copied to clipboard

Hook ioctl in QlFsMappedObject

Open Tim--- opened this issue 2 years ago • 4 comments
trafficstars

Is your feature request related to a problem? Please describe.

Hi,

I am trying to implement a custom QlFsMappedObject with ioctl support. Looking at the class, it seems that I need to override the ioctl method.

https://github.com/qilingframework/qiling/blob/f3e66ec290b8c7a0ee60bc2f2715ddc6e9389216/qiling/os/mapper.py#L44-L45

However, my handler is never called, and the "strace" output shows a -EPERM result when the ioctl syscall is made.

From what I see, the ioctl calls ends up in ql_syscall_ioctl, which only handles a few ioctl commands, and returns -1 (aka -EPERM) if the ioctl is not in the whitelist.

Contrary to other methods like ql_syscall_read, it does not seem to call the handler method.

Describe the solution you'd like

Did I miss something, or is the ioctl not currently implemented ?

Tim--- avatar Dec 02 '22 20:12 Tim---

@Tim--- Did you ever find a fix for this?

psparc82 avatar Feb 27 '24 15:02 psparc82

Well, it's been a while, so I don't remember what I did. But the code has barely changed since then. Apparently, the hook is only called for specific network interface ioctls here:

https://github.com/qilingframework/qiling/blob/f3e66ec290b8c7a0ee60bc2f2715ddc6e9389216/qiling/os/posix/syscall/ioctl.py#L94

I guess you have to modify the code of ql_syscall_ioctl if you want it to call your hook.

Tim--- avatar Feb 27 '24 20:02 Tim---

Hi there, Qiling is flexible enough to let you add your own customized handling. Here you could hook ioctl on exit to let your custom handler review the given parameters and take action for a certain set of values.

elicn avatar Feb 28 '24 11:02 elicn

@Tim--- , @elicn Thanks for the tips. I'll give them a go

psparc82 avatar Feb 28 '24 16:02 psparc82