我正在嘗試通過 ptrace 攔截和阻止系統呼叫。問題發生在系統呼叫結果的回傳程序中。errno 保持為 0,即使在系統呼叫回傳中使用 -EPERM 也是如此。
我試過運行這個例子。結果是一樣的。
$ ./xpledge ./example
fread("/dev/urandom")[1] = 0xb2ac39c4
XPledging...
fopen("/dev/urandom")[2]: Success
fread("/dev/urandom")[1] = 0x2e1bd1c4
這是代碼的一部分:
if (is_syscall_blocked(regs.orig_rax)) {
regs.orig_rax = -1; // set to invalid system call
if (ptrace(PTRACE_SETREGS, pid, 0, ®s) == -1)
FATAL("%s", strerror(errno));
}
/* Run system call and stop on exit */
if (ptrace(PTRACE_SYSCALL, pid, 0, 0) == -1)
FATAL("%s", strerror(errno));
if (waitpid(pid, 0, 0) == -1)
FATAL("%s", strerror(errno));
switch (regs.orig_rax) {
case -1:
if (ptrace(PTRACE_POKEUSER, pid, RAX * 8, -EPERM) == -1)
FATAL("%s", strerror(errno));
break;
}
所以問題是。拒絕系統呼叫時如何正確設定errno?
uj5u.com熱心網友回復:
實際上示例中的代碼看起來不正確。在教程中有一些不一樣的代碼片段。如果您嘗試一下,似乎它提供了正確的輸出
switch (regs.orig_rax) {
case -1:
regs.rax = -E2BIG;
if (ptrace(PTRACE_SETREGS, pid, 0, ®s) == -1)
FATAL("%s", strerror(errno));
break;
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/338696.html
