GCC how to block system calls within a program?

后端 未结 6 1079
别那么骄傲
别那么骄傲 2021-02-10 06:24

Does anyone tell me how to block some specific system calls within a program, please? I am building a system which takes a piece of C source code, compiles it with gcc and runs

6条回答
  •  说谎
    说谎 (楼主)
    2021-02-10 07:06

    You can't.

    Even this program:

    #include 
    
    int main()
    {
        printf("Hello, World\n");
        return 0;
    }
    

    makes at least one system call (to send the string "Hello, World\n" to standard out). System calls are the only way for a program to interact with the outside World. Use the operating system's security model for security.

    Edited for this comment:

    I meant not all system calls but malicious system calls, e.g. execv() could be used to execute a BASH script which wipes out my data on the disk.

    Your operating system already includes mechanisms to stop that sort of thing happening. For instance, in order for a bash script to wipe out your data, the process must already have write access to that data. That means it must have been started by you or root. Your only real option is not to install untrustworthy software.

    By the way, depending on your platform, execv is not necessarily a system call. On Linux, it's a C library wrapper for the real system call (execve).

提交回复
热议问题