A Linux System call fuzz tester.
|What is it?.|
The basic idea is fairly simple. As 'fuzz testing' suggests, we call syscalls at random, with random arguments.
Not an original idea, and one that has been done many times before on Linux, and on other operating systems.
Where Trinity differs is that the arguments it passes are not purely random.
We found some bugs in the past by just passing random values, but once the *really* dumb bugs were found,
these dumb fuzzers would just run and run. The problem was if a syscall took for example a file descriptor
as an argument, one of the first things it would try to do was validate that fd. Being garbage, the kernel would just
reject it as -EINVAL of course. So on startup, Trinity creates a list of file descriptors, by opening pipes, scanning sysfs, procfs, /dev,
and creates a bunch of sockets using random network protocols. Then when a syscall needs an fd, it gets passed
one of these at random.
File descriptors aren't the only thing Trinity knows about. Every syscall has its arguments annotated,
and where possible it tries to provide something at least semi-sensible. "Length" arguments for example get
passed one of a whole bunch of potentially interesting values.
Trinity also shares those file descriptors between multiple processes, which causes havoc sometimes.
If a child process successfully creates an mmap, the pointer is stored, and fed to subsequent syscalls, sometimes with hilarious results.
Trinity supports Alpha, Aarch64, ARM, i386, IA-64, MIPS, PowerPC-32, PowerPC-64, S390, S390x, SPARC-64, x86-64.
Adding support for additional architectures is a small amount of work mostly involving just defining the order of the syscall table.
See Documentation/HACKING for details.
|How do I use it?.|
If you run Trinity without any arguments, it will scan for fd's as mentioned above, then
create a number of child processes (depending on how many processors you have). These child processes are where
the 'call the syscall' happens. It's done in child processes so that if a syscall causes a segfault, trinity will respawn
a new thread to take its place. Likewise, if a syscall hangs for more than a few seconds, it will get killed by a
I recommend against tarball as root right now, although there is an experimental mode which drops privileges.
I recommend not running it on machines containing data you care about.
It's entirely plausible that trinity could start calling unlink() on files it randomly finds.
You might also want to make sure that there are no nfs or similar filesystems mounted for the same reason.
With that warning out of the way: Trinity has a neat feature called 'victim files'. You can point at a directory with -V and it will use anything
it finds in there as potential sources when it needs a file descriptor. If this is somewhere on NFS for example, this will cause a bunch of
filesystem related syscalls over NFS to occur, which might shake out NFS related bugs.
There's a more extensive README in the source tarball which details all the extra parameters.
Also recommended reading, are the examples in scripts/ which should give some ideas.
|Known problems ?|
- There are almost always new kernel bugs being triggered by trinity.
I used to maintain a list of the bugs found/fixed, but it got to be too much work to keep track of.
- Sometimes, trinity causes the oom-killer to trigger. As long as the oom-killer picks the right process (ie, one of the trinity children, and not dbus, or NetworkManager etc)
then this is working as designed.
- There's a fair amount of "noise" printk's in the kernel that Trinity triggers.
I keep a set of patches to remove the most common ones in git. It should always apply to Linus' latest tree. For older kernels, you may have to fix up some parts.
- If you do find and report a new kernel bug, please Cc me, and mention that you found it with Trinity.
- Latest release is v1.7, released on October 28th 2016.
- The git tree for trinity lives on github. (Please don't send me github pull requests, send email instead).
- snapshot tarballs are created every hour.
|Major changes in git since the last (1.6) tarball release.|
- Generic object cache implementation
- Converted mmap, and all fd generators to use objcache.
- Now tracks (and garbage collects where necessary) child created fd's etc.
- When creating an fd, we sometimes also now create an mmap'd variant for some fd types.
- New syscalls: membarrier, mlock2, copy_file_range, pwritev2, preadv2, bpf, pkey_mprotect, pkey alloc/free.
- Various new flags supported (MADV_FREE, MCL_ONFAULT, yadayada)
- No longer passes bogus addresses to syscalls which result in crashing the child. (as a result, children run a lot longer)
- Watchdog code rewritten to no longer need to run in separate process.
- Improvements to PF_ALG and PF_NETLINK
- Where an ipv address is needed, now uses localhost more often.
- Network protocols now have a per-proto "generate packet" function (not really used yet)
- Add a lot of missing setsockopt values.
- Rewrote socket generation to only generate singletons of each socket type per proto.
- Better futex() coverage. (Davidlohr Bueso)
- Removed tracking of previous syscall each child did.
- Remove long-standing rare bug that would occasionally kill -9 -1, taking down the whole session.
- Assorted improvements to random number generation/seeding.
- Improved debugging of 'stuck' child processes.
- Processes stuck in D state no longer get killed too soon.
- Simplified locking primitives.
- Many enhancements to the 'fault a page' routines. Lots of corner-case segfaults fixed.
- Improvements to numerous syscalls to fail less often.
- Randomize the order in which file descriptor types get initialized.
- Improve perf event fd generator to fail more gracefully.
- Some slight improvements to ioctl fuzzing.
- Initial work to make things run in Windows 10 'LXcore'.
- Framework to support different child types. (Not used much yet)
- Ability to run some child processes as root for known-safe root operations. (When started as root, privs are now dropped later)
- No longer creates 10MB anon mappings. They just increased the likelyhoods of triggering the OOM killer.
- No longer creates 4MB anon mappings because !PAE 32bit x86 isn't interesting.
- Now only creates 1GB mappings if enough memory is available.
- The BPF generator can now generate eBPF instructions.
- Support all the various BPF map types.
- Stores the results of which fds worked with which syscalls.
There is a mailing list for trinity hosted at vger.kernel.org.
To subscribe, send a mail with "subscribe trinity" in the body to [email protected]
If you get oopses, send them to [email protected] with the relevant maintainer Cc'd.
(I'd appreciate a Cc too <davej atsign codemonkey.org.uk>, and please mention that you used Trinity to trigger it).
Your donations will go directly towards buying and running new hardware to run continuous testing.|
back to Dave Jones home page..