Created
February 21, 2023 15:14
-
-
Save gwisp2/aec6b92922d6e2252263e95ce507bc98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <unistd.h> | |
| #include <sys/syscall.h> | |
| #include <errno.h> | |
| #include <string.h> | |
| int main(int argc, char *argv[]) { | |
| if (argc < 2) { | |
| printf("No path to executable to start provided\n"); | |
| return 255; | |
| } | |
| if (syscall(SYS_close_range, 3U, ~0U, 0U)) { | |
| printf("Failed to close file descriptors: %s\n", strerror(errno)); | |
| return 255; | |
| } | |
| if (execv(argv[1], &argv[1])) { | |
| printf("Exec %s failed: %s\n", argv[1], strerror(errno)); | |
| return 255; | |
| } | |
| return 0; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Linux kernel 5.9 or newer is required because close_range syscall is used. However, the same idea could be rewritten without using the newest kernel features.
How to build: