@@ -212,34 +212,19 @@ static int not_supported(const char *function_name) {
212212 _exit (1 );
213213 return -1 ;
214214}
215- static pid_t ppid = 0 ;
216- // 在进程初始化时保存 PID
217- __attribute__((constructor )) static void init_sandbox () {
218- ppid = getpid ();
219- }
220215#define RESOLVE_REAL (func ) \
221216 static typeof(func) *real_##func = NULL; \
222217 if (!real_##func) { \
223218 real_##func = dlsym(RTLD_NEXT, #func); \
224219 }
225220int execv (const char * path , char * const argv []) {
226221 RESOLVE_REAL (execv );
227- // fprintf(stdout, "execv path: %s ppid=%d pid=%d\n", path, sandbox_pid, getpid());
228- if (!allow_create_subprocess ()) {
229- // 只允许创建python进程,但不允许python进程替换(用os.execvp里又启动另一个python进程)
230- if (strstr (path , "bin/python" ) == NULL || getpid () == ppid ) {
231- return deny ();
232- }
233- }
222+ if (!allow_create_subprocess ()) return deny ();
234223 return real_execv (path , argv );
235224}
236225int __execv (const char * path , char * const argv []) {
237226 RESOLVE_REAL (__execv );
238- if (!allow_create_subprocess ()) {
239- if (strstr (path , "bin/python" ) == NULL || getpid () == ppid ) {
240- return deny ();
241- }
242- }
227+ if (!allow_create_subprocess ()) return deny ();
243228 return real___execv (path , argv );
244229}
245230int execve (const char * filename , char * const argv [], char * const envp []) {
@@ -259,16 +244,24 @@ int execveat(int dirfd, const char *pathname,
259244 return real_execveat (dirfd , pathname , argv , envp , flags );
260245}
261246int execvpe (const char * file , char * const argv [], char * const envp []) {
262- return not_supported ("execvpe" );
247+ RESOLVE_REAL (execvpe );
248+ if (!allow_create_subprocess ()) return deny ();
249+ return real_execvpe (file , argv , envp );
263250}
264251int __execvpe (const char * file , char * const argv [], char * const envp []) {
265- return not_supported ("__execvpe" );
252+ RESOLVE_REAL (__execvpe );
253+ if (!allow_create_subprocess ()) return deny ();
254+ return real___execvpe (file , argv , envp );
266255}
267256int execvp (const char * file , char * const argv []) {
268- return not_supported ("execvp" );
257+ RESOLVE_REAL (execvp );
258+ if (!allow_create_subprocess ()) return deny ();
259+ return real_execvp (file , argv );
269260}
270261int __execvp (const char * file , char * const argv []) {
271- return not_supported ("__execvp" );
262+ RESOLVE_REAL (__execvp );
263+ if (!allow_create_subprocess ()) return deny ();
264+ return real___execvp (file , argv );
272265}
273266int execl (const char * path , const char * arg , ...) {
274267 return not_supported ("execl" );
0 commit comments