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

gevent.exceptions.LoopExit exception #1402

Open
jhtshr opened this issue Oct 31, 2023 · 1 comment
Open

gevent.exceptions.LoopExit exception #1402

jhtshr opened this issue Oct 31, 2023 · 1 comment

Comments

@jhtshr
Copy link

jhtshr commented Oct 31, 2023

*Describe the bug
When simulating the /bin/sh process, after the shell starts, the pwd command displays normally, but when the ls or id command is entered, it raises the gevent.exceptions.LoopExit exception.

Sample Code

from qiling import *
from qiling.const import QL_VERBOSE

def custom_geteuid32(ql, *args, **kwargs):
    return 0  

def my_sandbox(path, rootfs):
    # setup Qiling engine
    ql = Qiling(path, rootfs,verbose=QL_VERBOSE.DEBUG,console=True,multithread=True) # QL_VERBOSE.OFF QL_VERBOSE.DEBUG
    ql.os.set_syscall("geteuid32", custom_geteuid32) 
    ql.run()

if __name__ == "__main__":
    my_sandbox(["./rootfs/bin/sh"], "./rootfs/")

Expected behavior
all command in shell displays normally

Screenshots

[+] [Thread 2000]       Received interrupt: 0x2
[+] [Thread 294468]     Received interrupt: 0x2
[+] [Thread 294468]     0x901ca24c: futex(uaddr = 0x9021f034, op = 0x0, val = 0x2, timeout = 0x0, uaddr2 = 0x1, val3 = 0x9021f034) = 0x0
[+] [Thread 294468]     Suspended at 0x901ca24c
[+] [Thread 294468]     Saved context. c13_c0_3=0x902224a0
[+] [Thread 294468]     Call sched_cb: <function QlLinuxFutexManagement.futex_wait.<locals>._sched_wait_event at 0x7f800df500d0>
[+] [Thread 294468]     Wait for notifications.
Traceback (most recent call last):
  File "qiling_vigor.py", line 15, in <module>
    my_sandbox(["./rootfs/bin/sh"], "./rootfs/")
  File "qiling_vigor.py", line 12, in my_sandbox
    ql.run()
  File "/root/.local/lib/python3.8/site-packages/qiling/core.py", line 597, in run
    self.os.run()
  File "/root/.local/lib/python3.8/site-packages/qiling/os/linux/linux.py", line 164, in run
    thread_management.run()
  File "/root/.local/lib/python3.8/site-packages/qiling/os/linux/thread.py", line 618, in run
    gevent.joinall([self.main_thread], raise_error=True)
  File "src/gevent/greenlet.py", line 1065, in gevent._gevent_cgreenlet.joinall
  File "src/gevent/greenlet.py", line 1078, in gevent._gevent_cgreenlet.joinall
  File "src/gevent/_hub_primitives.py", line 185, in gevent._gevent_c_hub_primitives._WaitIterator.__next__
  File "src/gevent/_hub_primitives.py", line 176, in gevent._gevent_c_hub_primitives._WaitIterator.__next__
  File "src/gevent/_waiter.py", line 195, in gevent._gevent_c_waiter.MultipleWaiter.get
  File "src/gevent/_waiter.py", line 154, in gevent._gevent_c_waiter.Waiter.get
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch
gevent.exceptions.LoopExit: This operation would block forever
        Hub: <Hub '' at 0x7f800e083810 epoll default pending=0 ref=0 fileno=3 thread_ident=0x7f805236a740>
        Handles:
[]
[+] [Thread 2000]       0x9018b1fc: wait4(pid = 0xffffffff, wstatus = 0x7ff3ca14, options = 0x0, rusage = 0x0) = 0x47e44
[+] [Thread 2000]       Received interrupt: 0x2
[+] [Thread 2000]       0x901b5b1c: ioctl(fd = 0x0, cmd = 0x5401, arg = 0x7ff3ba0c) = 0x0
[+] [Thread 2000]       Received interrupt: 0x2

Additional context

└─# python3 qiling_v.py


BusyBox v1.4.2 (2022-04-13 20:52:17 CST) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

./rootfs/bin/sh: can't access tty; job control turned off
/ # pwd

/
/ # ls
ls
Traceback (most recent call last):
  File "qiling_vigor.py", line 15, in <module>
    my_sandbox(["./rootfs/bin/sh"], "./rootfs/")
  File "qiling_vigor.py", line 12, in my_sandbox
    ql.run()
  File "/root/.local/lib/python3.8/site-packages/qiling/core.py", line 597, in run
    self.os.run()
  File "/root/.local/lib/python3.8/site-packages/qiling/os/linux/linux.py", line 164, in run
    thread_management.run()
  File "/root/.local/lib/python3.8/site-packages/qiling/os/linux/thread.py", line 618, in run
    gevent.joinall([self.main_thread], raise_error=True)
  File "src/gevent/greenlet.py", line 1065, in gevent._gevent_cgreenlet.joinall
  File "src/gevent/greenlet.py", line 1078, in gevent._gevent_cgreenlet.joinall
  File "src/gevent/_hub_primitives.py", line 185, in gevent._gevent_c_hub_primitives._WaitIterator.__next__
  File "src/gevent/_hub_primitives.py", line 176, in gevent._gevent_c_hub_primitives._WaitIterator.__next__
  File "src/gevent/_waiter.py", line 195, in gevent._gevent_c_waiter.MultipleWaiter.get
  File "src/gevent/_waiter.py", line 154, in gevent._gevent_c_waiter.Waiter.get
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch
gevent.exceptions.LoopExit: This operation would block forever
        Hub: <Hub '' at 0x7f735e5a4680 epoll default pending=0 ref=0 fileno=3 thread_ident=0x7f73a289b740>
        Handles:
[]
/ # 
@iMoD1998
Copy link

iMoD1998 commented Mar 6, 2024

Did you ever find a fix? I'm getting this same issue.

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

2 participants