加入收藏 | 设为首页 | 会员中心 | 我要投稿 51站长网 (https://www.51zhanzhang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
站内搜索:
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Linux对ptrace TRACEME调用的影响

发布时间:2020-12-31 21:24:31 所属栏目:Linux 来源:网络整理
导读:我有以下代码.它只是调用ptrace(PTRACE_TRACEME)然后进入无限循环. 我有两个问题. 1. after executing this binary,I can't attach gdb even if I am root.2. with ptrace(PTRACE_TRACEME),I can't terminate the process with Ctrl-C (SIGINT). it simply s

我有以下代码.它只是调用ptrace(PTRACE_TRACEME)然后进入无限循环.
我有两个问题.

1. after executing this binary,I can't attach gdb even if I am root.

2. with ptrace(PTRACE_TRACEME),I can't terminate the process with Ctrl-C (SIGINT). it simply stops.

能有人解释我的原因吗?
先感谢您.
PS.我知道大多数调试器会分叉子,并在’execve()之前调用ptrace(PTRACE_TRACEME)’.没必要提醒我这个.

#include <sys/ptrace.h>
#include <sys/reg.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

int main(int argc,char **argv) {

    printf("my pid : %dn",getpid());  
    ptrace(PTRACE_TRACEME);


    while(1){
        printf("euid : %dn",geteuid());
        sleep(2);
    }
    return 0;
}

解决方法

after executing this binary,I can’t attach gdb even if I am root.

来自man ptrace:

ERRORS

EPERM The specified process cannot be traced. This could be
because the parent has insufficient privileges (the required
capability is CAP_SYS_PTRACE); non-root processes cannot trace
processes that they cannot send signals to or those running
set-user-ID/set- group-ID programs,for obvious reasons.
Alternatively,the process may already be being traced,or be init(8) (PID 1).

with ptrace(PTRACE_TRACEME),I can’t terminate the process with Ctrl-C (SIGINT). it simply stops.

来自man ptrace:

DESCRIPTION

While being traced,the child will stop each time a signal is
delivered,even if the signal is being ignored. (The exception is SIGKILL,which has its usual effect.) The parent will be notified at its next wait(2) and may inspect and modify the child process while it is stopped. The parent then causes the child to continue,optionally ignoring the delivered signal (or even delivering a different signal instead).

(编辑:ASP站长)

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

    相关内容
    未处理完善
      无相关信息
    未处理完善