Consistently Making Wrong Decisions Whilst Writing Recreational C
amodernist.com
amodernist.com
-e fault=clone:error=ENOMEM:when=1+2
First, modern glibc doesn't use the `fork` syscall directly; it uses clone() instead, so you have to fault clone to see anything happen on a glibc-based system. Second, I botched the syntax, oops!For practical use, you probably want something like this:
strace -e fault=clone:error=ENOMEM:when=2+2 -e fault=write:error=EFAULT:when=3+3 -c -o /dev/null bash
This faults both clone and write at different rates (try it, the results are sort of funny), sets strace to only count events (reducing its overhead), and then suppresses the count printout at the end. Might be fun to use as a prank login shell if you want someone to think their machine is broken :)This approach would also give students insight into testing strategies like mocking, plus it would work on more operating systems.
[Edit: Not to disparage this project. It seems like it would have lots of uses, and it was probably a lot of fun to develop.]
(I built a similar tool[1] a few years ago, but at the syscall layer to ensure that statically linked binaries could also have faults injected into them reliably. My colleagues used it to find a handful of bugs on prominent Go codebases.)
[1]: https://blog.trailofbits.com/2019/01/17/how-to-write-a-rootk...
I don't understand the desire not to link to pthread, it's about as ubiquitous as a library can be.
I doubt it's really a problem in this application... but naive userspace spinlocks are absolutely horrendous, see NOTES here: https://man.archlinux.org/man/pthread_spin_init.3.en
User-space spin locks [...] are, by definition, prone to priority inversion and unbounded spin times. A programmer using spin locks must be exceptionally careful not only in the code, but also in terms of system configuration, thread placement, and priority assignment.Logging nicely was also an issue. I decided to avoid linking to any other symbols and implemented it with inline Assembly for x86/64 and aarch64: https://github.com/ashvardanian/LibSee/blob/fdae92e71c449c91...
The configure script even checks the existence of several system headers this way, so if your C compiler don't support # markers in -E output, you get missing includes everywhere.
[0] https://github.com/Perl/perl5/blob/blead/ext/Errno/Errno_pm....
icterid$ /usr/lib/x86_64-linux-gnu/libc.so.6
GNU C Library (Debian GLIBC 2.36-9+deb12u7) stable release version 2.36.
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 12.2.0.
libc ABIs: UNIQUE IFUNC ABSOLUTE
Minimum supported kernel: 3.2.0
For bug reporting instructions, please see:
<http://www.debian.org/Bugs/>.It's spelled "/lib/ld-linux-aarch64.so.1" on my nearest Linux box but is still executable today.
If /usr/bin isn't a symlink to /bin or vice-versa, then you should have tools there to do the same thing.
If you somehow still have a working C compiler (or access to another language that can do syscalls or has C bindings), it's pretty easy to write a wrapper for the syscall.
If there's an rsync daemon, nfs share, etc. running, you can copy over a static busybox and fix the system that way.
If you're allowed to take the system down, it's really easy - just boot up a live image and change the permissions.
Having held a couple interviews like this, if you suggest taking the system down, I'll tell you that would work -- now tell me another way to do it.
It's still a plus that you suggested it, even if it isn't enough of an answer on its own.
Imagine having in front of you a webpage that doesn't work the way you want. You use View Source in your browser, find the URL of some component written in JS that probably contains the offending logic, navigate to that URL, and the source code for that library unfolds on your screen and is free to do whatever it wants to best present itself to you for your understanding. This could include doing syntax highlighting for you (rather than the default black-on-white text that most browsers use when showing you a JS file), putting helper widgets on the screen (e.g. object/configuration inspectors), other on-screen editor components e.g. for any DSLs used in the file, base64-encoded data, etc.
Or imagine a file that knows that it was compiled from TypeScript and knows where the TypeScript source that it was compiled from lives. When you open the URL for the compiled form in your browser, when it loads it dynamically fetches the original .ts sources from elsewhere on the server and then puts that on the screen—maybe even going so far as to put it inside an editor that forms a TypeScript playground.
You can probably use an LLM for this.
I find LLMs very helpful when the task is annoyingly underdefined / understructured, but the result I want is easy to eyeball-audit.
This seems like one of those. Boiling down manpages to a consistent structure which a program can consume is going to involve a lot of special-casing a script, because they aren't written to be scraped like that.
But opening the result in one window, then loading the manpages one at a time in the other, and sanity-checking the contents, is less effort than manually copy-pasting everything and getting it into a consistent data format by hand.
Feeding the result of an LLM-grep sight-unseen into another program is an insane thing to do, of course. But using it like the above could save a lot of time.
...why though? I mean, it's position-independent, just load and relocate it wherever? Or does "PIE" mean something different in Linux from what it does in Windows?
An example of a problem provided in a different bug: https://sourceware.org/bugzilla/show_bug.cgi?id=11754#c15
But I don't really understand what's going on in that example.
Aside, it only took 9 years for that patch to get conclusively rejected.