https://github.com/imz/randomize_fd
LD_PRELOAD to randomize the fd returned by open or socket
https://github.com/imz/randomize_fd
Last synced: 3 months ago
JSON representation
LD_PRELOAD to randomize the fd returned by open or socket
- Host: GitHub
- URL: https://github.com/imz/randomize_fd
- Owner: imz
- License: lgpl-3.0
- Created: 2018-03-12T17:58:26.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-15T16:04:16.000Z (about 7 years ago)
- Last Synced: 2025-01-24T15:42:08.217Z (4 months ago)
- Language: C
- Homepage: http://git.altlinux.org/people/imz/packages/randomize_fd.git
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
Sometimes (to reproduce a bug) we want to force the use of different
file descriptors in a sequence of `open` or `socket` followed by
`close`, so that:1. the new fd is different from the previous one,
2. and the previous one doesn't look like a valid descriptor anymore.(Due to 2, `strace -e inject=close:retval=0` is not a solution; though
it is a quick solution for 1 until we run out of the available number
of fds.)Here, we solve this problem by providing wrappers around `open` and
`socket` to be LD_PRELOADed.Example (normal behavior; the same descriptor `3` is re-used):
$ strace -e trace=open,read -y -f cat /etc/altlinux-release /etc/redhat-release 2>&1 | tail -9
open("/etc/altlinux-release", O_RDONLY) = 3
read(3, "Simply Linux 7.0.5 (Dory)\n", 131072) = 27
Simply Linux 7.0.5 (Dory)
read(3, "", 131072) = 0
open("/etc/redhat-release", O_RDONLY) = 3
read(3, "Simply Linux 7.0.5 (Dory)\n", 131072) = 27
Simply Linux 7.0.5 (Dory)
read(3, "", 131072) = 0
+++ exited with 0 +++Example (with our intervention, different descriptors are used):
$ strace -e trace=open,read -y -f -E LD_PRELOAD=./randomize_fd_open.so cat /etc/altlinux-release /etc/redhat-release 2>&1 | tail -9
open("/etc/altlinux-release", O_RDONLY) = 3
read(9, "Simply Linux 7.0.5 (Dory)\n", 131072) = 27
Simply Linux 7.0.5 (Dory)
read(9, "", 131072) = 0
open("/etc/redhat-release", O_RDONLY) = 3
read(15, "Simply Linux 7.0.5 (Dory)\n", 131072) = 27
Simply Linux 7.0.5 (Dory)
read(15, "", 131072) = 0
+++ exited with 0 +++## URL
*
*