Haha, I don't know how folks found this, but I actually did make it for a real-world use case. While doing large-scale builds of debian packages [1], occasionally I'd have parts of the build process hang (usually some test that I didn't care about). I didn't want the whole build to fail, so I needed some way to kill the process but have it return 0 so that make and friends wouldn't think anything was amiss.
> Note: glibc provides no wrapper for exit_group(), necessitating the use of syscall(2).
Hmm, but elsewhere I find:
> In glibc up to version 2.3, the _exit() wrapper function invoked the kernel system call of the same name. Since glibc 2.3, the wrapper function invokes exit_group(2), in order to terminate all of the threads in a process.
It's not jumping to that address, it's injecting the exit syscall right under the instruction pointer.
If you wanted to modify the register, you'd do `set $rip = 0x050f` without the `{short}`
They're not changing the rip register at all. They're setting the contents of the memory location pointed to by the rip register to 0x050f. The equivalent of "set {x}y = z" in C would be "*(x *)y = z;".
Accidental discharge of gun is a frequent cause of death in the wild, wild united states of guns. Why not also falling out of window, tripping in kitchen with knife, or eating poorly cooked meat, comrade?
Also, credit where credit is due -- the original idea was suggested to me by Kyle Huey: https://twitter.com/moyix/status/1484342467205816325
[1] https://moyix.blogspot.com/2022/02/on-building-30k-debian-pa...
I found it yesterday on Ukrainian Linux users forum[0], and decided to re-post it on HN ;)
[0] https://linux.org.ua/index.php?topic=11868
http://main.lv/notes/syscalls.md
https://man7.org/linux/man-pages/man2/exit_group.2.html
> Note: glibc provides no wrapper for exit_group(), necessitating the use of syscall(2).
Hmm, but elsewhere I find:
> In glibc up to version 2.3, the _exit() wrapper function invoked the kernel system call of the same name. Since glibc 2.3, the wrapper function invokes exit_group(2), in order to terminate all of the threads in a process.
https://www.man7.org/linux/man-pages/man2/_exit.2.html
It's not jumping to that address, it's injecting the exit syscall right under the instruction pointer. If you wanted to modify the register, you'd do `set $rip = 0x050f` without the `{short}`
Deleted Comment
(I love the cell block tango)