Coder Social home page Coder Social logo

cargo test finally timed out about proot-rs HOT 4 CLOSED

proot-me avatar proot-me commented on July 29, 2024 1
cargo test finally timed out

from proot-rs.

Comments (4)

imlk0 avatar imlk0 commented on July 29, 2024 1

The timeout is caused by this test case:

fn test_push_regs_void_sysnum_sleep_test() {
let mut sleep_exit = false;
fork_test(
"/",
// expecting a normal execution
0,
// parent
|tracee, _| {
if tracee.regs.get_sys_num(Current) == NANOSLEEP {
// NANOSLEEP enter stage
tracee.regs.set_restore_original_regs(false);
tracee.regs.save_current_regs(Original);
// we cancel the sleep call by voiding it
tracee
.regs
.cancel_syscall("cancel sleep for push regs test");
tracee.regs.push_regs().expect("pushing regs");
// the new syscall will be nanosleep's exit (with a sys num equal to 0)
sleep_exit = true;
} else if sleep_exit {
// NANOSLEEP exit stage
tracee.regs.set_restore_original_regs(true);
tracee.regs.set(SysResult, 0, "simulate successful sleep");
tracee.regs.push_regs().expect("pushing regs");
return true;
}
false
},
// child
|| {
// calling the sleep function, which should call the NANOSLEEP syscall
execvp(
&CString::new("sleep").unwrap(),
&[CString::new(".").unwrap(), CString::new("9999").unwrap()],
)
.expect("failed execvp sleep");
},
);
}

It can be reproduced by:

cargo test -- --nocapture register::regs::tests::test_push_regs_void_sysnum_sleep_test

from proot-rs.

imlk0 avatar imlk0 commented on July 29, 2024 1

fixed in #14

from proot-rs.

imlk0 avatar imlk0 commented on July 29, 2024

It seems that /bin/sleep uses syscall CLOCK_NANOSLEEP

image
image

while the code capture syscall NANOSLEEP only:

if tracee.regs.get_sys_num(Current) == NANOSLEEP {

Therefore, the process will not exit until 9999 seconds.

from proot-rs.

imlk0 avatar imlk0 commented on July 29, 2024

Another issue is that cancel_syscall() is implemented by set SysNum to VOID

/// Little utility method to quickly void the syscall number.
#[inline]
pub fn cancel_syscall(&mut self, justification: &'static str) {
self.set(SysNum, VOID, justification);
}

while the VOID is defined as 0

const VOID: Word = 0;

which is exactly is the system call number of READ system call in x86_64 linux:

image

It seems that there is no way to cancel a syscall using ptrace.
Another way is to use an unused system call number(e.g. u64::MAX). In this case, the system call will fail.

from proot-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.