Note that there are some explanatory texts on larger screens.

plurals
  1. POCancel a system call with ptrace()
    primarykey
    data
    text
    <p>For some security purpose, I use ptrace to get the syscall number, and if it's a dangerous call (like 10 for unlink), I want to cancel this syscall.</p> <p>Here's the source code for the test program <code>del.c</code>. Compile with <code>gcc -o del del.c</code>.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main() { remove("/root/abc.out"); return 0; } </code></pre> <p>Here's the security manager source code <code>test.c</code>. Compile with <code>gcc -o test test.c</code>.</p> <pre><code>#include &lt;signal.h&gt; #include &lt;syscall.h&gt; #include &lt;sys/ptrace.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/wait.h&gt; #include &lt;unistd.h&gt; #include &lt;errno.h&gt; #include &lt;sys/user.h&gt; #include &lt;sys/reg.h&gt; #include &lt;sys/syscall.h&gt; int main() { int i; pid_t child; int status; long orig_eax; child = fork(); if(child == 0) { ptrace(PTRACE_TRACEME, 0, NULL, NULL); execl("/root/del", "del", NULL); } else { i = 0; while(1){ wait(&amp;status); if (WIFEXITED(status) || WIFSIGNALED(status) )break; orig_eax = ptrace(PTRACE_PEEKUSER, child, 4 * ORIG_EAX, NULL); if (orig_eax == 10){ fprintf(stderr, "Got it\n"); kill(child, SIGKILL); } printf("%d time," "system call %ld\n", i++, orig_eax); ptrace(PTRACE_SYSCALL, child, NULL, NULL); } } return 0; } </code></pre> <p>Create the <code>abc.out</code> file, then run the test program:</p> <pre class="lang-sh prettyprint-override"><code>cd /root touch abc.out ./test </code></pre> <p>The file <code>/root/abc.out</code> should still exist.</p> <p>How do I implement this requirement?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload