From e14f62996aeedad94dcccc236ed3937f97e7b04f Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 18 Sep 2017 20:13:31 -0400 Subject: [PATCH 001/119] update the TODO some. Still needs some cleanup, but this is a braindump of my private TODO that has a mix of old/new stuff. --- Documentation/TODO | 424 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 346 insertions(+), 78 deletions(-) diff --git a/Documentation/TODO b/Documentation/TODO index 9b64e70f9..db0343b63 100644 --- a/Documentation/TODO +++ b/Documentation/TODO @@ -1,3 +1,52 @@ +* Various syscall improvements. + - brk could be smarter about existing brk + - Revisit fuzzing ptrace. + - It's disabled currently because of situations like.. + child a traces child b + child a segfaults + child b never proceeds, and doesn't get untraced. + - semtimedop needs a timeout + - execve close stderr/stdin/stdout and then dup weird fd's + - demux do_futex + - mremap post needs to get rid of global 'map'. Stash something in ->rec ? + - Improve ioctl + - VFS ioctls + - ext ioctls + - XFS ioctls + - 3rd param to ioctl struct for the arg type + - needs filename globbing for some ioctls + - Maybe just make the ioctl's be NEED_ROOT child ops + - audit which syscalls never succeed, and write sanitise routines for them + - sanitise for shmget/shmat/shmctl + - Make the write variants handle all common block/page sizes. + The ARG_LEN code in particular could probably be made better. + +* Further syscall annotation improvements + - Finish annotating syscall return types & error codes. + - Add missing system calls. + + +* UDP logging +- This is pretty rough right now, but kinda works. + : Shortcomings: + - if client crashes, or gets oom killed, server doesn't detect + and sits on packets. flush-on-no-packet-in-a-while ? + - ctrl-c on server should flush queues + - getting a new handshake message should flush queues + - if hasn't flushed in a while, will eventually oom. + + - accumulate packets, and kick threads to dispatch as needed ? + - when we get a child spawn/signal/quit message, clear the queue of old pid first. + - When this is solid enough, can we kill off post-mortem code ? + - Likewise, can we revert all the log-to-disk stuff again, and just run a server on localhost ? + - client perform extended tracking: + - global fd logging. Store a linked-list of every op that happened to an fd, and the pid that did it. + - log child exit reasons, so we can print reason when children just 'exit after n ops' + - destroy context & restart when main exits. There's beginnings of multi-session support in how + the fuzzsession struct was created, but there's no code to manage the possibility of multiple of them. + I forward-planned a little too far here, thinking about a possible future where we have one server, + and multiple clients running simultaneously. + * Flesh out the child ops some more - Add more things that a real program would do. - add all the ops things like fsx do. @@ -10,10 +59,54 @@ - send fd's over unix sockets to other children - open/read all /proc/$$/* files - tuned random syscalls. (open -> read -> close). tree of possibilities. - - Ability to mark some ops as 'NEEDS_ROOT'. - - Move the drop privs code from main to just before we start a new child. + - increment progress in childops + - memcpy between map ptrs + - child type where it picks one syscall and hammers on it with random args + - maybe also hammer on an ->assoc + - mlock patterns. Every other page etc. + - madvise(DONTNEED/WILLNEED) in a loop on a mapping for a while. + - "mmap-pagefault-munmap" loop + - ioctls as child-op type + - mprotect adjacent pages to random prot's, then all the same, to test splitting/merging + - walk backwards + - /dev/shm hugepage fuckery. + - fork(), mess with maps, exit + - fsx stuff + - readdir() + - inode spewer + - create nested dir struct + - create huge number of files in a subdir + - nftw (stat/read/write) + - nftw (stat/mmap/write) + - nftw to delete subtree + - variant: delete as we go + - variant: create inotify/fsnotify watches + "mount, make millions of inodes in cache, then unmount, and everything is sad" + - http://bazaar.launchpad.net/~domas-mituzas/%2Bjunk/uncache/annotate/head%3A/uncache.c + - blast data through a pipe / read from a pipe + - producer/consumer over an ipv[46] socket + - open/access/write/close one file concurrently + - tsearch: http://serverfault.com/questions/183821/rm-on-a-directory-with-millions-of-files + - read a file page at a time, MADV_DONTNEED'ing as we go + - root child-ops + - cgroup shit + - mount something on a testdir + - ionice + - sched features + - vm compaction + - mkfs & mount a ramdisk, cd into it, add to pathname list. + - loopback mount + - cd back to original cwd, unmount a ramdisk + - chroot to a destdir + - create a pidns + - mount a proc,sysfs,tmpfs in a destdir + - unshare(CLONE_NEWPID) - fork then returns 1 in the child ? https://www.exploit-db.com/exploits/36746/ + http://stealth.openwall.net/xSports/clown-newuser.c + - echo 0,1,2 > /sys/kernel/mm/ksm/run + - /proc/sys/vm/drop_cache + -* vm related improvements: +* mm related improvements: - mmapping: - Sometimes generate overlapping addresses/lengths when we have ARG_ADDRESS/ARG_ADDRESS2 pairs - munge lengths when handing out maps. @@ -31,24 +124,77 @@ - /dev/shm mappings - pass memfd's in mmap sanitise - sysv shm handling could be improved. + - map cache a la last-fd cache + - map struct needs a destructor. + id = shmget(IPC_PRIVATE, 3 * PAGE_SIZE, 0); + p = shmat(id, NULL, 0); + shmctl(id, IPC_RMID, NULL); + remap_file_pages(p, 3 * PAGE_SIZE, 0, 7, 0); + + In this case, the destructor is shmdt + - Only allow max of 2-3 huge pages per child + - Check we update map struct ptr when we mremap it + +* Networking improvements. + - More focus on non-ipv4 protocols. + - igmp + - ipv6 / 6to4 + - sctp + - ipip + - tun (vxlan / gre) + - ppp + - pppoe + - tipc + - rds + - nfc + - nft + - iscsi + - for syscalls that take a fd and a sockaddr, look up the triplet and match. + - Flesh out sockaddr/socket gen for all remaining protocols. + - setsockopt coverage is still lacking for some protocols. + - improve netlink fuzzing. + - Make sure we support all the different socket types. + - pass down more realistic looking messages. + - param to specify an ip of a victim machine + - --proto-exclude + - check EAFNOSUPPORT if -P + - split ARG_SOCKET into per proto object caches ? + - have write() check if the fd to be written to is a socket + if so, lookup protocol, and use correct ->genpacket + - in fds/sockets, as well as bind() try connect() random ip's + borrow from https://github.com/borkmann/stuff/blob/master/daytime.c + - accept() only on IPPROTO_IP sockets + - linger off vs 0 linger + - make -P INET:DCCP work + - rewrite socket init to just do < 5 of each known proto type + - Pass FD's over AF_UNIX between children + - more ->socket entries for missing ones? + - store the ports we're listening on in the shm, and use those when we send() + --no-rfc1918, so we only use localhost + - Is the socketcache still useful ? Probably not.. + +* Improve the ->post routine to walk a list of objects that we allocated during a + syscalls ->sanitise in a ->post method. + - On return from the syscall, we don't call the destructor immediately. + We pick a small random number, and do N other syscalls before we do the destruction. + This requires us to create a list of work to be done later, along with a pointer + to any allocated data. + - some ancillary data needs to be destroyed immediately after the syscall + (it's pointless keeping around mangled pathnames for eg). + For this, we just destroy it in ->post + - Right now ->sanitise routines have to pick either a map, or malloc itself and + do the right thing to free it in ->post. By tagging what the allocation type was in + generic-sanitise, we can do multiple types. * munge_process() on child startup - replace fork() with random clone() - run children in different namespaces, personalities. - unshare - do some random fcntls to all fd's on child spawn - -* ioctl improvements - - needs filename globbing for some ioctls - - Sanitise routines for more ioctls - - ext4 - - Maybe just make the ioctl's be NEED_ROOT child ops + - on child startup, setup some cgroup params for that child. * Some debugging enhancements. - Make -D use a separate debug log file - - if we have a large number of children, we use up a lot of fd's for - the log files. Instead of keeping them all open, reopen them as needed. - - mprotect the child struct around write accesses - improve debugf re: http://c-faq.com/varargs/handoff.html - Activate the function tracer before each syscall. Flush before calling. @@ -56,7 +202,6 @@ - change child->syscall / ->previous to be a ringbuffer of syscallrecord structs. - Compare timestamp that taint was noticed at, ignore all later. - log 'unfinished' if state isn't complete. - - is post mortem code generating ESC0m ? - function that takes a void * and outputs what it is (mapping, page_* etc) (searches various lists etc) @@ -83,12 +228,35 @@ - Attach an operation history to each fd for post-mortem. Maybe we need an fd container struct ? - deregister fd providers if init of one fails + - separate fd lists for dirs vs files + - make fd providers take array to fillin & num of fds as params. + - child fd's + - call some fd providers from children after init + - periodically close/reopen existing fds + - random selection of fd providers on startup + - stuck_syscall_info should close the fd + This needs a way to communicate from child -> main. + - mmap more fd types + +Pathname rewrite: +- convert pathnames to objects + - separate pools for dev, sys, proc, testfile etc + - get_random_pathname picks from a random pool +- make get_filename return testfile[n] +- make sure pathnames are read-only +- make handle_arg_address return ptr to pathname +- open() should add to local fd's. +- finish globbing in ignore_files + - add sd[a-z]* hd[a-z]* +- if -EBADF remove the object +- children should nftw and create their own local objects * Pretty-print improvements. - decode fd number -> filename in output - decode addresses when printing them out to print 'page_rand+4' instead of a hex address. - ->decode_argN functions to print decoded flags etc. - decode maps. + - These things are all probably better done in the udp server at this point. * filename related issues. - filename cache. @@ -108,76 +276,23 @@ - use count - create N testfiles for each -V -* Networking improvements. - - More focus on non-ipv4 protocols. - - igmp - - ipv6 / 6to4 - - sctp - - ipip - - tun (vxlan / gre) - - ppp - - pppoe - - tipc - - rds - - nfc - - nft - - iscsi - - Rewrite socket generation. - Organise into (sorted) per-protocol buckets of linked-lists.. - - Search buckets for dupes before adding. - - for syscalls that take a fd and a sockaddr, look up the triplet and match. - - Flesh out sockaddr/socket gen for all remaining protocols. - - setsockopt coverage is still lacking for some protocols. - - improve netlink fuzzing - - specify an ip of a victim machine (Maybe also config file) - - --proto-exclude - - better spread of net protocols on startup - - check EAFNOSUPPORT if -P - - speed up PF_CAN creation - -* Improve the ->post routine to walk a list of objects that we allocated during a - syscalls ->sanitise in a ->post method. - - On return from the syscall, we don't call the destructor immediately. - We pick a small random number, and do N other syscalls before we do the destruction. - This requires us to create a list of work to be done later, along with a pointer - to any allocated data. - - some ancillary data needs to be destroyed immediately after the syscall - (it's pointless keeping around mangled pathnames for eg). - For this, we just destroy it in ->post - - Right now ->sanitise routines have to pick either a map, or malloc itself and - do the right thing to free it in ->post. By tagging what the allocation type was in - generic-sanitise, we can do multiple types. - * Perform some checks on return from syscall - check padding between struct members is zeroed. -* Output errno distribution on exit - * allow for multiple -G's (after there is more than 'vm') - -* audit which syscalls never succeed, and write sanitise routines for them + - multigroups. mmap should be in VFS too + - -G SCHED + - -G IPC * if a read() blocks, blacklist (close?) that fd/filename. - -* Various syscall improvements. - - brk could be smarter about existing brk - - Revisit fuzzing ptrace. - - It's disabled currently because of situations like.. - child a traces child b - child a segfaults - child b never proceeds, and doesn't get untraced. - -* Further syscall annotation improvements - - Finish annotating syscall return types & error codes. + This needs a way to communicate from child -> main. * structured logging. - - To begin with, in parallel with existing text based logging. - Basic premise is that we store records of each syscall in a manner that would allow easier replay of logs. - For eg, if a param is an fd, we store the type (socket/file/etc..) as well as a pathname/socket triplet/whatever to create it. - - Eventually, kill off the text based logging, and replace it with - ./trinity --parselog=mylog.bin + - Take a logdump from the server, and rerun it on the client with --parselog=mylog.bin - Done correctly, this should allow automated bisecting of replays. - Different replay strategies: - replay log in reverse order @@ -193,14 +308,25 @@ * Misc improvements. - implement _lock->queue so waiters get the lock on a FIFO basis. + (Do we have enough contention this matters?) - Add a NEEDS_ROOT flag for syscalls that are expected to fail. (and then if !root, deactivate them on startup) - - --stats - - count segv's. - avoid BORING syscalls. geteuid etc is kinda pointless. (maybe an override param to call them) - unix socket for comms between children/parent. also other apps so we can do stats gathering, debug, config changes etc + - make check_children_progressing() look at se.exec_start field of /proc/1/task/1/sched + (I can't remember the reasoning for this idea, it came from the watchdog days) + - make -V do IS_CHR() etc tests and add to device list if chardev/blockdev + - --no-sync to disable sync,syncfs,fsync,fdatasync + - ioprio tweaking before doing io + - split out sighandler -> sigalarmhandler + - more --stats + - count segv's. + - Output errno distribution on exit + - fastest/slowest syscall (that completed) + - syscalls per second + - segfaults per second * Misc cleanups - Move arch specific syscalls into syscalls/arch/ @@ -210,13 +336,17 @@ - zfree (free & null) - check_errno(EINVAL) (checks if -1, and checks errno, returns bool) + [I forget why this was useful] - set_random_bits() - - fix up -q. trinity -h needs to be more silent - - add a kernel rodata addr to trinity (sys_call_table for eg) + - fix up -q. trinity -h needs to be more silent for non help related text + - split up compat.h + - merge fruncate/truncate + - merge sync/fsync/syncfs + - constructors for objects, like the fd providers + +* add a kernel rodata addr to trinity (sys_call_table for eg) * watch dmesg buffer for interesting kernel messages and halt if necessary. Lockdep for eg. - - Pause on oops. - Sometimes we might want to read trinity state when we trigger a bad event. * Blocked child improvements. - if we find a blocking fd, check if it's a socket, and shutdown() it. @@ -224,7 +354,6 @@ * things to check. - - execve occasionally returns -ESRCH. Why ? - disappearing processes. 'oom killed maybe' when no oom. * pthreads. (Real long term, lots of work). @@ -237,3 +366,142 @@ put mutex in lock_t ? - logging for threads? - send pthread_kill + - split childdata into threaddata & childdata + - logfiles got a lot trickier. nrgh. (postpone until after udp logging implemented) + - audit getpids that should now be gettid's + - more syscalls to be marked avoid ? + - allocate threaddata/syscallrecord before/after syscall + - tgkill instead of kill ? + - child needs to 'tick' and also become mini-watchdog checking on threads. + - each syscall: + void *thr(void *p) + { + regset = (struct regset *) p; + do_syscall(regset); + } + + pthread_t th; + pthread_create(&th, 0, thr, regset); + //pthread_join(th, 0); + pthread_detach(th) + - parallelize nftw's on startup + + +* bugs that need fixing + -a64 is positional vs -c + -g vm -c sendfile -a64 enables 1 32bit. + use of socketinfo in syscall sanitizers will segv if --disable-fds=sockets + +- move to object cache + - sysv objects + - iovecs + - store shmat return addresses. + - keyctl foo + +* AVOID_SYSCALL_IF_ROOT might be useful ? + +* Improve ftrace setup + - command line arg to enable function tracer or function-graph + - use a list of functions to avoid. + +* make dropprivs default. + - Move the drop privs code from main to just before we start a new child. + +* New ARG_ types + - ARG_FPOS + - 0 + - page_size -1 + - page_size + - page_size * 2 + - (page_size * 2) -1 + - ARG_SHMID + - More ARG_*FD types + - ARG_FD -> ARG_FD_FILE + - ARG_FD_DIR + - ARG_FD_PIPE + - ARG_FD_SIGNAL + - ARG_FD_EVENT + - ARG_FD_TIMER + - ARG_FD_EPOLL + - ARG_FD_MQ + - ARG_FD_INOTIFY + - ARG_FD_FANOTIFY + - ARG_FD_TTY + - ARG_FD_FUSE + - ARG_FD_TTY + - ARG_FD_DRM + - ARG_FILENAME + - kill off ARG_NON_NULL_ADDRESS & ARG_ADDRESS + Long way to go here. Generally, use ARG_MMAP + - ARG_DEVT + - ARG_TIMESPEC + +makedev dev_t's for dev args +unlink on /dev files should be disallowed + +scan /proc/filesystems for args for sys_mount +Gather more from /proc/mounts ? Look at iknowthis for examples. + +Maintain a tree of errnos that a syscall has seen. (only tricky part is that it needs to be in the shm) + +on startup, enable /proc/sys/net/core/bpf_jit_enable if we're root + +ram disks for mkfs,mount etc + +audit malloc uses in syscalls and convert to ARG_MMAP use where possible + +zmalloc should indicate to children to munlockall, sleep, and then retry + (some unix socket shared between children->main for comms?) + +load balancer: +- monitor meminfo/loadavg and dynamically adjust number of children +- fork extra children when more than half have been sent KILLs +- set shm->notprogressing if stall count reaches == nr_running_child/2 + - dont fork new processes if set + - halve max_children + - kill a few children at random + +New directions: +- variable alarm time for syscalls that might take longer than usual. +- recursion depth in child struct, so we can call fork/clone + - use clone instead of fork() sometimes. + - per child pids[] array ? + - This gets messy with things like adding to object lists so might not be a good idea. +- .assoc for things like socket/shutdown, open/close, mmap/munmap, truncate/lseek etc +- create hash of call chain in kernel (mask out boring funcs) + - use kcov for kernel traces + - in syscall struct have a tree of mutations + struct mutation { + unsigned long tracehash; + struct regset regs; + } + - if ->mutations is empty, generate args. + otherwise, get mutation from list, and mutate one arg. + if new run = new hash, store mutation in list. + if new run = existing hash, refetch mutation & mutate again + - if no other mutations, generate all new args + - if child dies, generate all new args + +* Revisit kcov code, and make use of the stacktraces in some way. + - we're not a mutational fuzzer (yet?) like syzkaller, so we might have to think + of something different to do here. + Some old, possibly no longer interesting ideas: + + If success, store parameters + - each arg in syscall struct gets a valid inputs entry + ARG_FD: bitmap of fd's that don't inval + ARG_LEN: min/max + - generate_args + - looks at past successes and picks a mix of 90% the same as last inputs. + - occasionally try something completely new + + Store success/fail per syscall + + hash stack trace + for each arg { + mutate arg <---+ + if new stack trace | + store arg | + if tries < 10 ----+ + } + From 72b934fb86f0ee22ed76f7945574575a578aecbf Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 18 Sep 2017 20:15:17 -0400 Subject: [PATCH 002/119] add a script I use to monitor when the kernel interfaces change --- scripts/hashcheck.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 scripts/hashcheck.sh diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh new file mode 100755 index 000000000..c414d1624 --- /dev/null +++ b/scripts/hashcheck.sh @@ -0,0 +1,88 @@ +#!/bin/sh +# +# Run from with a kernel source tree. +# Update the hashes after adding support to Trinity. + +# $1 = filename $2 = hash $3 = pattern +# +check() +{ + if [ ! -f $1 ]; then + echo "$1 is no longer present" + else + NEW=$(grep "[0123456789]" $1 | grep "$3" | sha1sum | awk '{ print $1 }') + if [ "$NEW" != "$2" ]; then + echo "$1 $3 changed. ($NEW)" + YEAR=$(date +%Y -d "1 month ago") + git annotate $1 | grep $YEAR | grep "$3" + echo + fi + fi +} + +# new syscalls +check include/uapi/asm-generic/unistd.h f639f3e7152473778b30cbc59b55acb36b9970f4 sys_ +#check arch/alpha/include/uapi/asm/unistd.h 51fa669a21d8f26a0c9de8280a3cfd9c257a0d28 _NR_ +#check arch/arm/include/uapi/asm/unistd.h 7c601d436a3ebbe05a9b6813c0ffcf8eedaf101b SYSCALL +check arch/x86/entry/syscalls/syscall_32.tbl 1b9ed3050a88b2d84bdb7dbcfe2ab23b8234bee8 sys_ +check arch/x86/entry/syscalls/syscall_64.tbl d96a3053b5267a3191df9a459274dbec738947f8 sys_ +check arch/x86/entry/syscalls/syscall_64.tbl da39a3ee5e6b4b0d3255bfef95601890afd80709 stub_ +#check arch/ia64/kernel/entry.S e6a21b973609ec08cd19b0b8c67830f8570e93ef "data8\ sys_" +#check arch/mips/kernel/scall32-o32.S b1501a675dd998fe2af68ae43cd797cf18d67b33 sys_ +#check arch/parisc/kernel/syscall_table.S 25d14db60070cb29499a9a16c975c7984f124f74 ENTRY_ +#check arch/powerpc/include/asm/systbl.h 8d11bade2537d955bd694ae30b2e986c680bba54 SYS +#check arch/s390/include/uapi/asm/unistd.h 0f5821c2413561ec2581631cc60dc189700d7494 __NR_ +#check arch/sh/kernel/syscalls_64.S aa1a2e958b9e1c6129bc9b488148ecf5c4bc2a7e sys_ +#check arch/sparc/kernel/systbls_32.S 98100f9dedc82d82ac18a33fd68dc7e4852ffcb8 sys_ + +# new setsockopt values +check include/uapi/asm-generic/socket.h 07d5ff722694d6dbb02b9e176d5155a0bfb82dcb SO_ +check include/uapi/linux/tcp.h ed5bbfa500b64aad4d742b2eed0d35ce22ab36b8 \#define\ TCP_ +check include/uapi/linux/in.h 0116e6878df350e74ec730fd9f455efb95e510c8 \#define\ IP_ + +# Check for new packet families +check include/linux/socket.h 1d7b02dedfa31669e23495f3c854e6e1f0fc2ce2 SOL_ +check include/linux/socket.h 80c34154051e712d03e81577d494efe8f09139a8 AF_ + +# MSG_ flags +check include/linux/socket.h 8a16113605d79d8f280345857d40779a3b8b48cc \ MSG_ + +# new netlink protos +check include/uapi/linux/netlink.h 1f391f35d0443f432871cbb366d1150973eb2bcb "#define\ NETLINK_" + +# new O_ flags +check include/uapi/asm-generic/fcntl.h 256ab30dfec0915704a13755ba645c448a65220c O_ + +# new F_ flags +check include/uapi/asm-generic/fcntl.h 98cf236ce61466e272727683eba11493d41c6b27 F_ + +# new splice flags +check include/linux/splice.h fb753f99bf38f7c041427c442f199aa2049fa329 SPLICE_F_ + +# new madvise flags +check include/uapi/asm-generic/mman-common.h 2baddc86959839fbc367eff0c3fe830bce866d7c MADV_ + +# new mremap flags +check include/uapi/linux/mman.h 556bcea4a4581a03a600c2d383c462840f1c0e6c MREMAP_ + +# new IPPROTO's +check include/uapi/linux/in.h 80799106aba80b40af5416f0d5cc47dea8b02225 \ \ IPPROTO_ + +# Check for new errnos +check include/uapi/asm-generic/errno.h da39a3ee5e6b4b0d3255bfef95601890afd80709 134 + +# new prctls +check include/uapi/linux/prctl.h 54a153856a9136a9bad87deed2475f8eca2ebbbb PR_ + +# new fallocate flags +check include/uapi/linux/falloc.h c46220c8e3bd5e237d02880e0d2ac16e88a6d7c0 FALLOC_ +# new fallocate flags +check include/uapi/linux/falloc.h c46220c8e3bd5e237d02880e0d2ac16e88a6d7c0 FL_ + + +# special: we want to know when MPOL_MF_VALID changes. +NEW=$(grep -C2 MPOL_MF_VALID include/uapi/linux/mempolicy.h | sha1sum | awk '{ print $1 }') +if [ "$NEW" != "1cf1845ede2e209d84ef0ab0dce6b523a70bb3ca" ]; then + echo "MPOL_MF_VALID changed. ($NEW)" +fi + From 2c49c862df82f311ae4791827542053ce8fe7bad Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 18 Sep 2017 20:16:24 -0400 Subject: [PATCH 003/119] add hashcheck use to TODO --- Documentation/TODO | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/TODO b/Documentation/TODO index db0343b63..893b1afbe 100644 --- a/Documentation/TODO +++ b/Documentation/TODO @@ -24,7 +24,8 @@ * Further syscall annotation improvements - Finish annotating syscall return types & error codes. - Add missing system calls. - + - Run scripts/hashcheck.sh to get info on new bits that need adding to Trinity. + - Add additional userspace APIs to hashcheck * UDP logging - This is pretty rough right now, but kinda works. From 14e3dbf95680d9eb9006233d09742be21f5726d8 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Sat, 23 Sep 2017 15:30:53 -0400 Subject: [PATCH 004/119] Fix up null ptr deref when no -l arg. --- log-files.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/log-files.c b/log-files.c index 5853c096e..1659fa3bd 100644 --- a/log-files.c +++ b/log-files.c @@ -15,11 +15,16 @@ FILE *mainlogfile; static FILE *open_logfile(const char *logfilename) { FILE *file; - char *fullpath; - int len = strlen(logging_args) + strlen(logfilename) + 2; + char *fullpath, *p; + int len = strlen(logfilename) + 2; - fullpath = zmalloc(len); - snprintf(fullpath, len, "%s/%s", logging_args, logfilename); + if (logging_args) + len += strlen(logging_args); + + p = fullpath = zmalloc(len); + if (logging_args) + p += snprintf(fullpath, strlen(logging_args) + 2, "%s/", logging_args); + p += snprintf(p, strlen(logfilename) + 1, "%s", logfilename); unlink(fullpath); From d4cb8d894ba32d1417ef8eb422515abb64ddf111 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Fri, 6 Oct 2017 13:58:50 -0400 Subject: [PATCH 005/119] ignore possible error codes like ERESTARTSYS These are usually only seen by libc, and never passed on to apps, but Trinity is doing raw syscalls, so we have to worry about these. --- syscall.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/syscall.c b/syscall.c index 3d6f3d728..b77d13976 100644 --- a/syscall.c +++ b/syscall.c @@ -278,7 +278,13 @@ void handle_syscall_ret(struct syscallrecord *rec) if (err < NR_ERRNOS) { entry->errnos[err]++; } else { - printf("errno out of range: %d:%s\n", err, strerror(err)); + // "These should never be seen by user programs." + // But trinity isn't a 'normal' user program, we're doing + // stuff that libc hides from apps. + if (err < 512 || err > 530) + printf("errno out of range after doing %s: %d:%s\n", + entry->name, + err, strerror(err)); } shm->stats.failures++; } From 68362e386dc687b787fd38119d6c58de5960a2c3 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 26 Oct 2017 10:09:50 -0400 Subject: [PATCH 006/119] add SO_ZEROCOPY --- include/compat.h | 4 +++- syscalls/setsockopt.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/compat.h b/include/compat.h index a7e99b903..1ec0866e4 100644 --- a/include/compat.h +++ b/include/compat.h @@ -525,7 +525,9 @@ enum kcmp_type { #define SO_PEERGROUPS 59 #endif - +#ifndef SO_ZEROCOPY +#define SO_ZEROCOPY 60 +#endif /* linux/tcp.h */ diff --git a/syscalls/setsockopt.c b/syscalls/setsockopt.c index 3653ad639..3f38a61a6 100644 --- a/syscalls/setsockopt.c +++ b/syscalls/setsockopt.c @@ -25,7 +25,7 @@ static const unsigned int socket_opts[] = { SO_BUSY_POLL, SO_MAX_PACING_RATE, SO_BPF_EXTENSIONS, SO_INCOMING_CPU, SO_ATTACH_BPF, SO_ATTACH_REUSEPORT_CBPF, SO_ATTACH_REUSEPORT_EBPF, SO_CNX_ADVICE, SCM_TIMESTAMPING_OPT_STATS, SO_MEMINFO, SO_INCOMING_NAPI_ID, - SO_COOKIE, SCM_TIMESTAMPING_PKTINFO, SO_PEERGROUPS, + SO_COOKIE, SCM_TIMESTAMPING_PKTINFO, SO_PEERGROUPS, SO_ZEROCOPY, }; static void socket_setsockopt(struct sockopt *so, __unused__ struct socket_triplet *triplet) From 6485043e0aec90fcd688d5f30192ec0b3f8b6ea3 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 26 Oct 2017 10:16:38 -0400 Subject: [PATCH 007/119] add statx for i386 --- include/syscalls-i386.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/syscalls-i386.h b/include/syscalls-i386.h index cfb5cd56a..1fee9b91a 100644 --- a/include/syscalls-i386.h +++ b/include/syscalls-i386.h @@ -1,6 +1,6 @@ #pragma once -/* Syscalls from arch/x86/syscalls/syscall_32.tbl */ +/* Syscalls from arch/x86/entry/syscalls/syscall_32.tbl */ #include "sanitise.h" #include "syscall.h" @@ -394,4 +394,5 @@ struct syscalltable syscalls_i386[] = { { .entry = &syscall_pkey_mprotect }, { .entry = &syscall_pkey_alloc }, { .entry = &syscall_pkey_free }, + { .entry = &syscall_statx }, }; From 3acf7d3eb577410c24f3f0c418bd8c3cad615aa6 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 26 Oct 2017 10:19:04 -0400 Subject: [PATCH 008/119] add MSG_ZEROCOPY --- include/compat.h | 4 ++++ syscalls/recv.c | 2 +- syscalls/send.c | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/compat.h b/include/compat.h index 1ec0866e4..42b25f29f 100644 --- a/include/compat.h +++ b/include/compat.h @@ -250,6 +250,10 @@ enum { #define MSG_BATCH 0x40000 #endif +#ifndef MSG_ZEROCOPY +#define MSG_ZEROCOPY 0x4000000 +#endif + #ifndef MSG_CMSG_CLOEXEC #define MSG_CMSG_CLOEXEC 0x40000000 #endif diff --git a/syscalls/recv.c b/syscalls/recv.c index fce18d954..2e0e0b12d 100644 --- a/syscalls/recv.c +++ b/syscalls/recv.c @@ -20,7 +20,7 @@ static unsigned long recv_flags[] = { MSG_WAITALL, MSG_FIN, MSG_SYN, MSG_CONFIRM, MSG_RST, MSG_ERRQUEUE, MSG_NOSIGNAL, MSG_MORE, MSG_WAITFORONE, MSG_FASTOPEN, MSG_CMSG_CLOEXEC, MSG_CMSG_COMPAT, - MSG_BATCH, + MSG_BATCH, MSG_ZEROCOPY, }; struct syscallentry syscall_recv = { diff --git a/syscalls/send.c b/syscalls/send.c index a45139eb4..59bf689d3 100644 --- a/syscalls/send.c +++ b/syscalls/send.c @@ -68,7 +68,7 @@ static unsigned long sendflags[] = { MSG_WAITALL, MSG_FIN, MSG_SYN, MSG_CONFIRM, MSG_RST, MSG_ERRQUEUE, MSG_NOSIGNAL, MSG_MORE, MSG_WAITFORONE, MSG_FASTOPEN, MSG_CMSG_CLOEXEC, MSG_CMSG_COMPAT, - MSG_BATCH, + MSG_BATCH, MSG_ZEROCOPY, }; struct syscallentry syscall_send = { From e1b99c67fd3da7a32c40e3bdbc02b03ac6839e1d Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 26 Oct 2017 10:20:53 -0400 Subject: [PATCH 009/119] add new madvise flags --- include/compat.h | 6 ++++++ syscalls/madvise.c | 1 + 2 files changed, 7 insertions(+) diff --git a/include/compat.h b/include/compat.h index 42b25f29f..10065ceca 100644 --- a/include/compat.h +++ b/include/compat.h @@ -138,6 +138,12 @@ enum { #ifndef MADV_DODUMP #define MADV_DODUMP 17 #endif +#ifndef MADV_WIPEONFORK +#define MADV_WIPEONFORK 18 +#endif +#ifndef MADV_KEEPONFORK +#define MADV_KEEPONFORK 19 +#endif /* bits/socket.h */ diff --git a/syscalls/madvise.c b/syscalls/madvise.c index 61e574382..b3c77b3e7 100644 --- a/syscalls/madvise.c +++ b/syscalls/madvise.c @@ -21,6 +21,7 @@ static unsigned long madvise_advices[] = { MADV_FREE, MADV_REMOVE, MADV_DONTFORK, MADV_DOFORK, MADV_MERGEABLE, MADV_UNMERGEABLE, MADV_HUGEPAGE, MADV_NOHUGEPAGE, MADV_DONTDUMP, MADV_DODUMP, + MADV_WIPEONFORK, MADV_KEEPONFORK, }; struct syscallentry syscall_madvise = { From 31a51156b468798238f9ea4ff180ec3c0edc1ca5 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 26 Oct 2017 10:21:04 -0400 Subject: [PATCH 010/119] update hashes --- scripts/hashcheck.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh index c414d1624..01c3b9d9b 100755 --- a/scripts/hashcheck.sh +++ b/scripts/hashcheck.sh @@ -20,12 +20,16 @@ check() fi } + # new syscalls -check include/uapi/asm-generic/unistd.h f639f3e7152473778b30cbc59b55acb36b9970f4 sys_ +# Note: Commented out checks are likely out of date, but they're for architectures +# I don't have time to care about. Step up and contribute if you care. +# +check include/uapi/asm-generic/unistd.h e1f35cf48a7ae6a07949ad3e875cb7937c2c6cf0 sys_ #check arch/alpha/include/uapi/asm/unistd.h 51fa669a21d8f26a0c9de8280a3cfd9c257a0d28 _NR_ #check arch/arm/include/uapi/asm/unistd.h 7c601d436a3ebbe05a9b6813c0ffcf8eedaf101b SYSCALL check arch/x86/entry/syscalls/syscall_32.tbl 1b9ed3050a88b2d84bdb7dbcfe2ab23b8234bee8 sys_ -check arch/x86/entry/syscalls/syscall_64.tbl d96a3053b5267a3191df9a459274dbec738947f8 sys_ +check arch/x86/entry/syscalls/syscall_64.tbl d52841da5ee801bfd7277fccf5b76d30566ace1a sys_ check arch/x86/entry/syscalls/syscall_64.tbl da39a3ee5e6b4b0d3255bfef95601890afd80709 stub_ #check arch/ia64/kernel/entry.S e6a21b973609ec08cd19b0b8c67830f8570e93ef "data8\ sys_" #check arch/mips/kernel/scall32-o32.S b1501a675dd998fe2af68ae43cd797cf18d67b33 sys_ @@ -36,16 +40,16 @@ check arch/x86/entry/syscalls/syscall_64.tbl da39a3ee5e6b4b0d3255bfef9560189 #check arch/sparc/kernel/systbls_32.S 98100f9dedc82d82ac18a33fd68dc7e4852ffcb8 sys_ # new setsockopt values -check include/uapi/asm-generic/socket.h 07d5ff722694d6dbb02b9e176d5155a0bfb82dcb SO_ +check include/uapi/asm-generic/socket.h 848bfd5d1700324c48e1216da2abdda7515b230b SO_ check include/uapi/linux/tcp.h ed5bbfa500b64aad4d742b2eed0d35ce22ab36b8 \#define\ TCP_ check include/uapi/linux/in.h 0116e6878df350e74ec730fd9f455efb95e510c8 \#define\ IP_ # Check for new packet families -check include/linux/socket.h 1d7b02dedfa31669e23495f3c854e6e1f0fc2ce2 SOL_ +check include/linux/socket.h 17b4779bb45a76825972f41d1fa1f8d2b908a21b SOL_ check include/linux/socket.h 80c34154051e712d03e81577d494efe8f09139a8 AF_ # MSG_ flags -check include/linux/socket.h 8a16113605d79d8f280345857d40779a3b8b48cc \ MSG_ +check include/linux/socket.h 91b84d05363d32e88375567a9bb7a4e16d738ea8 \ MSG_ # new netlink protos check include/uapi/linux/netlink.h 1f391f35d0443f432871cbb366d1150973eb2bcb "#define\ NETLINK_" @@ -60,7 +64,7 @@ check include/uapi/asm-generic/fcntl.h 98cf236ce61466e272727683eba11493d41c6b27 check include/linux/splice.h fb753f99bf38f7c041427c442f199aa2049fa329 SPLICE_F_ # new madvise flags -check include/uapi/asm-generic/mman-common.h 2baddc86959839fbc367eff0c3fe830bce866d7c MADV_ +check include/uapi/asm-generic/mman-common.h c6e990af02fd65c13c5e25c2d4e7dffa32724b23 MADV_ # new mremap flags check include/uapi/linux/mman.h 556bcea4a4581a03a600c2d383c462840f1c0e6c MREMAP_ From 40605158e06cd2e762b421866b0dabb42893fd02 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Thu, 26 Oct 2017 11:18:13 -0400 Subject: [PATCH 011/119] perf_event_open: update features to 4.14-rc6 This patch brings perf_event_open() support up to date as of 4.14-rc6. Signed-off-by: Vince Weaver --- include/perf_event.h | 108 +++++++++++++++++++++++++++++++++++-- syscalls/perf_event_open.c | 21 ++++++-- 2 files changed, 120 insertions(+), 9 deletions(-) diff --git a/include/perf_event.h b/include/perf_event.h index cb0796fb9..fd57a6570 100644 --- a/include/perf_event.h +++ b/include/perf_event.h @@ -138,8 +138,9 @@ enum perf_event_sample_format { PERF_SAMPLE_IDENTIFIER = 1U << 16, PERF_SAMPLE_TRANSACTION = 1U << 17, PERF_SAMPLE_REGS_INTR = 1U << 18, + PERF_SAMPLE_PHYS_ADDR = 1U << 19, - PERF_SAMPLE_MAX = 1U << 19, /* non-ABI */ + PERF_SAMPLE_MAX = 1U << 20, /* non-ABI */ }; /* @@ -173,6 +174,8 @@ enum perf_branch_sample_type_shift { PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT = 14, /* no flags */ PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT = 15, /* no cycles */ + PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT = 16, /* save branch type */ + PERF_SAMPLE_BRANCH_MAX_SHIFT /* non-ABI */ }; @@ -197,9 +200,30 @@ enum perf_branch_sample_type { PERF_SAMPLE_BRANCH_NO_FLAGS = 1U << PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT, PERF_SAMPLE_BRANCH_NO_CYCLES = 1U << PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT, + PERF_SAMPLE_BRANCH_TYPE_SAVE = + 1U << PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT, + PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT, }; +/* + * Common flow change classification + */ +enum { + PERF_BR_UNKNOWN = 0, /* unknown */ + PERF_BR_COND = 1, /* conditional */ + PERF_BR_UNCOND = 2, /* unconditional */ + PERF_BR_IND = 3, /* indirect */ + PERF_BR_CALL = 4, /* function call */ + PERF_BR_IND_CALL = 5, /* indirect function call */ + PERF_BR_RET = 6, /* function return */ + PERF_BR_SYSCALL = 7, /* syscall */ + PERF_BR_SYSRET = 8, /* syscall return */ + PERF_BR_COND_CALL = 9, /* conditional function call */ + PERF_BR_COND_RET = 10, /* conditional function return */ + PERF_BR_MAX, +}; + #define PERF_SAMPLE_BRANCH_PLM_ALL \ (PERF_SAMPLE_BRANCH_USER|\ PERF_SAMPLE_BRANCH_KERNEL|\ @@ -343,7 +367,8 @@ struct perf_event_attr { use_clockid : 1, /* use @clockid for time fields */ context_switch : 1, /* context switch data */ write_backward : 1, /* Write ring buffer from end to beginning */ - __reserved_1 : 36; + namespaces : 1, /* include namespaces data */ + __reserved_1 : 35; union { __u32 wakeup_events; /* wakeup every n events */ @@ -609,6 +634,23 @@ struct perf_event_header { __u16 size; }; +struct perf_ns_link_info { + __u64 dev; + __u64 ino; +}; + +enum { + NET_NS_INDEX = 0, + UTS_NS_INDEX = 1, + IPC_NS_INDEX = 2, + PID_NS_INDEX = 3, + USER_NS_INDEX = 4, + MNT_NS_INDEX = 5, + CGROUP_NS_INDEX = 6, + + NR_NAMESPACES, /* number of available namespaces */ +}; + enum perf_event_type { /* @@ -772,6 +814,7 @@ enum perf_event_type { * { u64 transaction; } && PERF_SAMPLE_TRANSACTION * { u64 abi; # enum perf_sample_regs_abi * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_INTR + * { u64 phys_addr;} && PERF_SAMPLE_PHYS_ADDR * }; */ PERF_RECORD_SAMPLE = 9, @@ -861,6 +904,18 @@ enum perf_event_type { */ PERF_RECORD_SWITCH_CPU_WIDE = 15, + /* + * struct { + * struct perf_event_header header; + * u32 pid; + * u32 tid; + * u64 nr_namespaces; + * { u64 dev, inode; } [nr_namespaces]; + * struct sample_id sample_id; + * }; + */ + PERF_RECORD_NAMESPACES = 16, + PERF_RECORD_MAX, /* non-ABI */ }; @@ -884,12 +939,14 @@ enum perf_callchain_context { */ #define PERF_AUX_FLAG_TRUNCATED 0x01 /* record was truncated to fit */ #define PERF_AUX_FLAG_OVERWRITE 0x02 /* snapshot from overwrite mode */ +#define PERF_AUX_FLAG_PARTIAL 0x04 /* record contains gaps */ #define PERF_FLAG_FD_NO_GROUP (1UL << 0) #define PERF_FLAG_FD_OUTPUT (1UL << 1) #define PERF_FLAG_PID_CGROUP (1UL << 2) /* pid=cgroup id, per-cpu mode only */ #define PERF_FLAG_FD_CLOEXEC (1UL << 3) /* O_CLOEXEC */ +#if defined(__LITTLE_ENDIAN_BITFIELD) union perf_mem_data_src { __u64 val; struct { @@ -898,9 +955,30 @@ union perf_mem_data_src { mem_snoop:5, /* snoop mode */ mem_lock:2, /* lock instr */ mem_dtlb:7, /* tlb access */ - mem_rsvd:31; + mem_lvl_num:4, /* memory hierarchy level number */ + mem_remote:1, /* remote */ + mem_snoopx:2, /* snoop mode, ext */ + mem_rsvd:24; }; }; +#elif defined(__BIG_ENDIAN_BITFIELD) +union perf_mem_data_src { + __u64 val; + struct { + __u64 mem_rsvd:24, + mem_snoopx:2, /* snoop mode, ext */ + mem_remote:1, /* remote */ + mem_lvl_num:4, /* memory hierarchy level number */ + mem_dtlb:7, /* tlb access */ + mem_lock:2, /* lock instr */ + mem_snoop:5, /* snoop mode */ + mem_lvl:14, /* memory hierarchy level */ + mem_op:5; /* type of opcode */ + }; +}; +#else +#error "Unknown endianness" +#endif /* type of opcode (load/store/prefetch,code) */ #define PERF_MEM_OP_NA 0x01 /* not available */ @@ -927,6 +1005,22 @@ union perf_mem_data_src { #define PERF_MEM_LVL_UNC 0x2000 /* Uncached memory */ #define PERF_MEM_LVL_SHIFT 5 +#define PERF_MEM_REMOTE_REMOTE 0x01 /* Remote */ +#define PERF_MEM_REMOTE_SHIFT 37 + +#define PERF_MEM_LVLNUM_L1 0x01 /* L1 */ +#define PERF_MEM_LVLNUM_L2 0x02 /* L2 */ +#define PERF_MEM_LVLNUM_L3 0x03 /* L3 */ +#define PERF_MEM_LVLNUM_L4 0x04 /* L4 */ +/* 5-0xa available */ +#define PERF_MEM_LVLNUM_ANY_CACHE 0x0b /* Any cache */ +#define PERF_MEM_LVLNUM_LFB 0x0c /* LFB */ +#define PERF_MEM_LVLNUM_RAM 0x0d /* RAM */ +#define PERF_MEM_LVLNUM_PMEM 0x0e /* PMEM */ +#define PERF_MEM_LVLNUM_NA 0x0f /* N/A */ + +#define PERF_MEM_LVLNUM_SHIFT 33 + /* snoop mode */ #define PERF_MEM_SNOOP_NA 0x01 /* not available */ #define PERF_MEM_SNOOP_NONE 0x02 /* no snoop */ @@ -935,6 +1029,10 @@ union perf_mem_data_src { #define PERF_MEM_SNOOP_HITM 0x10 /* snoop hit modified */ #define PERF_MEM_SNOOP_SHIFT 19 +#define PERF_MEM_SNOOPX_FWD 0x01 /* forward */ +/* 1 free */ +#define PERF_MEM_SNOOPX_SHIFT 37 + /* locked instruction */ #define PERF_MEM_LOCK_NA 0x01 /* not available */ #define PERF_MEM_LOCK_LOCKED 0x02 /* locked transaction */ @@ -967,6 +1065,7 @@ union perf_mem_data_src { * in_tx: running in a hardware transaction * abort: aborting a hardware transaction * cycles: cycles from last branch (or 0 if not supported) + * type: branch type */ struct perf_branch_entry { __u64 from; @@ -976,5 +1075,6 @@ struct perf_branch_entry { in_tx:1, /* in transaction */ abort:1, /* transaction abort */ cycles:16, /* cycle count to last branch */ - reserved:44; + type:4, /* branch type */ + reserved:40; }; diff --git a/syscalls/perf_event_open.c b/syscalls/perf_event_open.c index 6cecee882..10106b592 100644 --- a/syscalls/perf_event_open.c +++ b/syscalls/perf_event_open.c @@ -879,6 +879,8 @@ static long long random_sample_type(void) sample_type |= PERF_SAMPLE_TRANSACTION; if (RAND_BOOL()) sample_type |= PERF_SAMPLE_REGS_INTR; + if (RAND_BOOL()) + sample_type |= PERF_SAMPLE_PHYS_ADDR; return sample_type; } @@ -958,6 +960,16 @@ static long long random_branch_sample_type(void) branch_sample |= PERF_SAMPLE_BRANCH_ANY_RETURN; if (RAND_BOOL()) branch_sample |= PERF_SAMPLE_BRANCH_IND_CALL; + + /* Transactional Memory Types */ + if (RAND_BOOL()) + branch_sample |= PERF_SAMPLE_BRANCH_ABORT_TX; + if (RAND_BOOL()) + branch_sample |= PERF_SAMPLE_BRANCH_IN_TX; + if (RAND_BOOL()) + branch_sample |= PERF_SAMPLE_BRANCH_NO_TX; + + if (RAND_BOOL()) branch_sample |= PERF_SAMPLE_BRANCH_COND; if (RAND_BOOL()) @@ -966,14 +978,13 @@ static long long random_branch_sample_type(void) branch_sample |= PERF_SAMPLE_BRANCH_IND_JUMP; if (RAND_BOOL()) branch_sample |= PERF_SAMPLE_BRANCH_CALL; - - /* Transactional Memory Types */ if (RAND_BOOL()) - branch_sample |= PERF_SAMPLE_BRANCH_ABORT_TX; + branch_sample |= PERF_SAMPLE_BRANCH_NO_FLAGS; if (RAND_BOOL()) - branch_sample |= PERF_SAMPLE_BRANCH_IN_TX; + branch_sample |= PERF_SAMPLE_BRANCH_NO_CYCLES; if (RAND_BOOL()) - branch_sample |= PERF_SAMPLE_BRANCH_NO_TX; + branch_sample |= PERF_SAMPLE_BRANCH_TYPE_SAVE; + return branch_sample; } From 6a3de54ea0428a33e7039ab7940f38dcfea341ec Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Fri, 27 Oct 2017 16:39:17 -0400 Subject: [PATCH 012/119] TODO: some extra cmdline args --- Documentation/TODO | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/TODO b/Documentation/TODO index 893b1afbe..2c6a44216 100644 --- a/Documentation/TODO +++ b/Documentation/TODO @@ -206,8 +206,11 @@ - function that takes a void * and outputs what it is (mapping, page_* etc) (searches various lists etc) -* --dry-run mode. +* Extra command line args. + --dry-run mode. need to work around segv's when we do things like mmap->post and register null maps. + --disable-fault-injection + --pause (reinstate the old code to pause for a second after a syscall) * fd handling improvements. - kill off NR_FILE_FDS From 6ddabfd29480a6a526895a578c56bc8051228c15 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Fri, 3 Nov 2017 11:14:07 -0400 Subject: [PATCH 013/119] 1.8 release --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 32d092865..6b254b12d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION="1.8pre" +VERSION="1.8" ifeq (,$(findstring pre,$(VERSION))) DEVEL = 0 From 04033342041f8d302ccae8725a155570a91fa435 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Tue, 28 Nov 2017 11:47:32 -0500 Subject: [PATCH 014/119] Begin 1.9 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6b254b12d..786190649 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION="1.8" +VERSION="1.9pre" ifeq (,$(findstring pre,$(VERSION))) DEVEL = 0 From a80833f79b212a812613b5f9d569941f2a7dd3d9 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Tue, 28 Nov 2017 11:48:27 -0500 Subject: [PATCH 015/119] fd logging -> object logging --- Documentation/TODO | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Documentation/TODO b/Documentation/TODO index 2c6a44216..908fbe6d2 100644 --- a/Documentation/TODO +++ b/Documentation/TODO @@ -1,3 +1,7 @@ +* Object logging. + - Attach an operation history to each object to be dumped at post-mortem time. + - Will need a comms channel from children->main. pipe? unix socket? + * Various syscall improvements. - brk could be smarter about existing brk - Revisit fuzzing ptrace. @@ -229,8 +233,6 @@ they dominate over the /dev entries. - more fd 'types' (fanotify_init) - need a way to go from fd to string describing what it is. for post-mortem - - Attach an operation history to each fd for post-mortem. - Maybe we need an fd container struct ? - deregister fd providers if init of one fails - separate fd lists for dirs vs files - make fd providers take array to fillin & num of fds as params. From e4f31d5a1ce65974c2a6b2e6e1a2b16fffc51518 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Tue, 28 Nov 2017 10:15:22 +0100 Subject: [PATCH 016/119] compat: handle removed autofs macros In file included from ioctls/autofs.c:4:0: ioctls/autofs.c:241:8: error: 'AUTOFS_IOC_EXPIRE_INDIRECT' undeclared here (not in a function); did you mean 'AUTOFS_IOC_EXPIRE_CMD'? IOCTL(AUTOFS_IOC_EXPIRE_INDIRECT), ^ include/ioctls.h:53:15: note: in definition of macro 'IOCTL' { .request = _request, .name = #_request, } ^~~~~~~~ ioctls/autofs.c:242:8: error: 'AUTOFS_IOC_EXPIRE_DIRECT' undeclared here (not in a function); did you mean 'AUTOFS_IOC_EXPIRE_INDIRECT'? IOCTL(AUTOFS_IOC_EXPIRE_DIRECT), ^ include/ioctls.h:53:15: note: in definition of macro 'IOCTL' { .request = _request, .name = #_request, } ^~~~~~~~ Define them as AUTOFS_IOC_EXPIRE_MULTI as they used to be. Signed-off-by: Jiri Slaby --- include/compat.h | 8 ++++++++ ioctls/autofs.c | 1 + 2 files changed, 9 insertions(+) diff --git a/include/compat.h b/include/compat.h index 10065ceca..fc9a1b95a 100644 --- a/include/compat.h +++ b/include/compat.h @@ -1209,3 +1209,11 @@ struct kvm_get_htab_fd { #ifndef SO_IP_SET #define SO_IP_SET 83 #endif + +/* linux/auto_fs4.h */ +#ifndef AUTOFS_IOC_EXPIRE_INDIRECT +#define AUTOFS_IOC_EXPIRE_INDIRECT AUTOFS_IOC_EXPIRE_MULTI +#endif +#ifndef AUTOFS_IOC_EXPIRE_DIRECT +#define AUTOFS_IOC_EXPIRE_DIRECT AUTOFS_IOC_EXPIRE_MULTI +#endif diff --git a/ioctls/autofs.c b/ioctls/autofs.c index 04a3eb811..a39ccccc0 100644 --- a/ioctls/autofs.c +++ b/ioctls/autofs.c @@ -8,6 +8,7 @@ #include "shm.h" #include "syscall.h" #include "utils.h" +#include "compat.h" /* include/linux/auto_dev-ioctl.h */ /* From 00a1a514288e645690a46afaad87c1080da4960f Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Tue, 19 Dec 2017 15:41:13 -0500 Subject: [PATCH 017/119] document why we take that rec->lock in the extrafork path --- syscall.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/syscall.c b/syscall.c index b77d13976..000244b96 100644 --- a/syscall.c +++ b/syscall.c @@ -167,6 +167,8 @@ static void do_extrafork(struct syscallrecord *rec) if (pid_alive(extrapid) == TRUE) usleep(100); + /* We take the rec lock here even though we don't obviously use it. + * The reason, is that the grandchild is using it. */ lock(&rec->lock); while (pid == 0) { int childstatus; From 32aff3da79f50a2dd9a944022c1b2837bfe0d1b7 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 6 Feb 2018 09:02:23 +0100 Subject: [PATCH 018/119] trinity: Fix compile error on linux 4.15 kernel Commit 1f28c5d055032e7e8ee5e48198dca7e125d0eec6 ("autofs: remove unused AUTOFS_IOC_EXPIRE_DIRECT/INDIRECT") in the linux kernel removed the 2 defines AUTOFS_IOC_EXPIRE_INDIRECT AUTOFS_IOC_EXPIRE_DIRECT Since they are used unconditionally the build fails. To fix this add #ifdef/#endif around it. Signed-off-by: Thomas Richter --- ioctls/autofs.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ioctls/autofs.c b/ioctls/autofs.c index a39ccccc0..03eacaaeb 100644 --- a/ioctls/autofs.c +++ b/ioctls/autofs.c @@ -239,8 +239,15 @@ static const struct ioctl autofs_ioctls[] = { IOCTL(AUTOFS_IOC_SETTIMEOUT), IOCTL(AUTOFS_IOC_EXPIRE), IOCTL(AUTOFS_IOC_EXPIRE_MULTI), + /* Both defines removed by kernel commit + * 1f28c5d055032e7e8ee5e48198dca7e125d0eec6 + */ +#ifdef AUTOFS_IOC_EXPIRE_INDIRECT IOCTL(AUTOFS_IOC_EXPIRE_INDIRECT), +#endif +#ifdef AUTOFS_IOC_EXPIRE_DIRECT IOCTL(AUTOFS_IOC_EXPIRE_DIRECT), +#endif IOCTL(AUTOFS_IOC_PROTOSUBVER), IOCTL(AUTOFS_IOC_ASKUMOUNT), From 496b05a60ba7fbbfb86ea8519b5eeb695a1b37eb Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 6 Feb 2018 09:02:24 +0100 Subject: [PATCH 019/119] trinity: Update and comment on s390 system call table Update and add some comments on the system call tables for s390x (64bit) and s390 (31bit). Signed-off-by: Thomas Richter --- include/syscalls-s390.h | 81 +++++++++++--------- include/syscalls-s390x.h | 162 +++++++++++++++++++++++---------------- 2 files changed, 138 insertions(+), 105 deletions(-) diff --git a/include/syscalls-s390.h b/include/syscalls-s390.h index 9916e6c6e..83613edfc 100644 --- a/include/syscalls-s390.h +++ b/include/syscalls-s390.h @@ -7,7 +7,7 @@ #include "syscalls/syscalls.h" struct syscalltable syscalls_s390[] = { - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 0 unused system call */ { .entry = &syscall_exit }, { .entry = &syscall_fork }, { .entry = &syscall_read }, @@ -24,8 +24,8 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_mknod }, { .entry = &syscall_chmod }, { .entry = &syscall_lchown16 }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 17 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 18 unused system call */ { .entry = &syscall_lseek }, { .entry = &syscall_getpid }, { .entry = &syscall_mount }, @@ -35,14 +35,14 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_stime }, { .entry = &syscall_ptrace }, { .entry = &syscall_alarm }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 28 unused system call */ { .entry = &syscall_pause }, { .entry = &syscall_utime }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 31 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 32 unused system call */ { .entry = &syscall_access }, { .entry = &syscall_nice }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 35 unused system call */ { .entry = &syscall_sync }, { .entry = &syscall_kill }, { .entry = &syscall_rename }, @@ -51,7 +51,7 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_dup }, { .entry = &syscall_pipe }, { .entry = &syscall_times }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 44 unused system call */ { .entry = &syscall_brk }, { .entry = &syscall_setgid16 }, { .entry = &syscall_getgid16 }, @@ -60,13 +60,13 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_getegid16 }, { .entry = &syscall_acct }, { .entry = &syscall_umount }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 53 unused system call */ { .entry = &syscall_ioctl }, { .entry = &syscall_fcntl }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 56 unused system call */ { .entry = &syscall_setpgid }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 58 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 59 unused system call */ { .entry = &syscall_umask }, { .entry = &syscall_chroot }, { .entry = &syscall_ustat }, @@ -75,8 +75,8 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_getpgrp }, { .entry = &syscall_setsid }, { .entry = &syscall_sigaction }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 68 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 69 unused system call */ { .entry = &syscall_setreuid16 }, { .entry = &syscall_setregid16 }, { .entry = &syscall_sigsuspend }, @@ -89,14 +89,14 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_settimeofday }, { .entry = &syscall_getgroups16 }, { .entry = &syscall_setgroups16 }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 82 unused system call */ { .entry = &syscall_symlink }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 84 unused system call */ { .entry = &syscall_readlink }, { .entry = &syscall_uselib }, { .entry = &syscall_swapon }, { .entry = &syscall_reboot }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* TODO: readdir systemcall */ { .entry = &syscall_mmap }, /* old_mmap */ { .entry = &syscall_munmap }, { .entry = &syscall_truncate }, @@ -105,10 +105,10 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_fchown16 }, { .entry = &syscall_getpriority }, { .entry = &syscall_setpriority }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 98 unused system call */ { .entry = &syscall_statfs }, { .entry = &syscall_fstatfs }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant ioperm svc */ { .entry = &syscall_socketcall }, { .entry = &syscall_syslog }, { .entry = &syscall_setitimer }, @@ -116,11 +116,11 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_newstat }, { .entry = &syscall_newlstat }, { .entry = &syscall_newfstat }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 109 unused system call */ { .entry = &syscall_lookup_dcookie }, { .entry = &syscall_vhangup }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant idle svc */ + { .entry = &syscall_ni_syscall }, /* No 113 unused system call */ { .entry = &syscall_wait4 }, { .entry = &syscall_swapoff }, { .entry = &syscall_sysinfo }, @@ -130,21 +130,21 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_clone }, { .entry = &syscall_setdomainname }, { .entry = &syscall_newuname }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 123 unused system call */ { .entry = &syscall_adjtimex }, { .entry = &syscall_mprotect }, { .entry = &syscall_sigprocmask }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant create_module svc */ { .entry = &syscall_init_module }, { .entry = &syscall_delete_module }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant get_kernel_syms svc */ { .entry = &syscall_quotactl }, { .entry = &syscall_getpgid }, { .entry = &syscall_fchdir }, { .entry = &syscall_bdflush }, { .entry = &syscall_sysfs }, { .entry = &syscall_personality }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant afs_syscall svc */ { .entry = &syscall_setfsuid16 }, { .entry = &syscall_setfsgid16 }, { .entry = &syscall_llseek }, @@ -173,10 +173,10 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_mremap }, { .entry = &syscall_setresuid16 }, { .entry = &syscall_getresuid16 }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 166 unused system call */ + { .entry = &syscall_ni_syscall }, /* Non-existant query_module svc */ { .entry = &syscall_poll }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant nfsservctl svc */ { .entry = &syscall_setresgid16 }, { .entry = &syscall_getresgid16 }, { .entry = &syscall_prctl }, @@ -195,8 +195,8 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_capset }, { .entry = &syscall_sigaltstack }, { .entry = &syscall_sendfile }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant getpmsg svc */ + { .entry = &syscall_ni_syscall }, /* Non-existant putpmsg svc */ { .entry = &syscall_vfork }, { .entry = &syscall_getrlimit }, { .entry = &syscall_mmap2 }, @@ -249,7 +249,7 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_sched_setaffinity }, { .entry = &syscall_sched_getaffinity }, { .entry = &syscall_tgkill }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 242 unused system call */ { .entry = &syscall_io_setup }, { .entry = &syscall_io_destroy }, { .entry = &syscall_io_getevents }, @@ -270,7 +270,7 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_clock_gettime }, { .entry = &syscall_clock_getres }, { .entry = &syscall_clock_nanosleep }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 263 unused system call */ { .entry = &syscall_fadvise64_64 }, /* s390_fadvise64_64 */ { .entry = &syscall_statfs64 }, { .entry = &syscall_fstatfs64 }, @@ -324,7 +324,7 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_fallocate}, /* s390_fallocate */ { .entry = &syscall_utimensat }, { .entry = &syscall_signalfd }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant timerfd svc */ { .entry = &syscall_eventfd }, { .entry = &syscall_timerfd_create }, { .entry = &syscall_timerfd_settime }, @@ -349,7 +349,7 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_setns }, { .entry = &syscall_process_vm_readv }, { .entry = &syscall_process_vm_writev }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* TODO: s390_runtime_instr */ { .entry = &syscall_kcmp }, { .entry = &syscall_finit_module }, { .entry = &syscall_sched_setattr }, @@ -363,8 +363,8 @@ struct syscalltable syscalls_s390[] = { #else { .entry = NULL }, #endif - { .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_write - { .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_read + { .entry = &syscall_ni_syscall }, /* TODO: s390_pci_mmio_write svc */ + { .entry = &syscall_ni_syscall }, /* TODO: s390_pci_mmio_read svc */ { .entry = &syscall_execveat }, { .entry = &syscall_userfaultfd }, { .entry = &syscall_membarrier }, @@ -385,4 +385,11 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_recvfrom }, { .entry = &syscall_recvmsg }, { .entry = &syscall_shutdown }, + { .entry = &syscall_ni_syscall }, /* TODO: mlock2 svc */ + { .entry = &syscall_ni_syscall }, /* TODO: copy_file_range svc */ + { .entry = &syscall_ni_syscall }, /* TODO: preadv2 svc */ + { .entry = &syscall_ni_syscall }, /* TODO: pwritev2 svc */ + { .entry = &syscall_ni_syscall }, /* TODO: s390_guarded_storage svc */ + { .entry = &syscall_ni_syscall }, /* TODO: statx svc */ + { .entry = &syscall_ni_syscall }, /* TODO: s390_sthyi svc */ }; diff --git a/include/syscalls-s390x.h b/include/syscalls-s390x.h index 6dbaffb37..333d649cb 100644 --- a/include/syscalls-s390x.h +++ b/include/syscalls-s390x.h @@ -7,7 +7,7 @@ #include "syscalls/syscalls.h" struct syscalltable syscalls_s390x[] = { - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 0 unused system call */ { .entry = &syscall_exit }, { .entry = &syscall_fork }, { .entry = &syscall_read }, @@ -20,29 +20,29 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_unlink }, { .entry = &syscall_execve }, { .entry = &syscall_chdir }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 13 unused system call */ { .entry = &syscall_mknod }, { .entry = &syscall_chmod }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 16 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 17 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 18 unused system call */ { .entry = &syscall_lseek }, { .entry = &syscall_getpid }, { .entry = &syscall_mount }, { .entry = &syscall_oldumount }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 23 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 24 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 25 unused system call */ { .entry = &syscall_ptrace }, { .entry = &syscall_alarm }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 28 unused system call */ { .entry = &syscall_pause }, { .entry = &syscall_utime }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 31 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 32 unused system call */ { .entry = &syscall_access }, { .entry = &syscall_nice }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 35 unused system call */ { .entry = &syscall_sync }, { .entry = &syscall_kill }, { .entry = &syscall_rename }, @@ -51,22 +51,22 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_dup }, { .entry = &syscall_pipe }, { .entry = &syscall_times }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 44 unused system call */ { .entry = &syscall_brk }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 46 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 47 unused system call */ { .entry = &syscall_signal }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 49 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 50 unused system call */ { .entry = &syscall_acct }, { .entry = &syscall_umount }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 53 unused system call */ { .entry = &syscall_ioctl }, { .entry = &syscall_fcntl }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 56 unused system call */ { .entry = &syscall_setpgid }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 58 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 59 unused system call */ { .entry = &syscall_umask }, { .entry = &syscall_chroot }, { .entry = &syscall_ustat }, @@ -75,40 +75,40 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_getpgrp }, { .entry = &syscall_setsid }, { .entry = &syscall_sigaction }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 68 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 69 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 70 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 71 unused system call */ { .entry = &syscall_sigsuspend }, { .entry = &syscall_sigpending }, { .entry = &syscall_sethostname }, { .entry = &syscall_setrlimit }, - { .entry = &syscall_getrlimit }, + { .entry = &syscall_ni_syscall }, /* No 76 unused system call */ { .entry = &syscall_getrusage }, { .entry = &syscall_gettimeofday }, { .entry = &syscall_settimeofday }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 80 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 81 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 82 unused system call */ { .entry = &syscall_symlink }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 84 unused system call */ { .entry = &syscall_readlink }, { .entry = &syscall_uselib }, { .entry = &syscall_swapon }, { .entry = &syscall_reboot }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 89 unused system call */ { .entry = &syscall_mmap }, /* old_mmap */ { .entry = &syscall_munmap }, { .entry = &syscall_truncate }, { .entry = &syscall_ftruncate }, { .entry = &syscall_fchmod }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 95 unused system call */ { .entry = &syscall_getpriority }, { .entry = &syscall_setpriority }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 98 unused system call */ { .entry = &syscall_statfs }, { .entry = &syscall_fstatfs }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant ioperm svc */ { .entry = &syscall_socketcall }, { .entry = &syscall_syslog }, { .entry = &syscall_setitimer }, @@ -116,11 +116,11 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_newstat }, { .entry = &syscall_newlstat }, { .entry = &syscall_newfstat }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 109 unused system call */ { .entry = &syscall_lookup_dcookie }, { .entry = &syscall_vhangup }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant idle svc */ + { .entry = &syscall_ni_syscall }, /* No 113 unused system call */ { .entry = &syscall_wait4 }, { .entry = &syscall_swapoff }, { .entry = &syscall_sysinfo }, @@ -130,24 +130,24 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_clone }, { .entry = &syscall_setdomainname }, { .entry = &syscall_newuname }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 123 unused system call */ { .entry = &syscall_adjtimex }, { .entry = &syscall_mprotect }, { .entry = &syscall_sigprocmask }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant create_module svc */ { .entry = &syscall_init_module }, { .entry = &syscall_delete_module }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant get_kernel_syms svc */ { .entry = &syscall_quotactl }, { .entry = &syscall_getpgid }, { .entry = &syscall_fchdir }, { .entry = &syscall_bdflush }, { .entry = &syscall_sysfs }, { .entry = &syscall_personality }, /* s390_personality */ - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_llseek }, + { .entry = &syscall_ni_syscall }, /* Non-existant afs_syscall svc */ + { .entry = &syscall_ni_syscall }, /* No 138 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 139 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 140 unused system call */ { .entry = &syscall_getdents }, { .entry = &syscall_select }, { .entry = &syscall_flock }, @@ -171,14 +171,14 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_sched_rr_get_interval }, { .entry = &syscall_nanosleep }, { .entry = &syscall_mremap }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 164 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 165 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 166 unused system call */ + { .entry = &syscall_ni_syscall }, /* Non-existant query_module svc */ { .entry = &syscall_poll }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant nfsservctl svc */ + { .entry = &syscall_ni_syscall }, /* No 170 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 171 unused system call */ { .entry = &syscall_prctl }, { .entry = &syscall_rt_sigreturn }, { .entry = &syscall_rt_sigaction }, @@ -189,22 +189,22 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_rt_sigsuspend }, { .entry = &syscall_pread64 }, { .entry = &syscall_pwrite64 }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 182 unused system call */ { .entry = &syscall_getcwd }, { .entry = &syscall_capget }, { .entry = &syscall_capset }, { .entry = &syscall_sigaltstack }, { .entry = &syscall_sendfile64 }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant getpmsg svc */ + { .entry = &syscall_ni_syscall }, /* Non-existant putpmsg svc */ { .entry = &syscall_vfork }, { .entry = &syscall_getrlimit }, - { .entry = &syscall_mmap2 }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 192 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 193 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 194 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 195 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 196 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 197 unused system call */ { .entry = &syscall_lchown }, { .entry = &syscall_getuid }, { .entry = &syscall_getgid }, @@ -228,9 +228,9 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_mincore }, { .entry = &syscall_madvise }, { .entry = &syscall_getdents64 }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 221 unused system call */ { .entry = &syscall_readahead }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 223 unused system call */ { .entry = &syscall_setxattr }, { .entry = &syscall_lsetxattr }, { .entry = &syscall_fsetxattr }, @@ -249,7 +249,7 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_sched_setaffinity }, { .entry = &syscall_sched_getaffinity }, { .entry = &syscall_tgkill }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 242 unused system call */ { .entry = &syscall_io_setup }, { .entry = &syscall_io_destroy }, { .entry = &syscall_io_getevents }, @@ -270,8 +270,8 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_clock_gettime }, { .entry = &syscall_clock_getres }, { .entry = &syscall_clock_nanosleep }, - { .entry = &syscall_ni_syscall }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* No 263 unused system call */ + { .entry = &syscall_ni_syscall }, /* No 264 unused system call */ { .entry = &syscall_statfs64 }, { .entry = &syscall_fstatfs64 }, { .entry = &syscall_remap_file_pages }, @@ -324,7 +324,7 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_fallocate }, { .entry = &syscall_utimensat }, { .entry = &syscall_signalfd }, - { .entry = &syscall_ni_syscall }, + { .entry = &syscall_ni_syscall }, /* Non-existant timerfd svc */ { .entry = &syscall_eventfd }, { .entry = &syscall_timerfd_create }, { .entry = &syscall_timerfd_settime }, @@ -363,7 +363,33 @@ struct syscalltable syscalls_s390x[] = { #else { .entry = NULL }, #endif - { .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_write - { .entry = &syscall_ni_syscall }, // TODO: syscall_s390_pci_mmio_read + { .entry = &syscall_ni_syscall }, /* TODO: s390_pci_mmio_write svc */ + { .entry = &syscall_ni_syscall }, /* TODO: s390_pci_mmio_read svc */ { .entry = &syscall_execveat }, + { .entry = &syscall_userfaultfd }, + { .entry = &syscall_membarrier }, + { .entry = &syscall_recvmmsg }, + { .entry = &syscall_sendmmsg }, + { .entry = &syscall_socket }, + { .entry = &syscall_socketpair }, + { .entry = &syscall_bind }, + { .entry = &syscall_connect }, + { .entry = &syscall_listen }, + { .entry = &syscall_accept4 }, + { .entry = &syscall_getsockopt }, + { .entry = &syscall_setsockopt }, + { .entry = &syscall_getsockname }, + { .entry = &syscall_getpeername }, + { .entry = &syscall_sendto }, + { .entry = &syscall_sendmsg }, + { .entry = &syscall_recvfrom }, + { .entry = &syscall_recvmsg }, + { .entry = &syscall_shutdown }, + { .entry = &syscall_ni_syscall }, /* TODO: mlock2 svc */ + { .entry = &syscall_ni_syscall }, /* TODO: copy_file_range svc */ + { .entry = &syscall_ni_syscall }, /* TODO: preadv2 svc */ + { .entry = &syscall_ni_syscall }, /* TODO: pwritev2 svc */ + { .entry = &syscall_ni_syscall }, /* TODO: s390_guarded_storage svc */ + { .entry = &syscall_ni_syscall }, /* TODO: statx svc */ + { .entry = &syscall_ni_syscall }, /* TODO: s390_sthyi svc */ }; From 0cac1c48150ee1f41ef99bf6573f794f22699227 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 6 Feb 2018 09:02:25 +0100 Subject: [PATCH 020/119] trinity: Add support for preadv2/pwritev2 svcs Add support for s390x (64 bit) and s390 (31 bit) support for system calls preadv2 and pwritev2. Signed-off-by: Thomas Richter --- include/syscalls-s390.h | 4 ++-- include/syscalls-s390x.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/syscalls-s390.h b/include/syscalls-s390.h index 83613edfc..1ca1a0fe6 100644 --- a/include/syscalls-s390.h +++ b/include/syscalls-s390.h @@ -387,8 +387,8 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_shutdown }, { .entry = &syscall_ni_syscall }, /* TODO: mlock2 svc */ { .entry = &syscall_ni_syscall }, /* TODO: copy_file_range svc */ - { .entry = &syscall_ni_syscall }, /* TODO: preadv2 svc */ - { .entry = &syscall_ni_syscall }, /* TODO: pwritev2 svc */ + { .entry = &syscall_preadv2 }, + { .entry = &syscall_pwritev2 }, { .entry = &syscall_ni_syscall }, /* TODO: s390_guarded_storage svc */ { .entry = &syscall_ni_syscall }, /* TODO: statx svc */ { .entry = &syscall_ni_syscall }, /* TODO: s390_sthyi svc */ diff --git a/include/syscalls-s390x.h b/include/syscalls-s390x.h index 333d649cb..6c546e1bb 100644 --- a/include/syscalls-s390x.h +++ b/include/syscalls-s390x.h @@ -387,8 +387,8 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_shutdown }, { .entry = &syscall_ni_syscall }, /* TODO: mlock2 svc */ { .entry = &syscall_ni_syscall }, /* TODO: copy_file_range svc */ - { .entry = &syscall_ni_syscall }, /* TODO: preadv2 svc */ - { .entry = &syscall_ni_syscall }, /* TODO: pwritev2 svc */ + { .entry = &syscall_preadv2 }, + { .entry = &syscall_pwritev2 }, { .entry = &syscall_ni_syscall }, /* TODO: s390_guarded_storage svc */ { .entry = &syscall_ni_syscall }, /* TODO: statx svc */ { .entry = &syscall_ni_syscall }, /* TODO: s390_sthyi svc */ From 37bf9f6ee3f138a89c60fe36425b5a69ddcadddc Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 6 Feb 2018 09:02:26 +0100 Subject: [PATCH 021/119] trinity: Add support for statx svc Add support for s390x (64 bit) and s390 (31 bit) support for system call statx. Signed-off-by: Thomas Richter --- include/syscalls-s390.h | 2 +- include/syscalls-s390x.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/syscalls-s390.h b/include/syscalls-s390.h index 1ca1a0fe6..27fbcce18 100644 --- a/include/syscalls-s390.h +++ b/include/syscalls-s390.h @@ -390,6 +390,6 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_preadv2 }, { .entry = &syscall_pwritev2 }, { .entry = &syscall_ni_syscall }, /* TODO: s390_guarded_storage svc */ - { .entry = &syscall_ni_syscall }, /* TODO: statx svc */ + { .entry = &syscall_statx }, { .entry = &syscall_ni_syscall }, /* TODO: s390_sthyi svc */ }; diff --git a/include/syscalls-s390x.h b/include/syscalls-s390x.h index 6c546e1bb..a3efa7db5 100644 --- a/include/syscalls-s390x.h +++ b/include/syscalls-s390x.h @@ -390,6 +390,6 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_preadv2 }, { .entry = &syscall_pwritev2 }, { .entry = &syscall_ni_syscall }, /* TODO: s390_guarded_storage svc */ - { .entry = &syscall_ni_syscall }, /* TODO: statx svc */ + { .entry = &syscall_statx }, { .entry = &syscall_ni_syscall }, /* TODO: s390_sthyi svc */ }; From 22d843e681c5deced6397e894269b6e235b8236a Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 6 Feb 2018 09:02:27 +0100 Subject: [PATCH 022/119] trinity: Add support for mlock2 svc Add support for s390x (64 bit) and s390 (31 bit) support for system call mlock2. Signed-off-by: Thomas Richter --- include/syscalls-s390.h | 2 +- include/syscalls-s390x.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/syscalls-s390.h b/include/syscalls-s390.h index 27fbcce18..f53e52896 100644 --- a/include/syscalls-s390.h +++ b/include/syscalls-s390.h @@ -385,7 +385,7 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_recvfrom }, { .entry = &syscall_recvmsg }, { .entry = &syscall_shutdown }, - { .entry = &syscall_ni_syscall }, /* TODO: mlock2 svc */ + { .entry = &syscall_mlock2 }, { .entry = &syscall_ni_syscall }, /* TODO: copy_file_range svc */ { .entry = &syscall_preadv2 }, { .entry = &syscall_pwritev2 }, diff --git a/include/syscalls-s390x.h b/include/syscalls-s390x.h index a3efa7db5..f62c6fab5 100644 --- a/include/syscalls-s390x.h +++ b/include/syscalls-s390x.h @@ -385,7 +385,7 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_recvfrom }, { .entry = &syscall_recvmsg }, { .entry = &syscall_shutdown }, - { .entry = &syscall_ni_syscall }, /* TODO: mlock2 svc */ + { .entry = &syscall_mlock2 }, { .entry = &syscall_ni_syscall }, /* TODO: copy_file_range svc */ { .entry = &syscall_preadv2 }, { .entry = &syscall_pwritev2 }, From 3d26b9ef9f14e68201726b57bfe8cf81d1ae1f69 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 6 Feb 2018 09:02:28 +0100 Subject: [PATCH 023/119] trinity: Add support for copy_file_range svc Add support for s390x (64 bit) and s390 (31 bit) support for system call copy_file_range. Signed-off-by: Thomas Richter --- include/syscalls-s390.h | 2 +- include/syscalls-s390x.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/syscalls-s390.h b/include/syscalls-s390.h index f53e52896..027a9fcd7 100644 --- a/include/syscalls-s390.h +++ b/include/syscalls-s390.h @@ -386,7 +386,7 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_recvmsg }, { .entry = &syscall_shutdown }, { .entry = &syscall_mlock2 }, - { .entry = &syscall_ni_syscall }, /* TODO: copy_file_range svc */ + { .entry = &syscall_copy_file_range }, { .entry = &syscall_preadv2 }, { .entry = &syscall_pwritev2 }, { .entry = &syscall_ni_syscall }, /* TODO: s390_guarded_storage svc */ diff --git a/include/syscalls-s390x.h b/include/syscalls-s390x.h index f62c6fab5..a3e26181c 100644 --- a/include/syscalls-s390x.h +++ b/include/syscalls-s390x.h @@ -386,7 +386,7 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_recvmsg }, { .entry = &syscall_shutdown }, { .entry = &syscall_mlock2 }, - { .entry = &syscall_ni_syscall }, /* TODO: copy_file_range svc */ + { .entry = &syscall_copy_file_range }, { .entry = &syscall_preadv2 }, { .entry = &syscall_pwritev2 }, { .entry = &syscall_ni_syscall }, /* TODO: s390_guarded_storage svc */ From b9a7bd002a384513f230ffa21cc785e7dbf32fdb Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 6 Feb 2018 09:02:29 +0100 Subject: [PATCH 024/119] trinity: Add support for readdir svc Add support for system call readdir on s390 (31 bit). Signed-off-by: Thomas Richter --- include/syscalls-s390.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/syscalls-s390.h b/include/syscalls-s390.h index 027a9fcd7..682d20305 100644 --- a/include/syscalls-s390.h +++ b/include/syscalls-s390.h @@ -96,7 +96,7 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_uselib }, { .entry = &syscall_swapon }, { .entry = &syscall_reboot }, - { .entry = &syscall_ni_syscall }, /* TODO: readdir systemcall */ + { .entry = &syscall_oldreaddir }, { .entry = &syscall_mmap }, /* old_mmap */ { .entry = &syscall_munmap }, { .entry = &syscall_truncate }, From 617b4960c05f64c2622fa4331bb3594930442f2d Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 13 Feb 2018 08:55:49 +0100 Subject: [PATCH 025/119] trinity: Add support for runtime_instr svc This patch adds support for the s390 specific system call runtime_instr() for 31 and 64 bit. Signed-off-by: Thomas Richter --- Makefile | 1 + include/syscalls-s390.h | 2 +- include/syscalls-s390x.h | 2 +- syscalls/s390x/runtime_instr.c | 25 +++++++++++++++++++++++++ syscalls/syscalls.h | 1 + 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 syscalls/s390x/runtime_instr.c diff --git a/Makefile b/Makefile index 786190649..93e3460d6 100644 --- a/Makefile +++ b/Makefile @@ -87,6 +87,7 @@ SYSCALLS_ARCH := $(shell case "$(MACHINE)" in \ syscalls/x86/x86_64/*.c;; \ (i?86*) echo syscalls/x86/*.c \ syscalls/x86/i386/*.c;; \ + (s390x*) echo syscalls/s390x/*.c ;; \ esac) VERSION_H := include/version.h diff --git a/include/syscalls-s390.h b/include/syscalls-s390.h index 682d20305..c02ced94a 100644 --- a/include/syscalls-s390.h +++ b/include/syscalls-s390.h @@ -349,7 +349,7 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_setns }, { .entry = &syscall_process_vm_readv }, { .entry = &syscall_process_vm_writev }, - { .entry = &syscall_ni_syscall }, /* TODO: s390_runtime_instr */ + { .entry = &syscall_runtime_instr }, /* s390_runtime_instr svc */ { .entry = &syscall_kcmp }, { .entry = &syscall_finit_module }, { .entry = &syscall_sched_setattr }, diff --git a/include/syscalls-s390x.h b/include/syscalls-s390x.h index a3e26181c..b955ceaa3 100644 --- a/include/syscalls-s390x.h +++ b/include/syscalls-s390x.h @@ -349,7 +349,7 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_setns }, { .entry = &syscall_process_vm_readv }, { .entry = &syscall_process_vm_writev }, - { .entry = &syscall_ni_syscall }, /* TODO: s390_runtime_instr */ + { .entry = &syscall_runtime_instr }, /* s390_runtime_instr svc */ { .entry = &syscall_kcmp }, { .entry = &syscall_finit_module }, { .entry = &syscall_sched_setattr }, diff --git a/syscalls/s390x/runtime_instr.c b/syscalls/s390x/runtime_instr.c new file mode 100644 index 000000000..aa1f75fb8 --- /dev/null +++ b/syscalls/s390x/runtime_instr.c @@ -0,0 +1,25 @@ +/* + * int runtime_instr(int on_off, int sig_nr) + */ + +#include "sanitise.h" + +#define S390_RUNTIME_INSTR_START 0x1 +#define S390_RUNTIME_INSTR_STOP 0x2 + +static unsigned long syscall_runtime_instr_arg1[] = { + 0, S390_RUNTIME_INSTR_START, S390_RUNTIME_INSTR_STOP, 3 +}; + +struct syscallentry syscall_runtime_instr = { + .name = "runtime_instr", + .num_args = 2, + .arg1name = "on_off", + .arg1type = ARG_LIST, + .arg1list = ARGLIST(syscall_runtime_instr_arg1), + .arg2name = "sig_nr", + .arg2type = ARG_RANGE, + .low2range = 0, + .hi2range = 128, + .rettype = RET_ZERO_SUCCESS +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 38819b378..2260bbf89 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -386,5 +386,6 @@ extern struct syscallentry syscall_pkey_mprotect; extern struct syscallentry syscall_pkey_alloc; extern struct syscallentry syscall_pkey_free; extern struct syscallentry syscall_statx; +extern struct syscallentry syscall_runtime_instr; unsigned int random_fcntl_setfl_flags(void); From b57df767a90fd082aefc83964a9f9f1732065bc8 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 13 Feb 2018 08:55:50 +0100 Subject: [PATCH 026/119] trinity: Add support for s390_pci_mmio_read and write Add support for s390 specific system calls s390_pci_mmio_read and 390_pci_mmio_write for 31 bit and 64 bit. Signed-off-by: Thomas Richter --- include/syscalls-s390.h | 4 +- include/syscalls-s390x.h | 4 +- syscalls/s390x/s390_pci_mmio.c | 70 ++++++++++++++++++++++++++++++++++ syscalls/syscalls.h | 2 + 4 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 syscalls/s390x/s390_pci_mmio.c diff --git a/include/syscalls-s390.h b/include/syscalls-s390.h index c02ced94a..a5a30c9ef 100644 --- a/include/syscalls-s390.h +++ b/include/syscalls-s390.h @@ -363,8 +363,8 @@ struct syscalltable syscalls_s390[] = { #else { .entry = NULL }, #endif - { .entry = &syscall_ni_syscall }, /* TODO: s390_pci_mmio_write svc */ - { .entry = &syscall_ni_syscall }, /* TODO: s390_pci_mmio_read svc */ + { .entry = &syscall_s390_pci_mmio_write }, + { .entry = &syscall_s390_pci_mmio_read }, { .entry = &syscall_execveat }, { .entry = &syscall_userfaultfd }, { .entry = &syscall_membarrier }, diff --git a/include/syscalls-s390x.h b/include/syscalls-s390x.h index b955ceaa3..e74caa146 100644 --- a/include/syscalls-s390x.h +++ b/include/syscalls-s390x.h @@ -363,8 +363,8 @@ struct syscalltable syscalls_s390x[] = { #else { .entry = NULL }, #endif - { .entry = &syscall_ni_syscall }, /* TODO: s390_pci_mmio_write svc */ - { .entry = &syscall_ni_syscall }, /* TODO: s390_pci_mmio_read svc */ + { .entry = &syscall_s390_pci_mmio_write }, + { .entry = &syscall_s390_pci_mmio_read }, { .entry = &syscall_execveat }, { .entry = &syscall_userfaultfd }, { .entry = &syscall_membarrier }, diff --git a/syscalls/s390x/s390_pci_mmio.c b/syscalls/s390x/s390_pci_mmio.c new file mode 100644 index 000000000..62566ce41 --- /dev/null +++ b/syscalls/s390x/s390_pci_mmio.c @@ -0,0 +1,70 @@ +/* + * int s390_pci_mmio_read(unsigned long mmio_addr, + * void *user_buffer, size_t length); + * int s390_pci_mmio_write(unsigned long mmio_addr, + * void *user_buffer, size_t length); + */ + +#include "arch.h" +#include "random.h" +#include "sanitise.h" + +/* + * Allocate buffer which fits the svc requirements: + * - length must be lower or equal to page size. + * - transfer must no cross page boundary. + */ +static void sanitise_s390_pci_mmio(struct syscallrecord *rec) +{ + size_t offset = rec->a1 % page_size; + + if (offset + rec->a3 > page_size) + rec->a3 = page_size - offset; + rec->a2 = (unsigned long)malloc(rec->a3); +} + +/* Allocate buffer and generate random data. */ +static void sanitise_s390_pci_mmio_write(struct syscallrecord *rec) +{ + sanitise_s390_pci_mmio(rec); + if (rec->a2) /* Buffer allocated */ + generate_rand_bytes((void *)rec->a2, rec->a3); +} + +/* Free buffer, freeptr takes care of NULL */ +static void post_s390_pci_mmio(struct syscallrecord *rec) +{ + freeptr(&rec->a2); +} + +struct syscallentry syscall_s390_pci_mmio_read = { + .name = "s390_pci_mmio_read", + .sanitise = sanitise_s390_pci_mmio, + .post = post_s390_pci_mmio, + .num_args = 3, + .arg1name = "mmio_addr", + .arg1type = ARG_UNDEFINED, + .arg2name = "user_buffer", + .arg2type = ARG_NON_NULL_ADDRESS, + .arg3name = "length", + .arg3type = ARG_RANGE, + .low3range = 0, + .hi3range = 1 << PAGE_SHIFT, + .rettype = RET_ZERO_SUCCESS +}; + +struct syscallentry syscall_s390_pci_mmio_write = { + .name = "s390_pci_mmio_write", + .sanitise = sanitise_s390_pci_mmio_write, + .post = post_s390_pci_mmio, + .num_args = 3, + .arg1name = "mmio_addr", + .arg1type = ARG_UNDEFINED, + .arg2name = "user_buffer", + .arg2type = ARG_NON_NULL_ADDRESS, + .arg3name = "length", + .arg3type = ARG_RANGE, + .low3range = 0, + .hi3range = 1 << PAGE_SHIFT, + .rettype = RET_ZERO_SUCCESS +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 2260bbf89..6564e22eb 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -387,5 +387,7 @@ extern struct syscallentry syscall_pkey_alloc; extern struct syscallentry syscall_pkey_free; extern struct syscallentry syscall_statx; extern struct syscallentry syscall_runtime_instr; +extern struct syscallentry syscall_s390_pci_mmio_write; +extern struct syscallentry syscall_s390_pci_mmio_read; unsigned int random_fcntl_setfl_flags(void); From 3bfc517c49676150cf84766b35f4764e237bc93d Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 13 Feb 2018 08:55:51 +0100 Subject: [PATCH 027/119] trinity: Add support for s390_guarded_storage svc Add support for s390 specific system call s390_guarded_storage for 31 bit and 64 bit. Signed-off-by: Thomas Richter --- include/syscalls-s390.h | 2 +- include/syscalls-s390x.h | 2 +- syscalls/s390x/s390_guarded_storage.c | 48 +++++++++++++++++++++++++++ syscalls/syscalls.h | 1 + 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 syscalls/s390x/s390_guarded_storage.c diff --git a/include/syscalls-s390.h b/include/syscalls-s390.h index a5a30c9ef..ad2f88c65 100644 --- a/include/syscalls-s390.h +++ b/include/syscalls-s390.h @@ -389,7 +389,7 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_copy_file_range }, { .entry = &syscall_preadv2 }, { .entry = &syscall_pwritev2 }, - { .entry = &syscall_ni_syscall }, /* TODO: s390_guarded_storage svc */ + { .entry = &syscall_s390_guarded_storage }, { .entry = &syscall_statx }, { .entry = &syscall_ni_syscall }, /* TODO: s390_sthyi svc */ }; diff --git a/include/syscalls-s390x.h b/include/syscalls-s390x.h index e74caa146..a83974e44 100644 --- a/include/syscalls-s390x.h +++ b/include/syscalls-s390x.h @@ -389,7 +389,7 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_copy_file_range }, { .entry = &syscall_preadv2 }, { .entry = &syscall_pwritev2 }, - { .entry = &syscall_ni_syscall }, /* TODO: s390_guarded_storage svc */ + { .entry = &syscall_s390_guarded_storage }, { .entry = &syscall_statx }, { .entry = &syscall_ni_syscall }, /* TODO: s390_sthyi svc */ }; diff --git a/syscalls/s390x/s390_guarded_storage.c b/syscalls/s390x/s390_guarded_storage.c new file mode 100644 index 000000000..290fe626d --- /dev/null +++ b/syscalls/s390x/s390_guarded_storage.c @@ -0,0 +1,48 @@ +/* + * int s390_guarded_storage(int command, struct gs_cb *gs_cb) + */ + +#include + +#include "random.h" +#include "sanitise.h" + +static unsigned long syscall_s390_guarded_storage_arg1[] = { + GS_ENABLE, + GS_DISABLE, + GS_SET_BC_CB, + GS_CLEAR_BC_CB, + GS_BROADCAST, + GS_BROADCAST + 1, + -1 +}; + +/* Allocate buffer and generate random data. */ +static void sanitise_s390_gs(struct syscallrecord *rec) +{ + size_t size = sizeof(struct gs_cb); + void *addr = malloc(size); + + if (addr) { + generate_rand_bytes(addr, size); + rec->a2 = (unsigned long)addr; + } +} + +/* Free buffer, freeptr takes care of NULL */ +static void post_s390_gs(struct syscallrecord *rec) +{ + freeptr(&rec->a2); +} + +struct syscallentry syscall_s390_guarded_storage = { + .name = "s390_guarded_storage", + .sanitise = sanitise_s390_gs, + .post = post_s390_gs, + .num_args = 2, + .arg1name = "command", + .arg1type = ARG_LIST, + .arg1list = ARGLIST(syscall_s390_guarded_storage_arg1), + .arg2name = "gs_cb", + .arg2type = ARG_NON_NULL_ADDRESS +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 6564e22eb..382711704 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -389,5 +389,6 @@ extern struct syscallentry syscall_statx; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; extern struct syscallentry syscall_s390_pci_mmio_read; +extern struct syscallentry syscall_s390_guarded_storage; unsigned int random_fcntl_setfl_flags(void); From 2989c11ce77bc7bec23da62987e2c3a0dd8a83c9 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Tue, 13 Feb 2018 08:55:52 +0100 Subject: [PATCH 028/119] trinity: Add support for s390_sthyi svc Add support for s390 specific system call s390_sthyi for 31 bit and 64 bit. Signed-off-by: Thomas Richter --- include/syscalls-s390.h | 2 +- include/syscalls-s390x.h | 2 +- syscalls/s390x/s390_sthyi.c | 60 +++++++++++++++++++++++++++++++++++++ syscalls/syscalls.h | 1 + 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 syscalls/s390x/s390_sthyi.c diff --git a/include/syscalls-s390.h b/include/syscalls-s390.h index ad2f88c65..077066509 100644 --- a/include/syscalls-s390.h +++ b/include/syscalls-s390.h @@ -391,5 +391,5 @@ struct syscalltable syscalls_s390[] = { { .entry = &syscall_pwritev2 }, { .entry = &syscall_s390_guarded_storage }, { .entry = &syscall_statx }, - { .entry = &syscall_ni_syscall }, /* TODO: s390_sthyi svc */ + { .entry = &syscall_s390_sthyi }, }; diff --git a/include/syscalls-s390x.h b/include/syscalls-s390x.h index a83974e44..66f3bc566 100644 --- a/include/syscalls-s390x.h +++ b/include/syscalls-s390x.h @@ -391,5 +391,5 @@ struct syscalltable syscalls_s390x[] = { { .entry = &syscall_pwritev2 }, { .entry = &syscall_s390_guarded_storage }, { .entry = &syscall_statx }, - { .entry = &syscall_ni_syscall }, /* TODO: s390_sthyi svc */ + { .entry = &syscall_s390_sthyi }, }; diff --git a/syscalls/s390x/s390_sthyi.c b/syscalls/s390x/s390_sthyi.c new file mode 100644 index 000000000..9bf488a9f --- /dev/null +++ b/syscalls/s390x/s390_sthyi.c @@ -0,0 +1,60 @@ +/* + * int s390_sthyi(unsigned long function_code, void *resp_buffer, + * uint64_t *return_code, unsigned long flags); + */ + +#include + +#include "arch.h" +#include "random.h" +#include "sanitise.h" + +static unsigned long syscall_s390_sthyi_arg1[] = { + STHYI_FC_CP_IFL_CAP, + -1 +}; + +static u64 syscall_s390_sthyi_return_code; + +/* Allocate buffer. */ +static void sanitise_s390_sthyi(struct syscallrecord *rec) +{ + size_t size = RAND_RANGE(0, page_size); + void *addr = size ? malloc(size) : NULL; + + rec->a2 = (unsigned long)addr; + + /* Use NULL, random or valid address */ + switch (rnd() % 3) { + case 0: rec->a3 = 0; + break; + case 1: rec->a3 = rnd(); + break; + case 2: rec->a3 = (unsigned long)&syscall_s390_sthyi_return_code; + break; + } +} + +/* Free buffer, freeptr takes care of NULL */ +static void post_s390_sthyi(struct syscallrecord *rec) +{ + freeptr(&rec->a2); +} + +struct syscallentry syscall_s390_sthyi = { + .name = "s390_sthyi", + .sanitise = sanitise_s390_sthyi, + .post = post_s390_sthyi, + .num_args = 4, + .arg1name = "function_code", + .arg1type = ARG_LIST, + .arg1list = ARGLIST(syscall_s390_sthyi_arg1), + .arg2name = "resp_buffer", + .arg2type = ARG_NON_NULL_ADDRESS, + .arg3name = "return_code", + .arg3type = ARG_ADDRESS, + .arg4name = "resp_buffer", + .arg4type = ARG_RANGE, + .low4range = 0, + .hi4range = 128 +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 382711704..3620c4eab 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -390,5 +390,6 @@ extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; extern struct syscallentry syscall_s390_pci_mmio_read; extern struct syscallentry syscall_s390_guarded_storage; +extern struct syscallentry syscall_s390_sthyi; unsigned int random_fcntl_setfl_flags(void); From 0f2a3280b1a8109d340c54c8302259ed20c31514 Mon Sep 17 00:00:00 2001 From: Dave Tian Date: Sun, 25 Feb 2018 15:18:52 -0500 Subject: [PATCH 029/119] add ioctl pattern for sgx driver --- ioctls/sgx.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 ioctls/sgx.c diff --git a/ioctls/sgx.c b/ioctls/sgx.c new file mode 100644 index 000000000..9070e9b3d --- /dev/null +++ b/ioctls/sgx.c @@ -0,0 +1,78 @@ +/* + * ioctl fuzzing for Intel SGX kernel driver (isgx) + * based on intel_sgx: Intel SGX Driver v0.10 + * Feb 25, 2018 + * root@davejingtian.org + */ +#include +#include +#include "ioctls.h" +#include "utils.h" + +#define SGX_MAGIC 0xA4 + +#define SGX_IOC_ENCLAVE_CREATE \ + _IOW(SGX_MAGIC, 0x00, struct sgx_enclave_create) +#define SGX_IOC_ENCLAVE_ADD_PAGE \ + _IOW(SGX_MAGIC, 0x01, struct sgx_enclave_add_page) +#define SGX_IOC_ENCLAVE_INIT \ + _IOW(SGX_MAGIC, 0x02, struct sgx_enclave_init) + +/** + * struct sgx_enclave_create - parameter structure for the + * %SGX_IOC_ENCLAVE_CREATE ioctl + * @src: address for the SECS page data + */ +struct sgx_enclave_create { + __u64 src; +} __attribute__((__packed__)); + +/** + * struct sgx_enclave_add_page - parameter structure for the + * %SGX_IOC_ENCLAVE_ADD_PAGE ioctl + * @addr: address in the ELRANGE + * @src: address for the page data + * @secinfo: address for the SECINFO data + * @mrmask: bitmask for the 256 byte chunks that are to be measured + */ +struct sgx_enclave_add_page { + __u64 addr; + __u64 src; + __u64 secinfo; + __u16 mrmask; +} __attribute__((__packed__)); + +/** + * struct sgx_enclave_init - parameter structure for the + * %SGX_IOC_ENCLAVE_INIT ioctl + * @addr: address in the ELRANGE + * @sigstruct: address for the page data + * @einittoken: EINITTOKEN + */ +struct sgx_enclave_init { + __u64 addr; + __u64 sigstruct; + __u64 einittoken; +} __attribute__((__packed__)); + + +static const struct ioctl sgx_ioctls[] = { + IOCTL(SGX_IOC_ENCLAVE_CREATE), + IOCTL(SGX_IOC_ENCLAVE_ADD_PAGE), + IOCTL(SGX_IOC_ENCLAVE_INIT), +}; + +static const char *const sgx_devs[] = { + "isgx", +}; + +static const struct ioctl_group sgx_grp = { + .devtype = DEV_CHAR, + .devs = sgx_devs, + .devs_cnt = ARRAY_SIZE(sgx_devs), + .sanitise = pick_random_ioctl, + .ioctls = sgx_ioctls, + .ioctls_cnt = ARRAY_SIZE(sgx_ioctls), +}; + +REG_IOCTL_GROUP(sgx_grp) From f96636751422db8a478b6dab38bfc31635ec347c Mon Sep 17 00:00:00 2001 From: Dave Tian Date: Mon, 26 Feb 2018 15:01:47 -0500 Subject: [PATCH 030/119] add sgxv2 modified: ioctls/sgx.c --- ioctls/sgx.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ioctls/sgx.c b/ioctls/sgx.c index 9070e9b3d..af22548d7 100644 --- a/ioctls/sgx.c +++ b/ioctls/sgx.c @@ -2,6 +2,8 @@ * ioctl fuzzing for Intel SGX kernel driver (isgx) * based on intel_sgx: Intel SGX Driver v0.10 * Feb 25, 2018 + * Add support for SGXv2 + * Feb 26, 2018 * root@davejingtian.org */ #include @@ -18,6 +20,18 @@ #define SGX_IOC_ENCLAVE_INIT \ _IOW(SGX_MAGIC, 0x02, struct sgx_enclave_init) +/* SGXv2 */ +#define SGX_IOC_ENCLAVE_EMODPR \ + _IOW(SGX_MAGIC, 0x09, struct sgx_modification_param) +#define SGX_IOC_ENCLAVE_MKTCS \ + _IOW(SGX_MAGIC, 0x0a, struct sgx_range) +#define SGX_IOC_ENCLAVE_TRIM \ + _IOW(SGX_MAGIC, 0x0b, struct sgx_range) +#define SGX_IOC_ENCLAVE_NOTIFY_ACCEPT \ + _IOW(SGX_MAGIC, 0x0c, struct sgx_range) +#define SGX_IOC_ENCLAVE_PAGE_REMOVE \ + _IOW(SGX_MAGIC, 0x0d, unsigned long) + /** * struct sgx_enclave_create - parameter structure for the * %SGX_IOC_ENCLAVE_CREATE ioctl @@ -56,10 +70,30 @@ struct sgx_enclave_init { } __attribute__((__packed__)); +/* SGXv2 */ +struct sgx_range { + unsigned long start_addr; + unsigned int nr_pages; +}; + +struct sgx_modification_param { + struct sgx_range range; + unsigned long flags; +}; + + + static const struct ioctl sgx_ioctls[] = { IOCTL(SGX_IOC_ENCLAVE_CREATE), IOCTL(SGX_IOC_ENCLAVE_ADD_PAGE), IOCTL(SGX_IOC_ENCLAVE_INIT), +#ifdef SGXv2 + IOCTL(SGX_IOC_ENCLAVE_EMODPR), + IOCTL(SGX_IOC_ENCLAVE_MKTCS), + IOCTL(SGX_IOC_ENCLAVE_TRIM), + IOCTL(SGX_IOC_ENCLAVE_NOTIFY_ACCEPT), + IOCTL(SGX_IOC_ENCLAVE_PAGE_REMOVE), +#endif }; static const char *const sgx_devs[] = { From c07cd60f942e2b4b96bd9a401d3129760a6ac308 Mon Sep 17 00:00:00 2001 From: Dave Tian Date: Wed, 28 Feb 2018 23:54:30 -0500 Subject: [PATCH 031/119] suppress packed warning --- ioctls/sgx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ioctls/sgx.c b/ioctls/sgx.c index af22548d7..1fcb01f8e 100644 --- a/ioctls/sgx.c +++ b/ioctls/sgx.c @@ -32,6 +32,7 @@ #define SGX_IOC_ENCLAVE_PAGE_REMOVE \ _IOW(SGX_MAGIC, 0x0d, unsigned long) +#pragma GCC diagnostic ignored "-Wpacked" /** * struct sgx_enclave_create - parameter structure for the * %SGX_IOC_ENCLAVE_CREATE ioctl @@ -80,8 +81,7 @@ struct sgx_modification_param { struct sgx_range range; unsigned long flags; }; - - +#pragma GCC diagnostic pop static const struct ioctl sgx_ioctls[] = { IOCTL(SGX_IOC_ENCLAVE_CREATE), From c93bb184ce996c4d77eefbae2ab0bf74f396ec45 Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Tue, 13 Mar 2018 06:53:06 +0200 Subject: [PATCH 032/119] memfd: fix build with glibc 2.27 glibc 2.27 added a wrapper for memfd_create(). This causes build failure: fds/memfd.c:19:12: error: static declaration of 'memfd_create' follows non-static declaration static int memfd_create(__unused__ const char *uname, __unused__ unsigned int flag) ^~~~~~~~~~~~ Don't use the local definition when the libc provides one. Signed-off-by: Baruch Siach --- configure | 23 +++++++++++++++++++++++ fds/memfd.c | 3 +++ 2 files changed, 26 insertions(+) diff --git a/configure b/configure index dc0a87d8c..c0166af33 100755 --- a/configure +++ b/configure @@ -288,6 +288,29 @@ else echo "#define USE_BTRFS 1" >> $CONFIGH fi +############################################################################################# +# Does glibc provide memfd_create() syscall wrapper +# +echo -n "[*] Checking if glibc provides memfd_create.. " +rm -f "$TMP" || exit 1 + +cat >"$TMP.c" << EOF +#include + +void main() +{ + memfd_create(); +} +EOF + +${CC} ${CFLAGS} "$TMP.c" -o "$TMP" &>"$TMP.log" +if [ ! -x "$TMP" ]; then + echo $RED "[NO]" $COL_RESET +else + echo $GREEN "[YES]" $COL_RESET + echo "#define USE_MEMFD_CREATE 1" >> $CONFIGH +fi + ############################################################################################# check_header linux/caif/caif_socket.h USE_CAIF diff --git a/fds/memfd.c b/fds/memfd.c index 210678e45..aaaac2f78 100644 --- a/fds/memfd.c +++ b/fds/memfd.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "fd.h" #include "memfd.h" @@ -16,6 +17,7 @@ #include "trinity.h" #include "udp.h" +#ifndef USE_MEMFD_CREATE static int memfd_create(__unused__ const char *uname, __unused__ unsigned int flag) { #ifdef SYS_memfd_create @@ -24,6 +26,7 @@ static int memfd_create(__unused__ const char *uname, __unused__ unsigned int fl return -ENOSYS; #endif } +#endif static void memfd_destructor(struct object *obj) { From b4c6f51481c6e2968c17d24a9fc299954af80ab4 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Sat, 10 Mar 2018 08:33:07 +0100 Subject: [PATCH 033/119] mlock: move MLOCK_ONFAULT to compat.h It got defined in our headers, so it causes build failures: syscalls/mlock.c:30:0: error: "MLOCK_ONFAULT" redefined [-Werror] #define MLOCK_ONFAULT 0x01 In file included from /usr/include/bits/mman-linux.h:115:0, from /usr/include/bits/mman.h:45, from /usr/include/sys/mman.h:41, from include/utils.h:4, from include/syscall.h:7, from include/child.h:7, from include/shm.h:4, from syscalls/mlock.c:6: /usr/include/bits/mman-shared.h:33:0: note: this is the location of the previous definition # define MLOCK_ONFAULT 1U So move it out of our way. Signed-off-by: Jiri Slaby --- include/compat.h | 5 +++++ syscalls/mlock.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/compat.h b/include/compat.h index fc9a1b95a..fce3a873e 100644 --- a/include/compat.h +++ b/include/compat.h @@ -1186,6 +1186,11 @@ struct kvm_get_htab_fd { #define POLL_BUSY_LOOP 0x8000 #endif +/* asm/mman.h */ +#ifndef MLOCK_ONFAULT +#define MLOCK_ONFAULT 0x01 +#endif + /* linux/nvme_ioctl.h */ #ifndef NVME_IOCTL_RESET #define NVME_IOCTL_RESET _IO('N', 0x44) diff --git a/syscalls/mlock.c b/syscalls/mlock.c index a08836ffd..6a2aef16e 100644 --- a/syscalls/mlock.c +++ b/syscalls/mlock.c @@ -7,6 +7,7 @@ #include "sanitise.h" #include "syscall.h" #include "trinity.h" +#include "compat.h" static void sanitise_mlock(__unused__ struct syscallrecord *rec) { @@ -27,8 +28,6 @@ struct syscallentry syscall_mlock = { * SYSCALL_DEFINE3(mlock2, unsigned long, start, size_t, len, int, flags) */ -#define MLOCK_ONFAULT 0x01 - struct syscallentry syscall_mlock2 = { .name = "mlock2", .num_args = 2, From 83e0d12b27c77aaef562aa042c497ab2b40b3901 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Tue, 13 Mar 2018 18:02:37 -0400 Subject: [PATCH 034/119] short-circuit log handle discovery if logging disabled --- output.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/output.c b/output.c index f14bedb5a..c9143f1de 100644 --- a/output.c +++ b/output.c @@ -114,6 +114,9 @@ void output_rendered_buffer(char *buffer) fflush(stdout); } + if (logging == LOGGING_DISABLED) + return; + log_handle = find_logfile_handle(); if (log_handle != NULL) { fprintf(log_handle, "%s", buffer); From 43e56140a547c82aacbcfbb77f36ba2dd211a938 Mon Sep 17 00:00:00 2001 From: Jeremy Bicha Date: Mon, 2 Apr 2018 13:47:33 -0400 Subject: [PATCH 035/119] Fix pthread undefined references --- server/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/Makefile b/server/Makefile index 79f5e7535..b0458252a 100644 --- a/server/Makefile +++ b/server/Makefile @@ -29,7 +29,7 @@ endif # Sometimes useful for debugging. more useful with clang than gcc. #CFLAGS += -fsanitize=address -LDFLAGS = -lpthread +LDFLAGS = -pthread V = @ Q = $(V:1=) From 1751b2bd2dc3ef4e1cac250c1c06813b2294baa9 Mon Sep 17 00:00:00 2001 From: Helge Deller Date: Fri, 13 Apr 2018 13:04:00 +0200 Subject: [PATCH 036/119] parisc-specific updates A few parisc-specific updates for trinity: - Update PTRACE_XXXREGS constants which are now available on parisc - Add more syscalls - MS_ASYNC, MS_SYNC and MS_INVALIDATE can have different values than x86_64 on alpha, parisc, xtensa and other platforms Signed-off-by: Helge Deller --- include/arch-parisc.h | 8 ++++---- include/syscalls-parisc.h | 7 +++++++ syscalls/msync.c | 6 ++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/arch-parisc.h b/include/arch-parisc.h index 6f47ae8f0..f3315e21f 100644 --- a/include/arch-parisc.h +++ b/include/arch-parisc.h @@ -16,9 +16,9 @@ #define PAGE_SHIFT 12 #define PTE_FILE_MAX_BITS (32 - 11) -#define PTRACE_GETREGS 0 -#define PTRACE_GETFPREGS 0 -#define PTRACE_SETREGS 0 -#define PTRACE_SETFPREGS 0 +#define PTRACE_GETREGS 18 +#define PTRACE_GETFPREGS 14 +#define PTRACE_SETREGS 19 +#define PTRACE_SETFPREGS 15 #define SYSCALLS syscalls_parisc diff --git a/include/syscalls-parisc.h b/include/syscalls-parisc.h index 2ac2d5f95..8365d6aee 100644 --- a/include/syscalls-parisc.h +++ b/include/syscalls-parisc.h @@ -354,4 +354,11 @@ struct syscalltable syscalls_parisc[] = { { .entry = NULL }, #endif { .entry = &syscall_execveat }, + { .entry = &syscall_membarrier }, + { .entry = &syscall_userfaultfd }, + { .entry = &syscall_mlock2 }, + { .entry = &syscall_copy_file_range }, + { .entry = &syscall_preadv2 }, + { .entry = &syscall_pwritev2 }, + { .entry = &syscall_statx }, }; diff --git a/syscalls/msync.c b/syscalls/msync.c index 95fbb06fc..8f879deea 100644 --- a/syscalls/msync.c +++ b/syscalls/msync.c @@ -8,9 +8,15 @@ #include "syscall.h" #include "trinity.h" +#if !defined(MS_ASYNC) #define MS_ASYNC 1 /* Sync memory asynchronously. */ +#endif +#if !defined(MS_SYNC) #define MS_SYNC 4 /* Synchronous memory sync. */ +#endif +#if !defined(MS_INVALIDATE) #define MS_INVALIDATE 2 /* Invalidate the caches. */ +#endif static void sanitise_msync(struct syscallrecord *rec) { From 6ecbf3eacc0dfdccfc42a63859946f815a831b4b Mon Sep 17 00:00:00 2001 From: Chunyu Hu Date: Fri, 8 Jun 2018 04:03:28 -0400 Subject: [PATCH 037/119] trinity: check pidstatfile before fclose Below run got segment fault. This is caused by fclose to a null pidstatfile. Fix by checking it before executing fclose on it. trinity -csplice,move_pages -q -N 20 Signed-off-by: Chunyu Hu --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 9cbd56799..0e2d3f32b 100644 --- a/main.c +++ b/main.c @@ -566,8 +566,8 @@ static void handle_childsig(int childno, int childstatus, bool stop) log_child_signalled(childno, pid, WTERMSIG(childstatus), child->op_nr); } reap_child(shm->children[childno]); - - fclose(child->pidstatfile); + if (child->pidstatfile) + fclose(child->pidstatfile); child->pidstatfile = NULL; replace_child(childno); From 1b2d43cb383cef86a05acb2df046ce5e9b17a7fe Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Fri, 8 Jun 2018 06:05:26 +0300 Subject: [PATCH 038/119] configure: fix build with kernel headers v4.17+ Kernel v4.17 removed the linux/irda.h header. Skip the irda test when this header is missing. Signed-off-by: Baruch Siach --- configure | 1 + net/proto-irda.c | 6 +++++- net/protocols.c | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/configure b/configure index c0166af33..944c8cf77 100755 --- a/configure +++ b/configure @@ -316,6 +316,7 @@ fi check_header linux/caif/caif_socket.h USE_CAIF check_header linux/fsmap.h USE_FSMAP check_header linux/if_alg.h USE_IF_ALG +check_header linux/irda.h USE_IRDA check_header linux/rds.h USE_RDS check_header linux/vfio.h USE_VFIO check_header drm/drm.h USE_DRM diff --git a/net/proto-irda.c b/net/proto-irda.c index 02d51bcd2..264e36dfa 100644 --- a/net/proto-irda.c +++ b/net/proto-irda.c @@ -4,13 +4,15 @@ #include /* old irda.h does not include something which defines sa_family_t */ #include -#include #include #include "net.h" #include "random.h" #include "utils.h" // RAND_ARRAY #include "compat.h" +#ifdef USE_IRDA +#include + static void irda_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen) { struct sockaddr_irda *irda; @@ -53,3 +55,5 @@ const struct netproto proto_irda = { .valid_triplets = irda_triplets, .nr_triplets = ARRAY_SIZE(irda_triplets), }; + +#endif diff --git a/net/protocols.c b/net/protocols.c index 90a60affe..87acf85c7 100644 --- a/net/protocols.c +++ b/net/protocols.c @@ -26,7 +26,9 @@ const struct protoptr net_protocols[TRINITY_PF_MAX] = { #ifdef USE_RDS [PF_RDS] = { .proto = &proto_rds }, #endif +#ifdef USE_IRDA [PF_IRDA] = { .proto = &proto_irda }, +#endif [PF_LLC] = { .proto = &proto_llc }, [PF_CAN] = { .proto = &proto_can }, [PF_TIPC] = { .proto = &proto_tipc }, From a5f32b9714613404e9f4699aaaad720f2bb033b4 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Thu, 23 Aug 2018 22:28:49 +0000 Subject: [PATCH 039/119] Check if VIDIOC_RESERVED is defined. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VIDIOC_RESERVED was removed in Linux 4.19. commit ea8532daee31bc72abfbc9ca7a43cbec0f6c05af Author: Mauro Carvalho Chehab Date: Wed May 30 11:07:05 2018 -0400 media: videodev2: get rid of VIDIOC_RESERVED While this ioctl is there at least since Kernel 2.6.12-rc2, it was never used by any upstream driver. Get rid of it. Signed-off-by: Mauro Carvalho Chehab This patch fixes this build error. CC ioctls/videodev2.o In file included from ioctls/videodev2.c:4: ioctls/videodev2.c:8:8: error: ‘VIDIOC_RESERVED’ undeclared here (not in a function); did you mean ‘VIDIOC_G_STD’? IOCTL(VIDIOC_RESERVED), ^~~~~~~~~~~~~~~ include/ioctls.h:53:15: note: in definition of macro ‘IOCTL’ { .request = _request, .name = #_request, } ^~~~~~~~ Signed-off-by: Vinson Lee --- ioctls/videodev2.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ioctls/videodev2.c b/ioctls/videodev2.c index f7183f298..67089abf7 100644 --- a/ioctls/videodev2.c +++ b/ioctls/videodev2.c @@ -5,7 +5,9 @@ static const struct ioctl videodev2_ioctls[] = { IOCTL(VIDIOC_QUERYCAP), +#ifdef VIDIOC_RESERVED IOCTL(VIDIOC_RESERVED), +#endif IOCTL(VIDIOC_ENUM_FMT), IOCTL(VIDIOC_G_FMT), IOCTL(VIDIOC_S_FMT), From 9f6f9f916da3b42cef2e7c30101ff4b0397df736 Mon Sep 17 00:00:00 2001 From: Praveen K Pandey Date: Fri, 21 Sep 2018 11:16:12 +0530 Subject: [PATCH 040/119] Fixed trinity compile issue as on gcc gcc (Ubuntu 8.2.0-6ubuntu1) 8.2.0 it failed as -Werror=format-overflow= while assigning a array variable as size over flow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this patch address that issue to increase array size how much it require LOG: syscalls/perf_event_open.c: In function ‘init_pmus’: syscalls/perf_event_open.c:332:24: error: ‘/type’ directive writing 5 bytes into a region of size between 1 and 8192 [-Werror=format-overflow=] sprintf(temp_name,"%s/type",dir_name); ^~~~~ In file included from /usr/include/stdio.h:873, from include/list.h:3, from include/maps.h:5, from syscalls/perf_event_open.c:13: /usr/include/powerpc64le-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 6 and 8197 bytes into a destination of size 8192 return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __bos (__s), __fmt, __va_arg_pack ()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ syscalls/perf_event_open.c:345:26: error: ‘/format’ directive writing 7 bytes into a region of size between 1 and 8192 [-Werror=format-overflow=] sprintf(format_name,"%s/format",dir_name); ^~~~~~~ In file included from /usr/include/stdio.h:873, from include/list.h:3, from include/maps.h:5, from syscalls/perf_event_open.c:13: /usr/include/powerpc64le-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 8 and 8199 bytes into a destination of size 8192 return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __bos (__s), __fmt, __va_arg_pack ()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ syscalls/perf_event_open.c:382:26: error: ‘/format/’ directive writing 8 bytes into a region of size between 1 and 8192 [-Werror=format-overflow=] sprintf(temp_name,"%s/format/%s", ^~~~~~~~ In file included from /usr/include/stdio.h:873, from include/list.h:3, from include/maps.h:5, from syscalls/perf_event_open.c:13: /usr/include/powerpc64le-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 9 and 8455 bytes into a destination of size 8192 return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __bos (__s), __fmt, __va_arg_pack ()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ syscalls/perf_event_open.c:405:25: error: ‘/events’ directive writing 7 bytes into a region of size between 1 and 8192 [-Werror=format-overflow=] sprintf(event_name,"%s/events",dir_name); ^~~~~~~ In file included from /usr/include/stdio.h:873, from include/list.h:3, from include/maps.h:5, from syscalls/perf_event_open.c:13: /usr/include/powerpc64le-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 8 and 8199 bytes into a destination of size 8192 return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __bos (__s), __fmt, __va_arg_pack ()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ syscalls/perf_event_open.c:443:26: error: ‘/events/’ directive writing 8 bytes into a region of size between 1 and 8192 [-Werror=format-overflow=] sprintf(temp_name,"%s/events/%s", ^~~~~~~~ In file included from /usr/include/stdio.h:873, from include/list.h:3, from include/maps.h:5, from syscalls/perf_event_open.c:13: /usr/include/powerpc64le-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 9 and 8455 bytes into a destination of size 8192 return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __bos (__s), __fmt, __va_arg_pack ()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make: *** [Makefile:131: syscalls/perf_event_open.o] Error 1 Signed-off-by: Praveen K Pandey --- syscalls/perf_event_open.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/syscalls/perf_event_open.c b/syscalls/perf_event_open.c index 10106b592..517328de3 100644 --- a/syscalls/perf_event_open.c +++ b/syscalls/perf_event_open.c @@ -278,10 +278,10 @@ static int init_pmus(void) { DIR *dir,*event_dir,*format_dir; struct dirent *entry,*event_entry,*format_entry; char dir_name[BUFSIZ] = ""; - char event_name[BUFSIZ] = ""; + char event_name[BUFSIZ+7] = ""; char event_value[BUFSIZ] = ""; - char temp_name[BUFSIZ] = ""; - char format_name[BUFSIZ] = ""; + char temp_name[BUFSIZ*2] = ""; + char format_name[BUFSIZ+7] = ""; char format_value[BUFSIZ] = ""; int type,pmu_num=0,format_num=0,generic_num=0; FILE *fff; From 62fe9d014e3378ea1b93accff3f0ddc8eb8c9535 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 24 Jan 2019 11:23:59 -0500 Subject: [PATCH 041/119] add skeletons for io_pgetevents & rseq --- syscalls/io_pgetevents.c | 25 +++++++++++++++++++++++++ syscalls/rseq.c | 27 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 syscalls/io_pgetevents.c create mode 100644 syscalls/rseq.c diff --git a/syscalls/io_pgetevents.c b/syscalls/io_pgetevents.c new file mode 100644 index 000000000..22f67a23d --- /dev/null +++ b/syscalls/io_pgetevents.c @@ -0,0 +1,25 @@ +/* + * SYSCALL_DEFINE6(io_pgetevents, + * aio_context_t, ctx_id, + * long, min_nr, + * long, nr, + * struct io_event __user *, events, + * struct __kernel_timespec __user *, timeout, + * const struct __aio_sigset __user *, usig) + */ + +#include "syscall.h" + +struct syscallentry syscall_io_pgetevents = { + .name = "io_pgetevents,", + .num_args = 6, + + .arg1name = "ctx_id", + .arg2name = "min_nr", + .arg2type = ARG_LEN, + .arg3name = "nr", + .arg3type = ARG_LEN, + .arg4name = "events", + .arg5name = "timeout", + .arg6name = "usig", +}; diff --git a/syscalls/rseq.c b/syscalls/rseq.c new file mode 100644 index 000000000..f3dd1a11a --- /dev/null +++ b/syscalls/rseq.c @@ -0,0 +1,27 @@ +/* + * SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len, + * int, flags, u32, sig) + */ + +#include "syscall.h" + +enum rseq_flags { + RSEQ_FLAG_UNREGISTER = (1 << 0), +}; + +static unsigned long rseq_flags[] = { + RSEQ_FLAG_UNREGISTER, +}; + +struct syscallentry syscall_rseq = { + .name = "rseq,", + .num_args = 4, + + .arg1name = "rseq", + .arg2name = "rseq_len", + .arg2type = ARG_LEN, + .arg3name = "flags", + .arg3type = ARG_LIST, + .arg3list = ARGLIST(rseq_flags), + .arg4name = "sig", +}; From 3c1c657cf6e48d49b9e13d67b648e1927db1e617 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 24 Jan 2019 11:28:18 -0500 Subject: [PATCH 042/119] Silence spew from fds/bpf.c There's probably a better way to do this, but meh --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 93e3460d6..0b838c1e0 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,8 @@ CFLAGS += -Wwrite-strings CFLAGS += -Wno-format-nonliteral CFLAGS += -Wstrict-prototypes -Wmissing-prototypes CFLAGS += -fsigned-char +# BPF spew. +CFLAGS += -Wno-missing-field-initializers # needed for show_backtrace() to work correctly. LDFLAGS += -rdynamic From 048a4e3cfbdb2967fc77e116cc5153ddc03017d6 Mon Sep 17 00:00:00 2001 From: Baruch Siach Date: Wed, 12 Dec 2018 20:52:50 +0200 Subject: [PATCH 043/119] proto-rds: include libc network headers first To avoid collisions between libc networking headers and header kernels the libc headers must appear first in the list of headers. This fixes a build issue with kernel headers v4.19: In file included from include/net.h:5:0, from net/proto-rds.c:6: .../sysroot/usr/include/netinet/in.h:23:8: error: redefinition of 'struct in6_addr' struct in6_addr { ^~~~~~~~ In file included from .../sysroot/usr/include/linux/rds.h:40:0, from net/proto-rds.c:4: .../sysroot/usr/include/linux/in6.h:33:8: note: originally defined here struct in6_addr { ^~~~~~~~ Signed-off-by: Baruch Siach --- net/proto-rds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/proto-rds.c b/net/proto-rds.c index c8ff22f88..06e36e82d 100644 --- a/net/proto-rds.c +++ b/net/proto-rds.c @@ -1,12 +1,12 @@ #ifdef USE_RDS #include #include -#include #include #include "net.h" #include "compat.h" #include "random.h" #include "utils.h" // RAND_ARRAY +#include static void rds_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen) { From 78830fbf267b3f542c4b4bcf89c30ec93b254845 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 24 Jan 2019 12:43:41 -0500 Subject: [PATCH 044/119] Compile fix missing bits of commit that added the new syscalls. Committing in the wrong dir considered harmful --- include/syscalls-x86_64.h | 2 ++ syscalls/syscalls.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index e225492ca..6089b2fdc 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -344,4 +344,6 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_pkey_alloc }, { .entry = &syscall_pkey_free }, { .entry = &syscall_statx }, + { .entry = &syscall_io_pgetevents }, + { .entry = &syscall_rseq }, }; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 3620c4eab..6ed9c2362 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -386,6 +386,9 @@ extern struct syscallentry syscall_pkey_mprotect; extern struct syscallentry syscall_pkey_alloc; extern struct syscallentry syscall_pkey_free; extern struct syscallentry syscall_statx; +extern struct syscallentry syscall_io_pgetevents; +extern struct syscallentry syscall_rseq; + extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; extern struct syscallentry syscall_s390_pci_mmio_read; From 865ac5d832f23f0c24975b864fdc35a0b87ceaa2 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 24 Jan 2019 15:42:13 -0500 Subject: [PATCH 045/119] 1.9 release --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0b838c1e0..10a6d1a46 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION="1.9pre" +VERSION="1.9" ifeq (,$(findstring pre,$(VERSION))) DEVEL = 0 From 865d3fc2e9d402bf5c213706dc97939569fd606b Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 24 Jan 2019 15:43:11 -0500 Subject: [PATCH 046/119] Begin 1.10 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 10a6d1a46..66ac43917 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION="1.9" +VERSION="1.10pre" ifeq (,$(findstring pre,$(VERSION))) DEVEL = 0 From d9bd3f7e65a099d2538047bd6ca053ba04b61829 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Fri, 14 Jun 2019 12:14:17 -0400 Subject: [PATCH 047/119] strncpy -> memcpy --- fds/memfd.c | 2 +- mm/maps.c | 2 +- pathnames.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fds/memfd.c b/fds/memfd.c index aaaac2f78..f72a98fa8 100644 --- a/fds/memfd.c +++ b/fds/memfd.c @@ -45,7 +45,7 @@ static void memfd_dump(struct object *obj, bool global) init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_MEMFD, global, obj); objmsg.fd = mo->fd; len = strlen(mo->name); - strncpy(objmsg.name, mo->name, len); + memcpy(objmsg.name, mo->name, len); objmsg.flags = mo->flags; sendudp((char *) &objmsg, sizeof(objmsg)); } diff --git a/mm/maps.c b/mm/maps.c index c237c0006..c5e1e6c09 100644 --- a/mm/maps.c +++ b/mm/maps.c @@ -72,7 +72,7 @@ void map_dump(struct object *obj, bool global) init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_MAP, global, obj); objmsg.start = m->ptr; len = strlen(m->name); - strncpy(objmsg.name, m->name, len); + memcpy(objmsg.name, m->name, len); memset(objmsg.name + len, 0, MAPS_NAME_MAX_LEN - len); objmsg.prot = m->prot; objmsg.type = m->type; diff --git a/pathnames.c b/pathnames.c index 2d5180ad5..220ce407b 100644 --- a/pathnames.c +++ b/pathnames.c @@ -295,13 +295,13 @@ const char * generate_pathname(void) len = strlen(pathname); if (RAND_BOOL()) - (void) strncpy(newpath, pathname, len); + (void) memcpy(newpath, pathname, len); else { if (len < MAX_PATH_LEN - 2) { /* make it look relative to cwd */ newpath[0] = '.'; newpath[1] = '/'; - (void) strncpy(newpath + 2, pathname, len); + (void) memcpy(newpath + 2, pathname, len); len += 2; } } From 313d5a89bdd8694b6cd7582cb6873d53ebd69a47 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Fri, 14 Jun 2019 12:36:38 -0400 Subject: [PATCH 048/119] cppcheck fixes --- pathnames.c | 2 +- syscalls/mlockall.c | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/pathnames.c b/pathnames.c index 220ce407b..ab82cf5ae 100644 --- a/pathnames.c +++ b/pathnames.c @@ -117,7 +117,7 @@ static void add_to_namelist(const char *name) int check_stat_file(const struct stat *sb) { - int openflag; + int openflag = 0; bool set_read = FALSE; bool set_write = FALSE; uid_t target_uid = orig_uid; diff --git a/syscalls/mlockall.c b/syscalls/mlockall.c index 5f7ea8738..cc8777a84 100644 --- a/syscalls/mlockall.c +++ b/syscalls/mlockall.c @@ -18,19 +18,6 @@ #define MCL_ONFAULT 4 #endif -static void sanitise_mlockall(struct syscallrecord *rec) -{ - if (rec->a1 != 0) - return; - - /* - * There are two invalid bit patterns for MCL flags, 0, and MCL_ONFAULT - * alone. All other combinations should be valid. - */ - while (rec->a1 == 0 || rec->a1 == MCL_ONFAULT) - rec->a1 = (RAND_BYTE() & 0x07); -} - static unsigned long mlockall_flags[] = { MCL_CURRENT, MCL_FUTURE, MCL_ONFAULT, }; @@ -42,5 +29,4 @@ struct syscallentry syscall_mlockall = { .arg1type = ARG_LIST, .arg1list = ARGLIST(mlockall_flags), .group = GROUP_VM, - .sanitise = sanitise_mlockall, }; From 2d0c1817b57022072d2b7dae9ad8f1ac3127cd13 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Fri, 14 Jun 2019 12:40:20 -0400 Subject: [PATCH 049/119] memfd build fixes for modern glibc also add MFD_HUGETLB --- fds/memfd.c | 5 ++++- include/memfd.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fds/memfd.c b/fds/memfd.c index f72a98fa8..e3334a1d3 100644 --- a/fds/memfd.c +++ b/fds/memfd.c @@ -18,6 +18,8 @@ #include "udp.h" #ifndef USE_MEMFD_CREATE + +#ifndef MFD_ALLOW_SEALING static int memfd_create(__unused__ const char *uname, __unused__ unsigned int flag) { #ifdef SYS_memfd_create @@ -27,6 +29,7 @@ static int memfd_create(__unused__ const char *uname, __unused__ unsigned int fl #endif } #endif +#endif static void memfd_destructor(struct object *obj) { @@ -58,7 +61,7 @@ static int open_memfd_fds(void) 0, MFD_CLOEXEC, MFD_CLOEXEC | MFD_ALLOW_SEALING, - MFD_ALLOW_SEALING, + MFD_ALLOW_SEALING, MFD_HUGETLB, }; head = get_objhead(OBJ_GLOBAL, OBJ_FD_MEMFD); diff --git a/include/memfd.h b/include/memfd.h index 60f6b8b2f..cf3bdb94a 100644 --- a/include/memfd.h +++ b/include/memfd.h @@ -3,6 +3,7 @@ #ifndef MFD_CLOEXEC #define MFD_CLOEXEC 0x0001U #define MFD_ALLOW_SEALING 0x0002U +#define MFD_HUGETLB 0x0004U #endif // FIXME: Keep all this here until glibc supports it. From 930cbe37d6334f26facf3733f4fd2ac1c5d4bbc8 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 10:39:58 -0400 Subject: [PATCH 050/119] Add PF_XDP support Pointed out by Chunyu-Hu at https://github.com/kernelslacker/trinity/pull/30 --- net/proto-xdp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 net/proto-xdp.c diff --git a/net/proto-xdp.c b/net/proto-xdp.c new file mode 100644 index 000000000..b27155eab --- /dev/null +++ b/net/proto-xdp.c @@ -0,0 +1,12 @@ +#include "net.h" +#include "compat.h" + +static struct socket_triplet xdp_triplet[] = { + { .family = PF_XDP, .protocol = 0, .type = SOCK_RAW }, +}; + +const struct netproto proto_xdp = { + .name = "xdp", + .valid_triplets = xdp_triplet, + .nr_triplets = ARRAY_SIZE(xdp_triplet), +}; From 8412f260cff0e00aa6c639a9fc99ce708cb6a2b6 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 11:35:03 -0400 Subject: [PATCH 051/119] commit the additional PF_XDP bits --- include/compat.h | 4 ++++ include/net.h | 3 ++- net/protocols.c | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/compat.h b/include/compat.h index fce3a873e..f8be7083a 100644 --- a/include/compat.h +++ b/include/compat.h @@ -241,6 +241,10 @@ enum { #define PF_SMC 43 #endif +#ifndef PF_XDP +#define PF_XDP 44 +#endif + #ifndef NFC_SOCKPROTO_RAW #define NFC_SOCKPROTO_RAW 0 #endif diff --git a/include/net.h b/include/net.h index 6a535be21..99d55363f 100644 --- a/include/net.h +++ b/include/net.h @@ -15,7 +15,7 @@ extern unsigned int specific_domain; /* glibc headers might be older than the kernel, so chances are we know * about more protocols than glibc does. So we define our own PF_MAX */ -#define TRINITY_PF_MAX 44 +#define TRINITY_PF_MAX 45 #define PF_NOHINT (-1) @@ -99,6 +99,7 @@ extern const struct netproto proto_phonet; extern const struct netproto proto_kcm; extern const struct netproto proto_qipcrtr; extern const struct netproto proto_smc; +extern const struct netproto proto_xdp; /* bpf */ void bpf_gen_filter(unsigned long **addr, unsigned long *addrlen); diff --git a/net/protocols.c b/net/protocols.c index 87acf85c7..ea64d5f5d 100644 --- a/net/protocols.c +++ b/net/protocols.c @@ -57,4 +57,5 @@ const struct protoptr net_protocols[TRINITY_PF_MAX] = { [PF_KCM] = { .proto = &proto_kcm }, [PF_QIPCRTR] = { .proto = &proto_qipcrtr }, [PF_SMC] = { .proto = &proto_smc }, + [PF_XDP] = { .proto = &proto_xdp }, }; From c0b44d0c189c17d9ba86ff88b0c720a1f1e8c811 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 12:10:06 -0400 Subject: [PATCH 052/119] Add pidfd_send_signal ugh, syscall tables are sparse now ? ugh. --- include/syscalls-x86_64.h | 92 +++++++++++++++++++++++++++++++++++- syscalls/pidfd_send_signal.c | 21 ++++++++ syscalls/syscalls.h | 1 + 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 syscalls/pidfd_send_signal.c diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index 6089b2fdc..831ed4819 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -345,5 +345,95 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_pkey_free }, { .entry = &syscall_statx }, { .entry = &syscall_io_pgetevents }, - { .entry = &syscall_rseq }, + { .entry = &syscall_rseq }, // 334 + { .entry = NULL }, // 335 + { .entry = NULL }, // 336 + { .entry = NULL }, // 337 + { .entry = NULL }, // 338 + { .entry = NULL }, // 339 + { .entry = NULL }, // 340 + { .entry = NULL }, // 341 + { .entry = NULL }, // 342 + { .entry = NULL }, // 343 + { .entry = NULL }, // 344 + { .entry = NULL }, // 345 + { .entry = NULL }, // 346 + { .entry = NULL }, // 347 + { .entry = NULL }, // 348 + { .entry = NULL }, // 349 + { .entry = NULL }, // 350 + { .entry = NULL }, // 351 + { .entry = NULL }, // 352 + { .entry = NULL }, // 353 + { .entry = NULL }, // 354 + { .entry = NULL }, // 355 + { .entry = NULL }, // 356 + { .entry = NULL }, // 357 + { .entry = NULL }, // 358 + { .entry = NULL }, // 359 + { .entry = NULL }, // 360 + { .entry = NULL }, // 361 + { .entry = NULL }, // 362 + { .entry = NULL }, // 363 + { .entry = NULL }, // 364 + { .entry = NULL }, // 365 + { .entry = NULL }, // 366 + { .entry = NULL }, // 367 + { .entry = NULL }, // 368 + { .entry = NULL }, // 369 + { .entry = NULL }, // 370 + { .entry = NULL }, // 371 + { .entry = NULL }, // 372 + { .entry = NULL }, // 373 + { .entry = NULL }, // 374 + { .entry = NULL }, // 375 + { .entry = NULL }, // 376 + { .entry = NULL }, // 377 + { .entry = NULL }, // 378 + { .entry = NULL }, // 379 + { .entry = NULL }, // 380 + { .entry = NULL }, // 381 + { .entry = NULL }, // 382 + { .entry = NULL }, // 383 + { .entry = NULL }, // 384 + { .entry = NULL }, // 385 + { .entry = NULL }, // 386 + { .entry = NULL }, // 387 + { .entry = NULL }, // 388 + { .entry = NULL }, // 389 + { .entry = NULL }, // 390 + { .entry = NULL }, // 391 + { .entry = NULL }, // 392 + { .entry = NULL }, // 393 + { .entry = NULL }, // 394 + { .entry = NULL }, // 395 + { .entry = NULL }, // 396 + { .entry = NULL }, // 397 + { .entry = NULL }, // 398 + { .entry = NULL }, // 399 + { .entry = NULL }, // 400 + { .entry = NULL }, // 401 + { .entry = NULL }, // 402 + { .entry = NULL }, // 403 + { .entry = NULL }, // 404 + { .entry = NULL }, // 405 + { .entry = NULL }, // 406 + { .entry = NULL }, // 407 + { .entry = NULL }, // 408 + { .entry = NULL }, // 409 + { .entry = NULL }, // 400 + { .entry = NULL }, // 411 + { .entry = NULL }, // 412 + { .entry = NULL }, // 413 + { .entry = NULL }, // 414 + { .entry = NULL }, // 415 + { .entry = NULL }, // 416 + { .entry = NULL }, // 417 + { .entry = NULL }, // 418 + { .entry = NULL }, // 419 + { .entry = NULL }, // 420 + { .entry = NULL }, // 421 + { .entry = NULL }, // 422 + { .entry = NULL }, // 423 + { .entry = &syscall_pidfd_send_signal }, // 424 }; diff --git a/syscalls/pidfd_send_signal.c b/syscalls/pidfd_send_signal.c new file mode 100644 index 000000000..8be9dc437 --- /dev/null +++ b/syscalls/pidfd_send_signal.c @@ -0,0 +1,21 @@ +/* + * SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, siginfo_t __user *, info, unsigned int, flags) + */ +#include "sanitise.h" + +static unsigned long pidfd_send_signal_flags[] = { + 0, +}; + +struct syscallentry syscall_pidfd_send_signal = { + .name = "pidfd_send_signal", + .num_args = 4, + .arg1name = "pidfd", + .arg1type = ARG_FD, + .arg2name = "sig", + .arg3name = "info", + .arg3type = ARG_ADDRESS, + .arg4name = "flags", + .arg4type = ARG_OP, + .arg4list = ARGLIST(pidfd_send_signal_flags), +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 6ed9c2362..2863a6d9b 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -388,6 +388,7 @@ extern struct syscallentry syscall_pkey_free; extern struct syscallentry syscall_statx; extern struct syscallentry syscall_io_pgetevents; extern struct syscallentry syscall_rseq; +extern struct syscallentry syscall_pidfd_send_signal; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; From 7cf7122e9c75b97045c2a4a9098fc6ecf846bf42 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 12:21:20 -0400 Subject: [PATCH 053/119] basic io_uring support --- include/syscalls-x86_64.h | 3 +++ syscalls/io_uring_enter.c | 26 ++++++++++++++++++++++++++ syscalls/io_uring_register.c | 33 +++++++++++++++++++++++++++++++++ syscalls/io_uring_setup.c | 12 ++++++++++++ syscalls/syscalls.h | 3 +++ 5 files changed, 77 insertions(+) create mode 100644 syscalls/io_uring_enter.c create mode 100644 syscalls/io_uring_register.c create mode 100644 syscalls/io_uring_setup.c diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index 831ed4819..2fccb8956 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -436,4 +436,7 @@ struct syscalltable syscalls_x86_64[] = { { .entry = NULL }, // 422 { .entry = NULL }, // 423 { .entry = &syscall_pidfd_send_signal }, // 424 + { .entry = &syscall_io_uring_setup }, + { .entry = &syscall_io_uring_enter }, + { .entry = &syscall_io_uring_register }, }; diff --git a/syscalls/io_uring_enter.c b/syscalls/io_uring_enter.c new file mode 100644 index 000000000..c57540f9a --- /dev/null +++ b/syscalls/io_uring_enter.c @@ -0,0 +1,26 @@ +/* + * SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, u32, min_complete, u32, flags, const sigset_t __user *, sig, size_t, sigsz) + */ +#include "sanitise.h" + +#define IORING_ENTER_GETEVENTS (1U << 0) +#define IORING_ENTER_SQ_WAKEUP (1U << 1) + +static unsigned long io_uring_enter_flags[] = { + IORING_ENTER_GETEVENTS, IORING_ENTER_SQ_WAKEUP, +}; + +struct syscallentry syscall_io_uring_enter = { + .name = "io_uring_enter", + .num_args = 6, + .arg1name = "fd", + .arg1type = ARG_FD, + .arg2name = "to_submit", + .arg3name = "min_complete", + .arg4name = "flags", + .arg4type = ARG_OP, + .arg4list = ARGLIST(io_uring_enter_flags), + .arg5name = "sig", + .arg5type = ARG_ADDRESS, + .arg6name = "sigsz", +}; diff --git a/syscalls/io_uring_register.c b/syscalls/io_uring_register.c new file mode 100644 index 000000000..8eb8468e8 --- /dev/null +++ b/syscalls/io_uring_register.c @@ -0,0 +1,33 @@ +/* + * SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, unsigned int, opcode, void __user *, arg, unsigned int, nr_args) + */ +#include "sanitise.h" + +#define IORING_REGISTER_BUFFERS 0 +#define IORING_UNREGISTER_BUFFERS 1 +#define IORING_REGISTER_FILES 2 +#define IORING_UNREGISTER_FILES 3 +#define IORING_REGISTER_EVENTFD 4 +#define IORING_UNREGISTER_EVENTFD 5 + +static unsigned long io_uring_register_opcodes[] = { + IORING_REGISTER_BUFFERS, + IORING_UNREGISTER_BUFFERS, + IORING_REGISTER_FILES, + IORING_UNREGISTER_FILES, + IORING_REGISTER_EVENTFD, + IORING_UNREGISTER_EVENTFD, +}; + +struct syscallentry syscall_io_uring_register = { + .name = "io_uring_register", + .num_args = 4, + .arg1name = "fd", + .arg1type = ARG_FD, + .arg2name = "opcode", + .arg2type = ARG_OP, + .arg2list = ARGLIST(io_uring_register_opcodes), + .arg3name = "arg", + .arg3type = ARG_ADDRESS, + .arg4name = "nr_args", +}; diff --git a/syscalls/io_uring_setup.c b/syscalls/io_uring_setup.c new file mode 100644 index 000000000..bfeb81247 --- /dev/null +++ b/syscalls/io_uring_setup.c @@ -0,0 +1,12 @@ +/* + * SYSCALL_DEFINE2(io_uring_setup, u32, entries, struct io_uring_params __user *, params) + */ +#include "sanitise.h" + +struct syscallentry syscall_io_uring_setup = { + .name = "io_uring_setup", + .num_args = 2, + .arg1name = "entries", + .arg2name = "params", + .arg2type = ARG_ADDRESS, +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 2863a6d9b..4a67a89ea 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -389,6 +389,9 @@ extern struct syscallentry syscall_statx; extern struct syscallentry syscall_io_pgetevents; extern struct syscallentry syscall_rseq; extern struct syscallentry syscall_pidfd_send_signal; +extern struct syscallentry syscall_io_uring_setup; +extern struct syscallentry syscall_io_uring_enter; +extern struct syscallentry syscall_io_uring_register; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; From 85586483d192f1747f3088544b34e8a0d227512e Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 12:27:12 -0400 Subject: [PATCH 054/119] basic open_tree support --- include/syscalls-x86_64.h | 1 + syscalls/open_tree.c | 31 +++++++++++++++++++++++++++++++ syscalls/syscalls.h | 1 + 3 files changed, 33 insertions(+) create mode 100644 syscalls/open_tree.c diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index 2fccb8956..e528f8886 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -439,4 +439,5 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_io_uring_setup }, { .entry = &syscall_io_uring_enter }, { .entry = &syscall_io_uring_register }, + { .entry = &syscall_open_tree}, }; diff --git a/syscalls/open_tree.c b/syscalls/open_tree.c new file mode 100644 index 000000000..60b3ec408 --- /dev/null +++ b/syscalls/open_tree.c @@ -0,0 +1,31 @@ +/* + * SYSCALL_DEFINE3(open_tree, int, dfd, const char *, filename, unsigned, flags) + */ +#include "sanitise.h" +#include + +#ifndef OPEN_TREE_CLONE +#define OPEN_TREE_CLONE 1 /* Clone the target tree and attach the clone */ +#define OPEN_TREE_CLOEXEC O_CLOEXEC /* Close the file on execve() */ +#endif + +#ifndef AT_RECURSIVE +#define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */ +#endif + +static unsigned long open_tree_flags[] = { + AT_EMPTY_PATH, AT_NO_AUTOMOUNT, AT_RECURSIVE, AT_SYMLINK_NOFOLLOW, + OPEN_TREE_CLONE, OPEN_TREE_CLOEXEC, +}; + +struct syscallentry syscall_open_tree = { + .name = "open_tree", + .num_args = 3, + .arg1name = "dfd", + .arg1type = ARG_FD, + .arg2name = "filename", + .arg2type = ARG_PATHNAME, + .arg3name = "flags", + .arg3type = ARG_OP, + .arg3list = ARGLIST(open_tree_flags), +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 4a67a89ea..0bd48fb54 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -392,6 +392,7 @@ extern struct syscallentry syscall_pidfd_send_signal; extern struct syscallentry syscall_io_uring_setup; extern struct syscallentry syscall_io_uring_enter; extern struct syscallentry syscall_io_uring_register; +extern struct syscallentry syscall_open_tree; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; From 45791812abea8b8528881986584b97fd62a183c4 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 12:32:12 -0400 Subject: [PATCH 055/119] basic move_mount support --- include/syscalls-x86_64.h | 1 + syscalls/move_mount.c | 33 +++++++++++++++++++++++++++++++++ syscalls/syscalls.h | 1 + 3 files changed, 35 insertions(+) create mode 100644 syscalls/move_mount.c diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index e528f8886..5c1401581 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -440,4 +440,5 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_io_uring_enter }, { .entry = &syscall_io_uring_register }, { .entry = &syscall_open_tree}, + { .entry = &syscall_move_mount}, }; diff --git a/syscalls/move_mount.c b/syscalls/move_mount.c new file mode 100644 index 000000000..ed2d9a17e --- /dev/null +++ b/syscalls/move_mount.c @@ -0,0 +1,33 @@ +/* + * SYSCALL_DEFINE5(move_mount, int, from_dfd, const char *, from_pathname, + * int, to_dfd, const char *, to_pathname, unsigned int, flags) + */ +#include "sanitise.h" + +#define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */ +#define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */ +#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ +#define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */ +#define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */ +#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */ + +static unsigned long move_mount_flags[] = { + MOVE_MOUNT_F_SYMLINKS, MOVE_MOUNT_F_AUTOMOUNTS, MOVE_MOUNT_F_EMPTY_PATH, MOVE_MOUNT_T_SYMLINKS, + MOVE_MOUNT_T_AUTOMOUNTS, MOVE_MOUNT_T_EMPTY_PATH, +}; + +struct syscallentry syscall_move_mount = { + .name = "move_mount", + .num_args = 5, + .arg1name = "from_dfd", + .arg1type = ARG_FD, + .arg2name = "from_pathname", + .arg2type = ARG_PATHNAME, + .arg3name = "to_dfd", + .arg3type = ARG_FD, + .arg4name = "to_pathname", + .arg4type = ARG_PATHNAME, + .arg5name = "flags", + .arg5type = ARG_OP, + .arg5list = ARGLIST(move_mount_flags), +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 0bd48fb54..071737d3b 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -393,6 +393,7 @@ extern struct syscallentry syscall_io_uring_setup; extern struct syscallentry syscall_io_uring_enter; extern struct syscallentry syscall_io_uring_register; extern struct syscallentry syscall_open_tree; +extern struct syscallentry syscall_move_mount; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; From 7f6e54a3a55157106cf971e8bebc76830b849878 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 12:35:29 -0400 Subject: [PATCH 056/119] basic fsopen support --- include/syscalls-x86_64.h | 1 + syscalls/syscalls.h | 1 + 2 files changed, 2 insertions(+) diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index 5c1401581..d1bd85e53 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -441,4 +441,5 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_io_uring_register }, { .entry = &syscall_open_tree}, { .entry = &syscall_move_mount}, + { .entry = &syscall_fsopen }, }; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 071737d3b..5ec3507cc 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -394,6 +394,7 @@ extern struct syscallentry syscall_io_uring_enter; extern struct syscallentry syscall_io_uring_register; extern struct syscallentry syscall_open_tree; extern struct syscallentry syscall_move_mount; +extern struct syscallentry syscall_fsopen; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; From fcaf8297f02680e48044216c707d8960a0f59930 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 12:39:31 -0400 Subject: [PATCH 057/119] basic fsconfig support --- include/syscalls-x86_64.h | 1 + syscalls/fsconfig.c | 33 +++++++++++++++++++++++++++++++++ syscalls/syscalls.h | 1 + 3 files changed, 35 insertions(+) create mode 100644 syscalls/fsconfig.c diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index d1bd85e53..14e489c7e 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -442,4 +442,5 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_open_tree}, { .entry = &syscall_move_mount}, { .entry = &syscall_fsopen }, + { .entry = &syscall_fsconfig }, }; diff --git a/syscalls/fsconfig.c b/syscalls/fsconfig.c new file mode 100644 index 000000000..449f58978 --- /dev/null +++ b/syscalls/fsconfig.c @@ -0,0 +1,33 @@ +/* + * SYSCALL_DEFINE5(fsconfig, int, fd, unsigned int, cmd, const char __user *, _key, const void __user *, _value, int, aux) + */ +#include "sanitise.h" + +enum fsconfig_command { + FSCONFIG_SET_FLAG = 0, /* Set parameter, supplying no value */ + FSCONFIG_SET_STRING = 1, /* Set parameter, supplying a string value */ + FSCONFIG_SET_BINARY = 2, /* Set parameter, supplying a binary blob value */ + FSCONFIG_SET_PATH = 3, /* Set parameter, supplying an object by path */ + FSCONFIG_SET_PATH_EMPTY = 4, /* Set parameter, supplying an object by (empty) path */ + FSCONFIG_SET_FD = 5, /* Set parameter, supplying an object by fd */ + FSCONFIG_CMD_CREATE = 6, /* Invoke superblock creation */ + FSCONFIG_CMD_RECONFIGURE = 7, /* Invoke superblock reconfiguration */ +}; + +static unsigned long fsconfig_ops[] = { + FSCONFIG_SET_FLAG, FSCONFIG_SET_STRING, FSCONFIG_SET_BINARY, FSCONFIG_SET_PATH, + FSCONFIG_SET_PATH_EMPTY, FSCONFIG_SET_FD, FSCONFIG_CMD_CREATE, FSCONFIG_CMD_RECONFIGURE, +}; + +struct syscallentry syscall_fsconfig = { + .name = "fsconfig", + .num_args = 5, + .arg1name = "fd", + .arg1type = ARG_FD, + .arg2name = "cmd", + .arg2type = ARG_OP, + .arg2list = ARGLIST(fsconfig_ops), + .arg3name = "_key", + .arg4name = "_value", + .arg5name = "aux", +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 5ec3507cc..02848b970 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -395,6 +395,7 @@ extern struct syscallentry syscall_io_uring_register; extern struct syscallentry syscall_open_tree; extern struct syscallentry syscall_move_mount; extern struct syscallentry syscall_fsopen; +extern struct syscallentry syscall_fsconfig; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; From 4953ccfe8338e750dc47a8c294429d88cb4ef84e Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 12:45:16 -0400 Subject: [PATCH 058/119] basic fsmount support --- include/compat.h | 10 ++++++++++ syscalls/fsmount.c | 33 +++++++++++++++++++++++++++++++++ syscalls/fsopen.c | 20 ++++++++++++++++++++ syscalls/move_mount.c | 8 +------- 4 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 syscalls/fsmount.c create mode 100644 syscalls/fsopen.c diff --git a/include/compat.h b/include/compat.h index f8be7083a..3912574b4 100644 --- a/include/compat.h +++ b/include/compat.h @@ -1226,3 +1226,13 @@ struct kvm_get_htab_fd { #ifndef AUTOFS_IOC_EXPIRE_DIRECT #define AUTOFS_IOC_EXPIRE_DIRECT AUTOFS_IOC_EXPIRE_MULTI #endif + +/* linux/mount.h */ +#ifndef MOVE_MOUNT_F_SYMLINKS +#define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */ +#define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */ +#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ +#define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */ +#define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */ +#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */ +#endif diff --git a/syscalls/fsmount.c b/syscalls/fsmount.c new file mode 100644 index 000000000..3d9e8eb02 --- /dev/null +++ b/syscalls/fsmount.c @@ -0,0 +1,33 @@ +/* + * SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags, unsigned int, attr_flags) + */ +#include "sanitise.h" +#include "compat.h" + +#define FSMOUNT_CLOEXEC 0x00000001 +static unsigned long fsmount_flags[] = { + FSMOUNT_CLOEXEC, +}; + +static unsigned long fsmount_attr_flags[] = { + MOVE_MOUNT_F_SYMLINKS, + MOVE_MOUNT_F_AUTOMOUNTS, + MOVE_MOUNT_F_EMPTY_PATH, + MOVE_MOUNT_T_SYMLINKS, + MOVE_MOUNT_T_AUTOMOUNTS, + MOVE_MOUNT_T_EMPTY_PATH, +}; + + +struct syscallentry syscall_fsmount = { + .name = "fsmount", + .num_args = 3, + .arg1name = "fs_fd", + .arg1type = ARG_FD, + .arg2name = "flags", + .arg2type = ARG_OP, + .arg2list = ARGLIST(fsmount_flags), + .arg3name = "attr_flags", + .arg3type = ARG_OP, + .arg3list = ARGLIST(fsmount_attr_flags), +}; diff --git a/syscalls/fsopen.c b/syscalls/fsopen.c new file mode 100644 index 000000000..d8b0fbc90 --- /dev/null +++ b/syscalls/fsopen.c @@ -0,0 +1,20 @@ +/* + * SYSCALL_DEFINE2(fsopen, const char __user *, _fs_name, unsigned int, flags) + */ +#include "sanitise.h" + +// TODO: construct arg1 from /proc/filesystems + +#define FSOPEN_CLOEXEC 0x00000001 +static unsigned long fsopen_flags[] = { + FSOPEN_CLOEXEC +}; + +struct syscallentry syscall_fsopen = { + .name = "fsopen", + .num_args = 2, + .arg1name = "_fs_name", + .arg2name = "flags", + .arg2type = ARG_OP, + .arg2list = ARGLIST(fsopen_flags), +}; diff --git a/syscalls/move_mount.c b/syscalls/move_mount.c index ed2d9a17e..1ac8bc7c8 100644 --- a/syscalls/move_mount.c +++ b/syscalls/move_mount.c @@ -3,13 +3,7 @@ * int, to_dfd, const char *, to_pathname, unsigned int, flags) */ #include "sanitise.h" - -#define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */ -#define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */ -#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ -#define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */ -#define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */ -#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */ +#include "compat.h" static unsigned long move_mount_flags[] = { MOVE_MOUNT_F_SYMLINKS, MOVE_MOUNT_F_AUTOMOUNTS, MOVE_MOUNT_F_EMPTY_PATH, MOVE_MOUNT_T_SYMLINKS, From 55e63bcf103cfe11dd1423585957c5bebd360526 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 12:49:21 -0400 Subject: [PATCH 059/119] basic fspick support --- include/syscalls-x86_64.h | 2 ++ syscalls/fspick.c | 28 ++++++++++++++++++++++++++++ syscalls/syscalls.h | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 syscalls/fspick.c diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index 14e489c7e..9274cee41 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -443,4 +443,6 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_move_mount}, { .entry = &syscall_fsopen }, { .entry = &syscall_fsconfig }, + { .entry = &syscall_fsmount }, + { .entry = &syscall_fspick }, }; diff --git a/syscalls/fspick.c b/syscalls/fspick.c new file mode 100644 index 000000000..03fa29f30 --- /dev/null +++ b/syscalls/fspick.c @@ -0,0 +1,28 @@ +/* + * SYSCALL_DEFINE3(fspick, int, dfd, const char __user *, path, unsigned int, flags) + */ +#include "sanitise.h" + +#define FSPICK_CLOEXEC 0x00000001 +#define FSPICK_SYMLINK_NOFOLLOW 0x00000002 +#define FSPICK_NO_AUTOMOUNT 0x00000004 +#define FSPICK_EMPTY_PATH 0x00000008 + +static unsigned long fspick_flags[] = { + FSPICK_CLOEXEC, + FSPICK_SYMLINK_NOFOLLOW, + FSPICK_NO_AUTOMOUNT, + FSPICK_EMPTY_PATH, +}; + +struct syscallentry syscall_fspick = { + .name = "fspick", + .num_args = 3, + .arg1name = "dfd", + .arg1type = ARG_FD, + .arg2name = "path", + .arg2type = ARG_PATHNAME, + .arg3name = "flags", + .arg3type = ARG_OP, + .arg3list = ARGLIST(fspick_flags), +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 02848b970..69ddcc1c0 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -396,6 +396,8 @@ extern struct syscallentry syscall_open_tree; extern struct syscallentry syscall_move_mount; extern struct syscallentry syscall_fsopen; extern struct syscallentry syscall_fsconfig; +extern struct syscallentry syscall_fsmount; +extern struct syscallentry syscall_fspick; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; From 0c15cb4e3a45a7810d927dda4a96ab42cd350eab Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 12:55:38 -0400 Subject: [PATCH 060/119] update setsockopts --- include/compat.h | 23 +++++++++++++++++++++++ scripts/hashcheck.sh | 16 ++++++++-------- syscalls/setsockopt.c | 2 ++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/include/compat.h b/include/compat.h index 3912574b4..19b9fd236 100644 --- a/include/compat.h +++ b/include/compat.h @@ -543,6 +543,29 @@ enum kcmp_type { #define SO_ZEROCOPY 60 #endif +#ifndef SO_TXTIME +#define SO_TXTIME 61 +#endif +#ifndef SO_BINDTOIFINDEX +#define SO_BINDTOIFINDEX 62 +#endif +#ifndef SO_TIMESTAMP_NEW +#define SO_TIMESTAMP_NEW 63 +#endif +#ifndef SO_TIMESTAMPNS_NEW +#define SO_TIMESTAMPNS_NEW 64 +#endif +#ifndef SO_TIMESTAMPING_NEW +#define SO_TIMESTAMPING_NEW 65 +#endif +#ifndef SO_RCVTIMEO_NEW +#define SO_RCVTIMEO_NEW 66 +#endif +#ifndef SO_SNDTIMEO_NEW +#define SO_SNDTIMEO_NEW 67 +#endif + + /* linux/tcp.h */ #ifndef TCP_COOKIE_TRANSACTIONS diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh index 01c3b9d9b..79b0026fd 100755 --- a/scripts/hashcheck.sh +++ b/scripts/hashcheck.sh @@ -25,11 +25,11 @@ check() # Note: Commented out checks are likely out of date, but they're for architectures # I don't have time to care about. Step up and contribute if you care. # -check include/uapi/asm-generic/unistd.h e1f35cf48a7ae6a07949ad3e875cb7937c2c6cf0 sys_ +check include/uapi/asm-generic/unistd.h f15d6c6ce3fd351a88f40d7c8b2e631e25dbed8d sys_ #check arch/alpha/include/uapi/asm/unistd.h 51fa669a21d8f26a0c9de8280a3cfd9c257a0d28 _NR_ #check arch/arm/include/uapi/asm/unistd.h 7c601d436a3ebbe05a9b6813c0ffcf8eedaf101b SYSCALL check arch/x86/entry/syscalls/syscall_32.tbl 1b9ed3050a88b2d84bdb7dbcfe2ab23b8234bee8 sys_ -check arch/x86/entry/syscalls/syscall_64.tbl d52841da5ee801bfd7277fccf5b76d30566ace1a sys_ +check arch/x86/entry/syscalls/syscall_64.tbl 9aca30eead0af4397c058c829ca15b49ea3e585e sys_ check arch/x86/entry/syscalls/syscall_64.tbl da39a3ee5e6b4b0d3255bfef95601890afd80709 stub_ #check arch/ia64/kernel/entry.S e6a21b973609ec08cd19b0b8c67830f8570e93ef "data8\ sys_" #check arch/mips/kernel/scall32-o32.S b1501a675dd998fe2af68ae43cd797cf18d67b33 sys_ @@ -40,19 +40,19 @@ check arch/x86/entry/syscalls/syscall_64.tbl da39a3ee5e6b4b0d3255bfef9560189 #check arch/sparc/kernel/systbls_32.S 98100f9dedc82d82ac18a33fd68dc7e4852ffcb8 sys_ # new setsockopt values -check include/uapi/asm-generic/socket.h 848bfd5d1700324c48e1216da2abdda7515b230b SO_ -check include/uapi/linux/tcp.h ed5bbfa500b64aad4d742b2eed0d35ce22ab36b8 \#define\ TCP_ +check include/uapi/asm-generic/socket.h 9df70d0b2c11b5df9a2f9b3aa835d49511a0ec36 SO_ +check include/uapi/linux/tcp.h 8ea7461203395459db4a7ceaeea1f18893f74cec \#define\ TCP_ check include/uapi/linux/in.h 0116e6878df350e74ec730fd9f455efb95e510c8 \#define\ IP_ # Check for new packet families -check include/linux/socket.h 17b4779bb45a76825972f41d1fa1f8d2b908a21b SOL_ -check include/linux/socket.h 80c34154051e712d03e81577d494efe8f09139a8 AF_ +check include/linux/socket.h 52069f49a4646e9692c6b3186172fbd1fa681dcf SOL_ +check include/linux/socket.h 02ead19934fd61e127ccfb46445afea2caed4ece AF_ # MSG_ flags -check include/linux/socket.h 91b84d05363d32e88375567a9bb7a4e16d738ea8 \ MSG_ +check include/linux/socket.h 94a5669653d7098b8c4a4391aeabb593b5940486 \ MSG_ # new netlink protos -check include/uapi/linux/netlink.h 1f391f35d0443f432871cbb366d1150973eb2bcb "#define\ NETLINK_" +check include/uapi/linux/netlink.h 97cad03cf941de83421ddcfc5178af06a05cea50 "#define\ NETLINK_" # new O_ flags check include/uapi/asm-generic/fcntl.h 256ab30dfec0915704a13755ba645c448a65220c O_ diff --git a/syscalls/setsockopt.c b/syscalls/setsockopt.c index 3f38a61a6..dd5f10458 100644 --- a/syscalls/setsockopt.c +++ b/syscalls/setsockopt.c @@ -26,6 +26,8 @@ static const unsigned int socket_opts[] = { SO_ATTACH_BPF, SO_ATTACH_REUSEPORT_CBPF, SO_ATTACH_REUSEPORT_EBPF, SO_CNX_ADVICE, SCM_TIMESTAMPING_OPT_STATS, SO_MEMINFO, SO_INCOMING_NAPI_ID, SO_COOKIE, SCM_TIMESTAMPING_PKTINFO, SO_PEERGROUPS, SO_ZEROCOPY, + SO_TXTIME, SO_BINDTOIFINDEX, SO_TIMESTAMP_NEW, SO_TIMESTAMPNS_NEW, + SO_TIMESTAMPING_NEW, SO_RCVTIMEO_NEW, SO_SNDTIMEO_NEW, }; static void socket_setsockopt(struct sockopt *so, __unused__ struct socket_triplet *triplet) From 415dadcfde6f09deed4bc90f3975ecab3295c181 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 13:02:42 -0400 Subject: [PATCH 061/119] update prctl --- include/compat.h | 17 +++++++++++++++++ syscalls/prctl.c | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/include/compat.h b/include/compat.h index 19b9fd236..67687047f 100644 --- a/include/compat.h +++ b/include/compat.h @@ -376,6 +376,23 @@ enum { #define PR_CAP_AMBIENT 47 #endif +//TODO wtf were 48,49 ? + +// arm64 only +#ifndef PR_SVE_SET_VL +#define PR_SVE_SET_VL 50 +#define PR_SVE_GET_VL 51 +#endif + +#ifndef PR_GET_SPECULATION_CTRL +#define PR_GET_SPECULATION_CTRL 52 +#define PR_SET_SPECULATION_CTRL 53 +#endif + +// arm64 only +#ifndef PR_PAC_RESET_KEYS +#define PR_PAC_RESET_KEYS 54 +#endif /* linux/rds.h */ #ifndef RDS_CANCEL_SENT_TO diff --git a/syscalls/prctl.c b/syscalls/prctl.c index 0ef8c5375..afb447ecb 100644 --- a/syscalls/prctl.c +++ b/syscalls/prctl.c @@ -32,8 +32,12 @@ static int prctl_opts[] = { PR_SET_MM, PR_SET_CHILD_SUBREAPER, PR_GET_CHILD_SUBREAPER, PR_SET_NO_NEW_PRIVS, PR_GET_NO_NEW_PRIVS, PR_GET_TID_ADDRESS, PR_SET_THP_DISABLE, PR_GET_THP_DISABLE, PR_MPX_ENABLE_MANAGEMENT, PR_MPX_DISABLE_MANAGEMENT, + PR_GET_SPECULATION_CTRL, PR_SET_SPECULATION_CTRL, #ifdef __mips__ PR_GET_FP_MODE, PR_SET_FP_MODE, +#endif +#ifdef __arm64__ + PR_SVE_SET_VL, PR_SVE_GET_VL, PR_PAC_RESET_KEYS, #endif PR_CAP_AMBIENT, }; From d157fd87c095a66913e7c5c6dcda22f00037b3e6 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 13:14:47 -0400 Subject: [PATCH 062/119] update x86-32 syscalls --- include/syscalls-i386.h | 43 +++++++++++++++++++++++++++++++++++++++++ scripts/hashcheck.sh | 4 ++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/include/syscalls-i386.h b/include/syscalls-i386.h index 1fee9b91a..0124d7f0d 100644 --- a/include/syscalls-i386.h +++ b/include/syscalls-i386.h @@ -395,4 +395,47 @@ struct syscalltable syscalls_i386[] = { { .entry = &syscall_pkey_alloc }, { .entry = &syscall_pkey_free }, { .entry = &syscall_statx }, + { .entry = &syscall_arch_prctl }, + { .entry = &syscall_io_pgetevents }, + { .entry = &syscall_rseq }, + { .entry = &syscall_semget }, + { .entry = &syscall_semctl }, + { .entry = &syscall_shmget }, + { .entry = &syscall_shmctl }, + { .entry = &syscall_shmat }, + { .entry = &syscall_shmdt }, + { .entry = &syscall_msgget }, + { .entry = &syscall_msgsnd }, + { .entry = &syscall_msgrcv }, + { .entry = &syscall_msgctl }, + { .entry = &syscall_clock_gettime }, + { .entry = &syscall_clock_settime }, + { .entry = &syscall_clock_adjtime }, + { .entry = &syscall_clock_getres }, + { .entry = &syscall_clock_nanosleep }, + { .entry = &syscall_timer_gettime }, + { .entry = &syscall_timer_settime }, + { .entry = &syscall_timerfd_gettime }, + { .entry = &syscall_timerfd_settime }, + { .entry = &syscall_utimensat }, + { .entry = &syscall_pselect6 }, + { .entry = &syscall_ppoll }, + { .entry = &syscall_io_pgetevents }, + { .entry = &syscall_recvmmsg }, + { .entry = &syscall_mq_timedsend }, + { .entry = &syscall_mq_timedreceive }, + { .entry = &syscall_semtimedop }, + { .entry = &syscall_rt_sigtimedwait }, + { .entry = &syscall_futex }, + { .entry = &syscall_sched_rr_get_interval }, + { .entry = &syscall_pidfd_send_signal }, + { .entry = &syscall_io_uring_setup }, + { .entry = &syscall_io_uring_enter }, + { .entry = &syscall_io_uring_register }, + { .entry = &syscall_open_tree}, + { .entry = &syscall_move_mount}, + { .entry = &syscall_fsopen }, + { .entry = &syscall_fsconfig }, + { .entry = &syscall_fsmount }, + { .entry = &syscall_fspick }, }; diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh index 79b0026fd..374efe9f4 100755 --- a/scripts/hashcheck.sh +++ b/scripts/hashcheck.sh @@ -28,7 +28,7 @@ check() check include/uapi/asm-generic/unistd.h f15d6c6ce3fd351a88f40d7c8b2e631e25dbed8d sys_ #check arch/alpha/include/uapi/asm/unistd.h 51fa669a21d8f26a0c9de8280a3cfd9c257a0d28 _NR_ #check arch/arm/include/uapi/asm/unistd.h 7c601d436a3ebbe05a9b6813c0ffcf8eedaf101b SYSCALL -check arch/x86/entry/syscalls/syscall_32.tbl 1b9ed3050a88b2d84bdb7dbcfe2ab23b8234bee8 sys_ +check arch/x86/entry/syscalls/syscall_32.tbl 340cb5804ab72eeaea9aed0394b4f2e891575a81 sys_ check arch/x86/entry/syscalls/syscall_64.tbl 9aca30eead0af4397c058c829ca15b49ea3e585e sys_ check arch/x86/entry/syscalls/syscall_64.tbl da39a3ee5e6b4b0d3255bfef95601890afd80709 stub_ #check arch/ia64/kernel/entry.S e6a21b973609ec08cd19b0b8c67830f8570e93ef "data8\ sys_" @@ -76,7 +76,7 @@ check include/uapi/linux/in.h 80799106aba80b40af5416f0d5cc47dea8b02225 \ \ IPPR check include/uapi/asm-generic/errno.h da39a3ee5e6b4b0d3255bfef95601890afd80709 134 # new prctls -check include/uapi/linux/prctl.h 54a153856a9136a9bad87deed2475f8eca2ebbbb PR_ +check include/uapi/linux/prctl.h 2b3c44c13ff4df4b9062898f6bb5a3323283ab7d PR_ # new fallocate flags check include/uapi/linux/falloc.h c46220c8e3bd5e237d02880e0d2ac16e88a6d7c0 FALLOC_ From a9973aeffebf41fe0e31a8ca263d4a7f0958dc0d Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 13:28:27 -0400 Subject: [PATCH 063/119] Fix compile failure on centos7 --- fds/memfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fds/memfd.c b/fds/memfd.c index e3334a1d3..fc50322e4 100644 --- a/fds/memfd.c +++ b/fds/memfd.c @@ -19,7 +19,7 @@ #ifndef USE_MEMFD_CREATE -#ifndef MFD_ALLOW_SEALING +#ifndef memfd_create static int memfd_create(__unused__ const char *uname, __unused__ unsigned int flag) { #ifdef SYS_memfd_create From aee3c70a082837b3042ab7b7c15f0f2932ffb8a8 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 13:30:07 -0400 Subject: [PATCH 064/119] Bump version string to something that makes more sense There are no new point releases. I'll bump this to the latest date periodically, but I'm no longer creating tarball snapshots. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 66ac43917..6ebf728fb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION="1.10pre" +VERSION="2019.06" ifeq (,$(findstring pre,$(VERSION))) DEVEL = 0 From 0a835afeffecb42cd5961ea88f1882dceb85b491 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 15:10:18 -0400 Subject: [PATCH 065/119] no logging by default --- scripts/test-multi.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test-multi.sh b/scripts/test-multi.sh index eef66ee9b..2c81ca475 100755 --- a/scripts/test-multi.sh +++ b/scripts/test-multi.sh @@ -25,7 +25,7 @@ do rm -f trinity.socketcache - MALLOC_CHECK_=2 ../trinity -q -l wopr -C $NR_PROCESSES $DROPPRIVS -N 1000000 -E SMC -a64 + MALLOC_CHECK_=2 ../trinity -q -l off -C $NR_PROCESSES $DROPPRIVS -N 1000000 -E SMC -a64 chmod 755 $TRINITY_TMP popd > /dev/null From 02c01eea1283487ba06695f392a08ffc375b40c5 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 15:27:56 -0400 Subject: [PATCH 066/119] Don't do 10 iterations of sockets we can't generate --- fds/sockets.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fds/sockets.c b/fds/sockets.c index 3619f9dd4..eaae4928f 100644 --- a/fds/sockets.c +++ b/fds/sockets.c @@ -365,7 +365,8 @@ static bool generate_sockets(void) while (nr_sockets < NR_SOCKET_FDS) { r = rnd() % TRINITY_PF_MAX; for (i = 0; i < 10; i++) - generate_specific_socket(r); + if (generate_specific_socket(r) == FALSE) + break; } out_unlock: From 9c209af82fece8b40d18559a60887de1898d9b45 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 15:55:06 -0400 Subject: [PATCH 067/119] socket args are unsigned --- fds/sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fds/sockets.c b/fds/sockets.c index eaae4928f..b323ab137 100644 --- a/fds/sockets.c +++ b/fds/sockets.c @@ -249,7 +249,7 @@ static bool generate_socket(unsigned int family, unsigned int protocol, unsigned write_socket_to_cache(&st); return TRUE; } - output(2, "Couldn't open socket %d:%d:%d. %s\n", family, type, protocol, strerror(errno)); + output(2, "Couldn't open socket %u:%u:%u. %s\n", family, type, protocol, strerror(errno)); return FALSE; } From 92ce235aad2bcbee3a998c2d6151757f419142b8 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 16:00:21 -0400 Subject: [PATCH 068/119] silence the perf dumper it's not particularly helpful in this form rn --- fds/perf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fds/perf.c b/fds/perf.c index 290fb6332..d88ea37c3 100644 --- a/fds/perf.c +++ b/fds/perf.c @@ -30,17 +30,17 @@ static void perffd_dump(struct object *obj, bool global) struct perf_event_attr *attr = obj->perfobj.eventattr; struct msg_objcreatedperf *objmsg; char *p = (char *)attr; - unsigned int i; +// unsigned int i; unsigned int perfsize = sizeof(struct perf_event_attr); output(2, "perf fd: %d pid:%d cpu:%d group_fd:%d flags:%lx\n", po->fd, po->pid, po->cpu, po->group_fd, po->flags); - output(2, " perf_event_attr:"); +/* output(2, " perf_event_attr:"); for (i = 0; i < perfsize ; i++) { output(CONT, "%02x ", (unsigned char) p[i]); } output(CONT, "\n"); - +*/ objmsg = zmalloc(sizeof(struct msg_objcreatedperf) + perfsize); init_msgobjhdr(&objmsg->hdr, OBJ_CREATED_PERF, global, obj); objmsg->fd = po->fd; From d015b9507857f063f6d96f1f3a4f67a4a5a596a4 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 16:19:45 -0400 Subject: [PATCH 069/119] more signed->unsigned --- fds/sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fds/sockets.c b/fds/sockets.c index b323ab137..c69be72ec 100644 --- a/fds/sockets.c +++ b/fds/sockets.c @@ -279,7 +279,7 @@ static bool generate_specific_socket(int family) fd = open_socket(st.family, st.type, st.protocol); if (fd == -1) { - output(0, "Couldn't open socket (%d:%d:%d). %s\n", + output(0, "Couldn't open socket (%u:%u:%u). %s\n", st.family, st.type, st.protocol, strerror(errno)); return FALSE; From ca32294cd988224a42e95c2d81efe35b26cd61c0 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 16:33:25 -0400 Subject: [PATCH 070/119] Map PF_XDP to string --- net/domains.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/domains.c b/net/domains.c index 108875319..be4f76dbc 100644 --- a/net/domains.c +++ b/net/domains.c @@ -63,6 +63,7 @@ static const struct domain domains[] = { { "KCM", PF_KCM }, { "QIPCRTR", PF_QIPCRTR }, { "SMC", PF_SMC }, + { "XDP", PF_XDP }, }; static const struct domain *lookup_domain(const char *name) From 4cdf48b5e319178ea711ad5c8e628326ea273cfb Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 27 Jun 2019 16:37:48 -0400 Subject: [PATCH 071/119] Fix cut-n-paste errors in smc socket creation --- net/proto-smc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/proto-smc.c b/net/proto-smc.c index 2a97bf675..94764db94 100644 --- a/net/proto-smc.c +++ b/net/proto-smc.c @@ -1,9 +1,12 @@ #include "net.h" #include "compat.h" +#define SMCPROTO_SMC 0 /* SMC protocol, IPv4 */ +#define SMCPROTO_SMC6 1 /* SMC protocol, IPv6 */ + static struct socket_triplet smc_triplet[] = { - { .family = PF_QIPCRTR, .protocol = IPPROTO_IP, .type = SOCK_STREAM }, - { .family = PF_QIPCRTR, .protocol = IPPROTO_TCP, .type = SOCK_STREAM }, + { .family = SMCPROTO_SMC, .protocol = SMCPROTO_SMC, .type = SOCK_STREAM }, + { .family = SMCPROTO_SMC6, .protocol = SMCPROTO_SMC6, .type = SOCK_STREAM }, }; const struct netproto proto_smc = { From b28d72f754706265e81c44b86a05ca9d83a57fee Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 1 Jul 2019 09:40:31 -0400 Subject: [PATCH 072/119] Fix reversed file closures in ftrace code. --- ftrace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ftrace.c b/ftrace.c index 84a754b99..ef62882d7 100644 --- a/ftrace.c +++ b/ftrace.c @@ -53,10 +53,10 @@ static void dump_trace(void) output(0, "Dumped trace to %s\n", ftracedumpname); fail: fsync(traceout); - close(tracein); + close(traceout); fail_traceout: - close(traceout); + close(tracein); fail_tracein: free((void *)ftracedumpname); ftracedumpname = NULL; From 134c1a836a64a4350f79fa55d42b4190445960c2 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 1 Jul 2019 09:44:16 -0400 Subject: [PATCH 073/119] remove pointless or --- syscalls/perf_event_open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syscalls/perf_event_open.c b/syscalls/perf_event_open.c index 517328de3..e6bf63788 100644 --- a/syscalls/perf_event_open.c +++ b/syscalls/perf_event_open.c @@ -136,7 +136,7 @@ static int parse_format(const char *string, int *field_type, unsigned long long } if (bits==64) { - *mask|=0xffffffffffffffffULL; + *mask=0xffffffffffffffffULL; } else { *mask|=((1ULL< Date: Mon, 1 Jul 2019 09:54:27 -0400 Subject: [PATCH 074/119] don't free the default dump filename ptr --- ftrace.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ftrace.c b/ftrace.c index ef62882d7..6a7c80fcf 100644 --- a/ftrace.c +++ b/ftrace.c @@ -54,12 +54,13 @@ static void dump_trace(void) fail: fsync(traceout); close(traceout); - fail_traceout: close(tracein); fail_tracein: - free((void *)ftracedumpname); - ftracedumpname = NULL; + if (ftracedumpname != defaultdumpfilename) { + free((void *)ftracedumpname); + ftracedumpname = NULL; + } } void setup_ftrace(void) @@ -85,7 +86,5 @@ void stop_ftrace(void) } dump_trace(); return; - } else { - output(0, "trace_fd was %d\n", trace_fd); } } From 28c9d12aed813412b617de36ad68bf61219c16f1 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 1 Jul 2019 10:01:32 -0400 Subject: [PATCH 075/119] format string fixes --- debug.c | 6 +++--- fds/bpf.c | 2 +- fds/sockets.c | 10 +++++----- main.c | 4 ++-- syscalls/futex.c | 2 +- sysv-shm.c | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/debug.c b/debug.c index 70fa22c74..f043640c9 100644 --- a/debug.c +++ b/debug.c @@ -96,7 +96,7 @@ void dump_syscallrec(struct syscallrecord *rec) output(0, " state:%d\n", rec->state); output(0, " prebuffer : %p (len:%d)\n", rec->prebuffer, strlen(rec->prebuffer)); output(0, " -> %s\n", rec->prebuffer); - output(0, " postbuffer : %p (len:%d)\n", rec->postbuffer, strlen(rec->postbuffer)); + output(0, " postbuffer : %p (len:%ld)\n", rec->postbuffer, strlen(rec->postbuffer)); output(0, " -> %s\n", rec->postbuffer); } @@ -115,9 +115,9 @@ void dump_childdata(struct childdata *child) output(0, "objects: %p\n", child->objects); //TODO: dump each objhead - output(0, " tp.tv_sec=%d tp.tv_nsec=%ld\n", child->tp.tv_sec, child->tp.tv_nsec); + output(0, " tp.tv_sec=%ld tp.tv_nsec=%ld\n", child->tp.tv_sec, child->tp.tv_nsec); - output(0, "seed: %ld\n", child->seed); + output(0, "seed: %u\n", child->seed); output(0, "childnum: %d\n", child->num); output(0, "killcount: %d\n", child->kill_count); diff --git a/fds/bpf.c b/fds/bpf.c index 7e01100d7..4b763d131 100644 --- a/fds/bpf.c +++ b/fds/bpf.c @@ -78,7 +78,7 @@ static void bpf_map_dump(struct object *obj, bool global) struct msg_objcreatedbpfmap objmsg; u32 type = obj->bpfobj.map_type; - output(2, "bpf map fd:%d type:%s\n", obj->bpfobj.map_fd, &bpf_fds[type].name); + output(2, "bpf map fd:%d type:%s\n", obj->bpfobj.map_fd, (char *)&bpf_fds[type].name); init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_BPFMAP, global, obj); objmsg.map_fd = obj->bpfobj.map_fd; diff --git a/fds/sockets.c b/fds/sockets.c index c69be72ec..48dee9b92 100644 --- a/fds/sockets.c +++ b/fds/sockets.c @@ -47,7 +47,7 @@ static void sso_socket(struct socket_triplet *triplet, struct sockopt *so, int f ret = setsockopt(fd, so->level, so->optname, (void *)so->optval, so->optlen); if (ret == 0) { - output(2, "setsockopt(%lx %lx %lx %lx) on fd %d [%d:%d:%d]\n", + output(2, "setsockopt(%u 0x%lx 0x%lx 0x%lx) on fd %u [%u:%u:%u]\n", so->level, so->optname, so->optval, so->optlen, fd, triplet->family, triplet->type, triplet->protocol); } else { @@ -400,7 +400,7 @@ static void socket_destructor(struct object *obj) (void) shutdown(fd, SHUT_RDWR); if (close(fd) != 0) - output(1, "failed to close socket [%d:%d:%d].(%s)\n", + output(1, "failed to close socket [%u:%u:%u].(%s)\n", si->triplet.family, si->triplet.type, si->triplet.protocol, @@ -412,7 +412,7 @@ static void socket_dump(struct object *obj, bool global) struct socketinfo *si = &obj->sockinfo; struct msg_objcreatedsocket objmsg; - output(2, "socket fd:%d domain:%u (%s) type:0x%u protocol:%u\n", + output(2, "socket fd:%u domain:%u (%s) type:0x%u protocol:%u\n", si->fd, si->triplet.family, get_domain_name(si->triplet.family), si->triplet.type, si->triplet.protocol); @@ -438,7 +438,7 @@ static int open_sockets(void) if (cachefile < 0) { output(1, "Couldn't find socket cachefile. Regenerating.\n"); ret = generate_sockets(); - output(1, "created %d sockets\n", nr_sockets); + output(1, "created %u sockets\n", nr_sockets); return ret; } @@ -492,7 +492,7 @@ static int open_sockets(void) } } - output(1, "%d sockets created based on info from socket cachefile.\n", nr_sockets); + output(1, "%u sockets created based on info from socket cachefile.\n", nr_sockets); unlock_cachefile(); close(cachefile); diff --git a/main.c b/main.c index 0e2d3f32b..9d82f1052 100644 --- a/main.c +++ b/main.c @@ -403,7 +403,7 @@ static bool is_child_making_progress(struct childdata *child) if (diff < 40) return FALSE; - debugf("sending another SIGKILL to child %d (pid:%u type:%u). [kill count:%d] [diff:%d]\n", + debugf("sending another SIGKILL to child %u (pid:%u type:%u). [kill count:%u] [diff:%lu]\n", child->num, pid, child->type, child->kill_count, diff); child->kill_count++; kill_pid(pid); @@ -783,7 +783,7 @@ void main_loop(void) } if (syscalls_todo && (shm->stats.op_count >= syscalls_todo)) { - output(0, "Reached limit %d. Telling children to exit.\n", syscalls_todo); + output(0, "Reached limit %lu. Telling children to exit.\n", syscalls_todo); panic(EXIT_REACHED_COUNT); } diff --git a/syscalls/futex.c b/syscalls/futex.c index c4301057c..51d8d55d2 100644 --- a/syscalls/futex.c +++ b/syscalls/futex.c @@ -116,7 +116,7 @@ static void dump_futex(struct object *obj, __unused__ bool global) { struct msg_objcreatedfutex objmsg; - output(0, "futex: %lx owner:%d\n", obj->lock.futex, obj->lock.owner_pid); + output(0, "futex: %x owner:%d\n", obj->lock.futex, obj->lock.owner_pid); init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_FUTEX, global, obj); objmsg.futex = obj->lock.futex; diff --git a/sysv-shm.c b/sysv-shm.c index 9accd7c52..5a917c06f 100644 --- a/sysv-shm.c +++ b/sysv-shm.c @@ -17,7 +17,7 @@ static void dump_sysv_shm(struct object *obj, bool global) { struct msg_objcreatedshm objmsg; - output(0, "sysv_shm: id:%u size:%d flags:%x ptr:%p\n", + output(0, "sysv_shm: id:%u size:%ld flags:%x ptr:%p\n", obj->sysv_shm.id, obj->sysv_shm.size, obj->sysv_shm.flags, obj->sysv_shm.ptr); From ff43703055b7abc77b1c533a4f5a9230c40f0586 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 22 Jul 2019 16:17:53 -0400 Subject: [PATCH 076/119] add new 5.3 syscalls --- include/syscalls-x86_64.h | 2 ++ syscalls/clone3.c | 17 +++++++++++++++++ syscalls/pidfd_open.c | 19 +++++++++++++++++++ syscalls/syscalls.h | 2 ++ 4 files changed, 40 insertions(+) create mode 100644 syscalls/clone3.c create mode 100644 syscalls/pidfd_open.c diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index 9274cee41..a60f4d303 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -445,4 +445,6 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_fsconfig }, { .entry = &syscall_fsmount }, { .entry = &syscall_fspick }, + { .entry = &syscall_pidfd_open }, + { .entry = &syscall_clone3 }, }; diff --git a/syscalls/clone3.c b/syscalls/clone3.c new file mode 100644 index 000000000..3ed78b077 --- /dev/null +++ b/syscalls/clone3.c @@ -0,0 +1,17 @@ +/* + * SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size) + */ + +#include +#include "sanitise.h" + +struct syscallentry syscall_clone3 = { + .name = "clone3", + .num_args = 2, + .flags = AVOID_SYSCALL, + .arg1name = "uargs", + .arg1type = ARG_ADDRESS, + .arg2name = "size", + .arg2type = ARG_LEN, + .rettype = RET_PID_T, +}; diff --git a/syscalls/pidfd_open.c b/syscalls/pidfd_open.c new file mode 100644 index 000000000..a42145f04 --- /dev/null +++ b/syscalls/pidfd_open.c @@ -0,0 +1,19 @@ +/* + * SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags) + */ +#include "sanitise.h" + +static unsigned long pidfd_open_flags[] = { + 0, +}; + +struct syscallentry syscall_pidfd_open = { + .name = "pidfd_open", + .num_args = 2, + .arg1type = ARG_PID, + .arg1name = "pid", + .arg2name = "flags", + .arg2type = ARG_LIST, + .arg2list = ARGLIST(pidfd_open_flags), + .rettype = RET_PID_T, +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 69ddcc1c0..46884ec8c 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -398,6 +398,8 @@ extern struct syscallentry syscall_fsopen; extern struct syscallentry syscall_fsconfig; extern struct syscallentry syscall_fsmount; extern struct syscallentry syscall_fspick; +extern struct syscallentry syscall_pidfd_open; +extern struct syscallentry syscall_clone3; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; From db82a52f0588650925c78dc376f31a0f7056ec5b Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 22 Jul 2019 16:20:46 -0400 Subject: [PATCH 077/119] update x86-32 syscalls --- include/syscalls-i386.h | 2 ++ scripts/hashcheck.sh | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/syscalls-i386.h b/include/syscalls-i386.h index 0124d7f0d..844ef68b2 100644 --- a/include/syscalls-i386.h +++ b/include/syscalls-i386.h @@ -438,4 +438,6 @@ struct syscalltable syscalls_i386[] = { { .entry = &syscall_fsconfig }, { .entry = &syscall_fsmount }, { .entry = &syscall_fspick }, + { .entry = &syscall_pidfd_open }, + { .entry = &syscall_clone3 }, }; diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh index 374efe9f4..19d8d7c8a 100755 --- a/scripts/hashcheck.sh +++ b/scripts/hashcheck.sh @@ -25,11 +25,11 @@ check() # Note: Commented out checks are likely out of date, but they're for architectures # I don't have time to care about. Step up and contribute if you care. # -check include/uapi/asm-generic/unistd.h f15d6c6ce3fd351a88f40d7c8b2e631e25dbed8d sys_ +check include/uapi/asm-generic/unistd.h 198599d8f761b4dd63db413600419fdad3ddfcbd sys_ #check arch/alpha/include/uapi/asm/unistd.h 51fa669a21d8f26a0c9de8280a3cfd9c257a0d28 _NR_ #check arch/arm/include/uapi/asm/unistd.h 7c601d436a3ebbe05a9b6813c0ffcf8eedaf101b SYSCALL -check arch/x86/entry/syscalls/syscall_32.tbl 340cb5804ab72eeaea9aed0394b4f2e891575a81 sys_ -check arch/x86/entry/syscalls/syscall_64.tbl 9aca30eead0af4397c058c829ca15b49ea3e585e sys_ +check arch/x86/entry/syscalls/syscall_32.tbl be7686afac49943e1a89447b1d09f4a6e868f482 sys_ +check arch/x86/entry/syscalls/syscall_64.tbl 83b2c58072648e92afca0504d5a60b456ddfe2ce sys_ check arch/x86/entry/syscalls/syscall_64.tbl da39a3ee5e6b4b0d3255bfef95601890afd80709 stub_ #check arch/ia64/kernel/entry.S e6a21b973609ec08cd19b0b8c67830f8570e93ef "data8\ sys_" #check arch/mips/kernel/scall32-o32.S b1501a675dd998fe2af68ae43cd797cf18d67b33 sys_ From 0bf2d39cce58ce1d32ce1d52b13ea5635f8b64ce Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 22 Jul 2019 16:23:11 -0400 Subject: [PATCH 078/119] Add SO_DETACH_REUSEPORT_BPF --- include/compat.h | 4 ++++ scripts/hashcheck.sh | 2 +- syscalls/setsockopt.c | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/compat.h b/include/compat.h index 67687047f..9aa467687 100644 --- a/include/compat.h +++ b/include/compat.h @@ -582,6 +582,10 @@ enum kcmp_type { #define SO_SNDTIMEO_NEW 67 #endif +#ifndef SO_DETACH_REUSEPORT_BPF +#define SO_DETACH_REUSEPORT_BPF 68 +#endif + /* linux/tcp.h */ diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh index 19d8d7c8a..fdf21c7d3 100755 --- a/scripts/hashcheck.sh +++ b/scripts/hashcheck.sh @@ -40,7 +40,7 @@ check arch/x86/entry/syscalls/syscall_64.tbl da39a3ee5e6b4b0d3255bfef9560189 #check arch/sparc/kernel/systbls_32.S 98100f9dedc82d82ac18a33fd68dc7e4852ffcb8 sys_ # new setsockopt values -check include/uapi/asm-generic/socket.h 9df70d0b2c11b5df9a2f9b3aa835d49511a0ec36 SO_ +check include/uapi/asm-generic/socket.h 08003e14cf68ce62a2caeb8921db3e081a612f09 SO_ check include/uapi/linux/tcp.h 8ea7461203395459db4a7ceaeea1f18893f74cec \#define\ TCP_ check include/uapi/linux/in.h 0116e6878df350e74ec730fd9f455efb95e510c8 \#define\ IP_ diff --git a/syscalls/setsockopt.c b/syscalls/setsockopt.c index dd5f10458..91905c9b6 100644 --- a/syscalls/setsockopt.c +++ b/syscalls/setsockopt.c @@ -28,6 +28,7 @@ static const unsigned int socket_opts[] = { SO_COOKIE, SCM_TIMESTAMPING_PKTINFO, SO_PEERGROUPS, SO_ZEROCOPY, SO_TXTIME, SO_BINDTOIFINDEX, SO_TIMESTAMP_NEW, SO_TIMESTAMPNS_NEW, SO_TIMESTAMPING_NEW, SO_RCVTIMEO_NEW, SO_SNDTIMEO_NEW, + SO_DETACH_REUSEPORT_BPF, }; static void socket_setsockopt(struct sockopt *so, __unused__ struct socket_triplet *triplet) From b89601123b42e09ba9c7f9654c16c4a5c9dbcb6e Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 22 Jul 2019 16:27:39 -0400 Subject: [PATCH 079/119] update TCP setsockopts --- include/compat.h | 20 ++++++++++++++++++++ net/proto-ip-tcp.c | 2 ++ scripts/hashcheck.sh | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/compat.h b/include/compat.h index 9aa467687..5267998a7 100644 --- a/include/compat.h +++ b/include/compat.h @@ -658,6 +658,26 @@ enum kcmp_type { #define TCP_MD5SIG_EXT 32 #endif +#ifndef TCP_FASTOPEN_KEY +#define TCP_FASTOPEN_KEY 33 /* Set the key for Fast Open (cookie) */ +#endif + +#ifndef TCP_FASTOPEN_NO_COOKIE +#define TCP_FASTOPEN_NO_COOKIE 34 /* Enable TFO without a TFO cookie */ +#endif + +#ifndef TCP_ZEROCOPY_RECEIVE +#define TCP_ZEROCOPY_RECEIVE 35 +#endif + +#ifndef TCP_INQ +#define TCP_INQ 36 /* Notify bytes available to read as a cmsg on read */ +#endif + +#ifndef TCP_TX_DELAY +#define TCP_TX_DELAY 37 +#endif + /* linux/if_packet.h */ #ifndef PACKET_VNET_HDR #define PACKET_VNET_HDR 15 diff --git a/net/proto-ip-tcp.c b/net/proto-ip-tcp.c index a8ae54f2c..60eb59e65 100644 --- a/net/proto-ip-tcp.c +++ b/net/proto-ip-tcp.c @@ -14,6 +14,8 @@ static const unsigned int tcp_opts[] = { TCP_QUEUE_SEQ, TCP_REPAIR_OPTIONS, TCP_FASTOPEN, TCP_TIMESTAMP, TCP_NOTSENT_LOWAT, TCP_CC_INFO, TCP_SAVE_SYN, TCP_SAVED_SYN, TCP_REPAIR_WINDOW, TCP_FASTOPEN_CONNECT, TCP_ULP, TCP_MD5SIG_EXT, + TCP_FASTOPEN_KEY, TCP_FASTOPEN_NO_COOKIE, TCP_ZEROCOPY_RECEIVE, TCP_INQ, + TCP_TX_DELAY, }; void tcp_setsockopt(struct sockopt *so, __unused__ struct socket_triplet *triplet) diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh index fdf21c7d3..a113793d0 100755 --- a/scripts/hashcheck.sh +++ b/scripts/hashcheck.sh @@ -41,7 +41,7 @@ check arch/x86/entry/syscalls/syscall_64.tbl da39a3ee5e6b4b0d3255bfef9560189 # new setsockopt values check include/uapi/asm-generic/socket.h 08003e14cf68ce62a2caeb8921db3e081a612f09 SO_ -check include/uapi/linux/tcp.h 8ea7461203395459db4a7ceaeea1f18893f74cec \#define\ TCP_ +check include/uapi/linux/tcp.h 149a6ee4bb5bb81fd8d44923c5846f85b7130d5e \#define\ TCP_ check include/uapi/linux/in.h 0116e6878df350e74ec730fd9f455efb95e510c8 \#define\ IP_ # Check for new packet families From f93256fb0da5c376ed790e10f6fa98d107877dfb Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 1 Aug 2019 20:17:51 -0400 Subject: [PATCH 080/119] Remove DEVEL crud --- Makefile | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/Makefile b/Makefile index 6ebf728fb..37bb98806 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,5 @@ VERSION="2019.06" -ifeq (,$(findstring pre,$(VERSION))) -DEVEL = 0 -else -DEVEL = 1 -endif - INSTALL_PREFIX ?= $(DESTDIR) INSTALL_PREFIX ?= $(HOME) NR_CPUS := $(shell grep -c ^processor /proc/cpuinfo) @@ -22,14 +16,6 @@ CFLAGS += -Wall -Wextra -I. -Iinclude/ -include config.h -Wimplicit -D_GNU_SOURC CCSTD := $(shell if $(CC) -std=gnu11 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-std=gnu11"; else echo "-std=gnu99"; fi) CFLAGS += $(CCSTD) -# -Werror only enabled during development, and on gcc 7+ -ifeq ($(DEVEL), 1) -CPP_MAJOR := $(shell $(CPP) -dumpversion 2>&1 | cut -d'.' -f1) -CPP_MINOR := $(shell $(CPP) -dumpversion 2>&1 | cut -d'.' -f2) -WERROR := $(shell if [ $(CPP_MAJOR) -ge 7 ] ; then echo "-Werror"; else echo ""; fi) -CFLAGS += $(WERROR) -endif - ifneq ($(SYSROOT),) CFLAGS += --sysroot=$(SYSROOT) endif @@ -59,9 +45,6 @@ LDLIBS += -lrt ifneq ($(shell $(CC) -v 2>&1 | grep -c "clang"), 1) CFLAGS += -Wlogical-op CFLAGS += -Wstrict-aliasing=3 -ifeq ($(DEVEL), 0) -CFLAGS += -Wno-maybe-uninitialized -endif endif # Sometimes useful for debugging. more useful with clang than gcc. From 45fdc97620063be4318b9b361482fa1b5463e1d5 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Mon, 18 Nov 2019 10:14:55 +0100 Subject: [PATCH 081/119] modify_ldt: include linux/types.h before ASSEMBLY == 1 Otherwise we see a lot of: In file included from /usr/include/bits/statx.h:30, from /usr/include/sys/stat.h:446, from include/files.h:3, from include/shm.h:6, from syscalls/x86/modify_ldt.c:12: /usr/include/linux/stat.h:57:2: error: unknown type name '__s64' 57 | __s64 tv_sec; | ^~~~~ /usr/include/linux/stat.h:58:2: error: unknown type name '__u32' 58 | __u32 tv_nsec; | ^~~~~ --- syscalls/x86/modify_ldt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/syscalls/x86/modify_ldt.c b/syscalls/x86/modify_ldt.c index f2eaf065d..0221561a5 100644 --- a/syscalls/x86/modify_ldt.c +++ b/syscalls/x86/modify_ldt.c @@ -6,6 +6,7 @@ */ #include #include +#include /* before __ASSEMBLY__ == 1 */ #define __ASSEMBLY__ 1 #include #include "sanitise.h" From af355e9497b60a14187cc97b1625deafa22c38ec Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Tue, 19 Nov 2019 08:00:48 +0100 Subject: [PATCH 082/119] syscalls: remove arch_prctl from x86_32 It's not defined there: /usr/lib/gcc/i586-suse-linux/9/../../../../i586-suse-linux/bin/ld: tables.o:(.data.rel+0x600): undefined reference to `syscall_arch_prctl' So define it as NULL instead. --- include/syscalls-i386.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/syscalls-i386.h b/include/syscalls-i386.h index 844ef68b2..847e2dea5 100644 --- a/include/syscalls-i386.h +++ b/include/syscalls-i386.h @@ -395,7 +395,7 @@ struct syscalltable syscalls_i386[] = { { .entry = &syscall_pkey_alloc }, { .entry = &syscall_pkey_free }, { .entry = &syscall_statx }, - { .entry = &syscall_arch_prctl }, + { .entry = NULL }, /* we don't care about arch_prctl */ { .entry = &syscall_io_pgetevents }, { .entry = &syscall_rseq }, { .entry = &syscall_semget }, From 1e9e055539f04cfbdf8ebce3aa5ce50efc4e2193 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 26 Dec 2019 13:09:31 -0500 Subject: [PATCH 083/119] Remove unnecessary abstraction. I had big plans for this stuff, but it never panned out, and I'm not likely to ever find time to work on it again, so just remove it all and make the common case faster. --- Makefile | 2 - child.c | 96 +------------------ childops/read-all-files.c | 61 ------------ childops/thrash-pid-files.c | 67 ------------- childops/truncate-testfile.c | 33 ------- include/child.h | 11 --- main.c | 11 +-- childops/random-syscall.c => random-syscall.c | 0 8 files changed, 6 insertions(+), 275 deletions(-) delete mode 100644 childops/read-all-files.c delete mode 100644 childops/thrash-pid-files.c delete mode 100644 childops/truncate-testfile.c rename childops/random-syscall.c => random-syscall.c (100%) diff --git a/Makefile b/Makefile index 37bb98806..77d7f8799 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,6 @@ VERSION_H := include/version.h HEADERS := $(patsubst %.h,%.h,$(wildcard *.h)) $(patsubst %.h,%.h,$(wildcard syscalls/*.h)) $(patsubst %.h,%.h,$(wildcard ioctls/*.h)) SRCS := $(wildcard *.c) \ - $(wildcard childops/*.c) \ $(wildcard fds/*.c) \ $(wildcard ioctls/*.c) \ $(wildcard mm/*.c) \ @@ -90,7 +89,6 @@ SRCS := $(wildcard *.c) \ $(SYSCALLS_ARCH) OBJS := $(sort $(patsubst %.c,%.o,$(wildcard *.c))) \ - $(sort $(patsubst %.c,%.o,$(wildcard childops/*.c))) \ $(sort $(patsubst %.c,%.o,$(wildcard fds/*.c))) \ $(sort $(patsubst %.c,%.o,$(wildcard ioctls/*.c))) \ $(sort $(patsubst %.c,%.o,$(wildcard mm/*.c))) \ diff --git a/child.c b/child.c index 2d7a67ebc..b648570d5 100644 --- a/child.c +++ b/child.c @@ -30,56 +30,6 @@ #include "udp.h" #include "utils.h" // zmalloc -enum childflags { - NONE, - ONESHOT, -}; - -struct child_funcs { - const char *name; - bool (*func)(struct childdata *child); - unsigned char likelyhood; - enum childtype type; - unsigned int flags; -}; - -static const struct child_funcs child_ops[] = { - { - .name = "rand_syscall", - .func = random_syscall, - .likelyhood = 100, - .type = CHILD_RAND_SYSCALL - }, -/* { - .name = "read_all_files", - .func = read_all_files, - .likelyhood = 10, - .type = CHILD_READ_ALL_FILES - }, - { - .name = "thrash_pid_files", - .func = thrash_pidfiles, - .likelyhood = 50, - .type = CHILD_THRASH_PID - }, - { - .name = "truncate_testfile", - .func = truncate_testfile, - .likelyhood = 10, - .type = CHILD_TRUNCATE_TESTFILE - }, -*/ -}; - -static const struct child_funcs root_child_ops[] = { - { - .name = "drop_privs", - .func = drop_privs, - .likelyhood = 90, - .type = CHILD_ROOT_DROP_PRIVS, - .flags = ONESHOT, - }, -}; /* * Provide temporary immunity from the reaper * This is useful if we're going to do something that might take @@ -445,29 +395,6 @@ static bool handle_sigreturn(int sigwas) } -static const struct child_funcs * set_new_op(struct childdata *child) -{ - const struct child_funcs *ops = child_ops; - size_t len = ARRAY_SIZE(child_ops); - - if (orig_uid == 0) { - if (child->dropped_privs == FALSE) { - ops = root_child_ops; - len = ARRAY_SIZE(root_child_ops); - } - } - - while (1) { - unsigned int i = rnd() % len; - - if (rnd() % 100 <= ops[i].likelyhood) { - //output(0, "Chose %s.\n", ops[i].name); - child->type = ops[i].type; - return ops; - } - } -} - /* * This is the child main loop, entered after init_child has completed * from the fork_children() loop. @@ -477,9 +404,6 @@ static const struct child_funcs * set_new_op(struct childdata *child) void child_process(struct childdata *child, int childno) { - const struct child_funcs *ops; - bool (*op)(struct childdata *child); - unsigned int loops; int ret; init_child(child, childno); @@ -495,10 +419,6 @@ void child_process(struct childdata *child, int childno) goto out; // Exit the child, things are getting too weird. } - op = NULL; - ops = NULL; - loops = 0; - while (shm->exit_reason == STILL_RUNNING) { /* If the parent reseeded, we should reflect the latest seed too. */ if (shm->seed != child->seed) { @@ -508,28 +428,16 @@ void child_process(struct childdata *child, int childno) periodic_work(); - /* Every NEW_OP_COUNT potentially pick a new childop. */ - if (loops == 0) { - ops = set_new_op(child); - op = ops->func; - loops = NEW_OP_COUNT; - } - - /* timestamp, and do the childop */ + /* timestamp, and do the syscall */ clock_gettime(CLOCK_MONOTONIC, &child->tp); - ret = op(child); + ret = random_syscall(child); child->op_nr++; if (ret == FAIL) goto out; - loops--; - - if (ops->flags & ONESHOT) - loops = 0; - if (syscalls_todo) { if (shm->stats.op_count >= syscalls_todo) { shm->exit_reason = EXIT_REACHED_COUNT; diff --git a/childops/read-all-files.c b/childops/read-all-files.c deleted file mode 100644 index 97ab2e299..000000000 --- a/childops/read-all-files.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Simple child to iterate over the entire fd list, opening/reading/closing as we go. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "arch.h" // page_size -#include "child.h" -#include "files.h" -#include "pathnames.h" -#include "random.h" - -bool read_all_files(__unused__ struct childdata *child) -{ - struct stat sb; - char *buffer; - unsigned int i; - int fd; - - for (i = 0; i < files_in_index; i++) { - int ret; - const char *filename; - - filename = fileindex[i]; - - fd = open(filename, O_RDONLY | O_NONBLOCK); - if (fd == -1) - continue; - - ret = (fstat(fd, &sb)); - if (ret == -1) - goto closeout; - - if (sb.st_size == 0) - sb.st_size = page_size; - - buffer = malloc(sb.st_size); - if (!buffer) - goto closeout; - - memset(buffer, 0, sb.st_size); - - ret = read(fd, buffer, sb.st_size); -// if (ret != -1) -// output(0, "%s:%s\n", filename, buffer); - - if (RAND_BOOL()) - sleep(1); - - free(buffer); -closeout: - close(fd); - } - return TRUE; -} diff --git a/childops/thrash-pid-files.c b/childops/thrash-pid-files.c deleted file mode 100644 index fc8c4e8a2..000000000 --- a/childops/thrash-pid-files.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Simple child to hammer on every child pids /proc// files. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "arch.h" // page_size -#include "child.h" -#include "pathnames.h" -#include "pids.h" -#include "random.h" -#include "shm.h" - -static void read_pid_files(pid_t pid, char *buffer) -{ - int fd; - int ret; - int n; - char filename[128]; - - n = sprintf(filename, "/proc/%d/status", pid); - filename[n] = 0; - - fd = open(filename, O_RDONLY); - if (fd < 0) - return; - - ret = read(fd, buffer, page_size); - if (ret < 0) { - close(fd); - return; - } - - close(fd); -} - -bool thrash_pidfiles(__unused__ struct childdata *child) -{ - unsigned int i; - char *buffer; - - buffer = zmalloc(page_size); - - for_each_child(i) { - pid_t pid = pids[i]; - - if (pid != EMPTY_PIDSLOT) - read_pid_files(pid, buffer); - - if (shm->exit_reason != STILL_RUNNING) { - free(buffer); - return FALSE; - } - - clock_gettime(CLOCK_MONOTONIC, &child->tp); - } - - free(buffer); - return TRUE; -} diff --git a/childops/truncate-testfile.c b/childops/truncate-testfile.c deleted file mode 100644 index e2bf9efa2..000000000 --- a/childops/truncate-testfile.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Pick a testfile, truncate it back to zero bytes, or a - * selection of random sizes. - */ - -#include -#include -#include "objects.h" -#include "random.h" -#include "testfile.h" -#include "utils.h" - -//TODO: stat the file, and divide by two - -bool truncate_testfile(struct childdata *child) -{ - int fd; - int ret; - off_t sizes[] = { 0, 4096, MB(1), GB(1) }; - - fd = get_rand_testfile_fd(); - if (fd < 0) - return FALSE; - - ret = ftruncate(fd, RAND_ARRAY(sizes)); - - clock_gettime(CLOCK_MONOTONIC, &child->tp); - - if (ret < 0) - return FALSE; - - return TRUE; -} diff --git a/include/child.h b/include/child.h index a6d315aa0..6fcd0ad7a 100644 --- a/include/child.h +++ b/include/child.h @@ -6,15 +6,6 @@ #include "objects.h" #include "syscall.h" -/* Childops */ -enum childtype { - CHILD_RAND_SYSCALL, - CHILD_READ_ALL_FILES, - CHILD_THRASH_PID, - CHILD_ROOT_DROP_PRIVS, - CHILD_TRUNCATE_TESTFILE, -}; - struct childdata { /* The actual syscall records each child uses. */ struct syscallrecord syscall; @@ -40,8 +31,6 @@ struct childdata { unsigned char kill_count; - enum childtype type; - bool dontkillme; /* provide temporary protection from the reaper. */ bool dropped_privs; diff --git a/main.c b/main.c index 9d82f1052..60e6272b3 100644 --- a/main.c +++ b/main.c @@ -300,9 +300,6 @@ static void stuck_syscall_info(struct childdata *child) if (shm->debug == FALSE) return; - if (child->type != CHILD_RAND_SYSCALL) - return; - rec = &child->syscall; if (trylock(&rec->lock) == FALSE) @@ -403,8 +400,8 @@ static bool is_child_making_progress(struct childdata *child) if (diff < 40) return FALSE; - debugf("sending another SIGKILL to child %u (pid:%u type:%u). [kill count:%u] [diff:%lu]\n", - child->num, pid, child->type, child->kill_count, diff); + debugf("sending another SIGKILL to child %u (pid:%u). [kill count:%u] [diff:%lu]\n", + child->num, pid, child->kill_count, diff); child->kill_count++; kill_pid(pid); @@ -613,8 +610,8 @@ static void handle_child(int childno, pid_t childpid, int childstatus) log_child_exited(child); - debugf("Child %d (pid:%u type:%u) exited after %ld operations.\n", - childno, childpid, child->type, child->op_nr); + debugf("Child %d (pid:%u) exited after %ld operations.\n", + childno, childpid, child->op_nr); reap_child(shm->children[childno]); if (child->pidstatfile != NULL) fclose(child->pidstatfile); diff --git a/childops/random-syscall.c b/random-syscall.c similarity index 100% rename from childops/random-syscall.c rename to random-syscall.c From c927ff98280b17883995b9f519428f7011e0d65f Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 26 Dec 2019 13:44:54 -0500 Subject: [PATCH 084/119] remove all the udp logging unfinished, kinda broken, and not likely to get worked on in this lifetime --- child.c | 15 -- fds/bpf.c | 10 +- fds/drm.c | 4 - fds/epoll.c | 11 +- fds/eventfd.c | 11 +- fds/fanotify_init.c | 12 +- fds/files.c | 18 +- fds/inotify.c | 9 +- fds/memfd.c | 13 +- fds/perf.c | 21 +-- fds/pipes.c | 13 +- fds/sockets.c | 14 +- fds/testfiles.c | 18 +- fds/timerfd.c | 10 +- fds/userfaultfd.c | 9 +- include/child.h | 2 - include/log.h | 1 - include/udp.h | 257 -------------------------- log.c | 43 +---- main.c | 56 ------ mm/maps.c | 16 +- objects.c | 5 - params.c | 4 - rand/seed.c | 7 - server/.gitignore | 1 - server/Makefile | 69 ------- server/child.c | 63 ------- server/child.h | 12 -- server/decode.c | 39 ---- server/decode.h | 41 ----- server/logfiles.c | 36 ---- server/logfiles.h | 4 - server/main.c | 47 ----- server/objects.c | 291 ----------------------------- server/packet.h | 9 - server/session.h | 19 -- server/syscalls.c | 82 --------- server/trinityserver.c | 408 ----------------------------------------- server/udp-server.c | 76 -------- server/udp-server.h | 12 -- server/utils.c | 31 ---- syscall.c | 25 --- syscalls/futex.c | 10 +- sysv-shm.c | 14 +- tables-biarch.c | 54 ------ tables-uniarch.c | 29 --- tables.c | 9 - trinity.1 | 2 - trinity.c | 1 - udp.c | 205 --------------------- 50 files changed, 40 insertions(+), 2128 deletions(-) delete mode 100644 include/udp.h delete mode 100644 server/.gitignore delete mode 100644 server/Makefile delete mode 100644 server/child.c delete mode 100644 server/child.h delete mode 100644 server/decode.c delete mode 100644 server/decode.h delete mode 100644 server/logfiles.c delete mode 100644 server/logfiles.h delete mode 100644 server/main.c delete mode 100644 server/objects.c delete mode 100644 server/packet.h delete mode 100644 server/session.h delete mode 100644 server/syscalls.c delete mode 100644 server/trinityserver.c delete mode 100644 server/udp-server.c delete mode 100644 server/udp-server.h delete mode 100644 server/utils.c delete mode 100644 udp.c diff --git a/child.c b/child.c index b648570d5..c86c3ea56 100644 --- a/child.c +++ b/child.c @@ -27,7 +27,6 @@ #include "tables.h" #include "trinity.h" // ARRAY_SIZE #include "uid.h" -#include "udp.h" #include "utils.h" // zmalloc /* @@ -183,17 +182,6 @@ static void bind_child_to_cpu(struct childdata *child) sched_setaffinity(pid, sizeof(set), &set); } -static void log_child_spawned(pid_t pid, int childno) -{ - struct msg_childspawned childmsg; - - if (logging_enabled == FALSE) - return; - - init_msgchildhdr(&childmsg.hdr, CHILD_SPAWNED, pid, childno); - sendudp((char *) &childmsg, sizeof(childmsg)); -} - /* * Called from the fork_children loop in the main process. */ @@ -202,8 +190,6 @@ static void init_child(struct childdata *child, int childno) pid_t pid = getpid(); char childname[17]; - log_child_spawned(pid, childno); - /* Wait for parent to set our childno */ while (pids[childno] != pid) { /* Make sure parent is actually alive to wait for us. */ @@ -388,7 +374,6 @@ static bool handle_sigreturn(int sigwas) if (sigwas != SIGALRM) output(1, "[%d] Back from signal handler! (sig was %s)\n", getpid(), strsignal(sigwas)); else { - log_child_signalled(child->num, pids[child->num], SIGALRM, child->op_nr); child->op_nr++; } return TRUE; diff --git a/fds/bpf.c b/fds/bpf.c index 4b763d131..a0adc1278 100644 --- a/fds/bpf.c +++ b/fds/bpf.c @@ -21,7 +21,6 @@ #include "shm.h" #include "compat.h" #include "trinity.h" -#include "udp.h" static int bpf(int cmd, union bpf_attr *attr, unsigned int size) { @@ -75,15 +74,10 @@ static struct bpf_fd_types bpf_fds[] = { static void bpf_map_dump(struct object *obj, bool global) { - struct msg_objcreatedbpfmap objmsg; u32 type = obj->bpfobj.map_type; - output(2, "bpf map fd:%d type:%s\n", obj->bpfobj.map_fd, (char *)&bpf_fds[type].name); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_BPFMAP, global, obj); - objmsg.map_fd = obj->bpfobj.map_fd; - objmsg.map_type = obj->bpfobj.map_type; - sendudp((char *) &objmsg, sizeof(objmsg)); + output(2, "bpf map fd:%d type:%s global:%d\n", + obj->bpfobj.map_fd, (char *)&bpf_fds[type].name, global); } static int open_bpf_fds(void) diff --git a/fds/drm.c b/fds/drm.c index 15f46aa56..fe246a774 100644 --- a/fds/drm.c +++ b/fds/drm.c @@ -35,10 +35,6 @@ static void drmfd_dump(struct object *obj, bool global) struct msg_objcreateddrm objmsg; output(2, "drmfd:%d\n", obj->drmfd); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_DRM, global, obj); - objmsg.fd = obj->drmfd; - sendudp((char *) &objmsg, sizeof(objmsg)); } static int create_dumb(__unused__ int fd) diff --git a/fds/epoll.c b/fds/epoll.c index 444d45941..73a9abc9f 100644 --- a/fds/epoll.c +++ b/fds/epoll.c @@ -12,7 +12,6 @@ #include "random.h" #include "sanitise.h" #include "shm.h" -#include "udp.h" #define MAX_EPOLL_FDS 10 @@ -24,15 +23,9 @@ static void epoll_destructor(struct object *obj) static void epoll_dump(struct object *obj, bool global) { struct epollobj *eo = &obj->epollobj; - struct msg_objcreatedepoll objmsg; - output(2, "epoll fd:%d used create1?:%d flags:%x\n", eo->fd, eo->create1, eo->flags); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_EPOLL, global, obj); - objmsg.fd = eo->fd; - objmsg.create1 = eo->create1; - objmsg.flags = eo->flags; - sendudp((char *) &objmsg, sizeof(objmsg)); + output(2, "epoll fd:%d used create1?:%d flags:%x global:%d\n", + eo->fd, eo->create1, eo->flags, global); } static int open_epoll_fds(void) diff --git a/fds/eventfd.c b/fds/eventfd.c index 77aa4b077..5f1c40721 100644 --- a/fds/eventfd.c +++ b/fds/eventfd.c @@ -13,7 +13,6 @@ #include "random.h" #include "sanitise.h" #include "shm.h" -#include "udp.h" #include "compat.h" static void eventfd_destructor(struct object *obj) @@ -24,15 +23,9 @@ static void eventfd_destructor(struct object *obj) static void eventfd_dump(struct object *obj, bool global) { struct eventfdobj *eo = &obj->eventfdobj; - struct msg_objcreatedeventfd objmsg; - output(2, "eventfd fd:%d count:%d flags:%x\n", eo->fd, eo->count, eo->flags); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_EVENTFD, global, obj); - objmsg.fd = eo->fd; - objmsg.count = eo->count; - objmsg.flags = eo->flags; - sendudp((char *) &objmsg, sizeof(objmsg)); + output(2, "eventfd fd:%d count:%d flags:%x global:%d\n", + eo->fd, eo->count, eo->flags, global); } static int open_eventfd_fds(void) diff --git a/fds/fanotify_init.c b/fds/fanotify_init.c index bf4bea763..deb934e90 100644 --- a/fds/fanotify_init.c +++ b/fds/fanotify_init.c @@ -16,7 +16,6 @@ #include "compat.h" #include "trinity.h" #include "utils.h" -#include "udp.h" #define NR_FANOTIFYFDS 10 @@ -37,16 +36,9 @@ static void fanotifyfd_destructor(struct object *obj) static void fanotifyfd_dump(struct object *obj, bool global) { struct fanotifyobj *fo = &obj->fanotifyobj; - struct msg_objcreatedfanotify objmsg; - output(2, "fanotify fd:%d flags:%x eventflags:%x\n", - fo->fd, fo->flags, fo->eventflags); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_FANOTIFY, global, obj); - objmsg.fd = fo->fd; - objmsg.flags = fo->flags; - objmsg.eventflags = fo->eventflags; - sendudp((char *) &objmsg, sizeof(objmsg)); + output(2, "fanotify fd:%d flags:%x eventflags:%x global:%d\n", + fo->fd, fo->flags, fo->eventflags, global); } static int open_fanotify_fds(void) diff --git a/fds/files.c b/fds/files.c index 9d6e2d41c..7fda5a099 100644 --- a/fds/files.c +++ b/fds/files.c @@ -14,7 +14,6 @@ #include "pathnames.h" #include "random.h" #include "syscalls/syscalls.h" -#include "udp.h" int open_with_fopen(const char *filename, int flags) { @@ -95,20 +94,9 @@ static void filefd_destructor(struct object *obj) static void filefd_dump(struct object *obj, bool global) { struct fileobj *fo = &obj->fileobj; - struct msg_objcreatedfile objmsg; - int len = strlen(fo->filename); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_FILE, global, obj); - strncpy(objmsg.filename, fo->filename, len); - memset(objmsg.filename + len, 0, MAX_PATH_LEN - len); - objmsg.flags = fo->flags; - objmsg.fd = fo->fd; - objmsg.fopened = fo->fopened; - objmsg.fcntl_flags = fo->fcntl_flags; - sendudp((char *) &objmsg, sizeof(objmsg)); - - output(2, "file fd:%d filename:%s flags:%x fopened:%d fcntl_flags:%x\n", - fo->fd, fo->filename, fo->flags, fo->fopened, fo->fcntl_flags); + + output(2, "file fd:%d filename:%s flags:%x fopened:%d fcntl_flags:%x global:%d\n", + fo->fd, fo->filename, fo->flags, fo->fopened, fo->fcntl_flags, global); } static int open_files(void) diff --git a/fds/inotify.c b/fds/inotify.c index c0368f7cf..fb7fac73e 100644 --- a/fds/inotify.c +++ b/fds/inotify.c @@ -12,7 +12,6 @@ #include "random.h" #include "sanitise.h" #include "shm.h" -#include "udp.h" #define MAX_INOTIFY_FDS 5 @@ -24,14 +23,8 @@ static void inotify_destructor(struct object *obj) static void inotify_dump(struct object *obj, bool global) { struct inotifyobj *io = &obj->inotifyobj; - struct msg_objcreatedinotify objmsg; - output(2, "inotify fd:%d flags:%x\n", io->fd, io->flags); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_INOTIFY, global, obj); - objmsg.fd = io->fd; - objmsg.flags = io->flags; - sendudp((char *) &objmsg, sizeof(objmsg)); + output(2, "inotify fd:%d flags:%x global:%d\n", io->fd, io->flags, global); } static int open_inotify_fds(void) diff --git a/fds/memfd.c b/fds/memfd.c index fc50322e4..3c47620f7 100644 --- a/fds/memfd.c +++ b/fds/memfd.c @@ -15,7 +15,6 @@ #include "shm.h" #include "compat.h" #include "trinity.h" -#include "udp.h" #ifndef USE_MEMFD_CREATE @@ -40,17 +39,9 @@ static void memfd_destructor(struct object *obj) static void memfd_dump(struct object *obj, bool global) { struct memfdobj *mo = &obj->memfdobj; - struct msg_objcreatedmemfd objmsg; - int len; - output(2, "memfd fd:%d name:%s flags:%x\n", mo->fd, mo->name, mo->flags); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_MEMFD, global, obj); - objmsg.fd = mo->fd; - len = strlen(mo->name); - memcpy(objmsg.name, mo->name, len); - objmsg.flags = mo->flags; - sendudp((char *) &objmsg, sizeof(objmsg)); + output(2, "memfd fd:%d name:%s flags:%x global:%d\n", + mo->fd, mo->name, mo->flags, global); } static int open_memfd_fds(void) diff --git a/fds/perf.c b/fds/perf.c index d88ea37c3..546967c36 100644 --- a/fds/perf.c +++ b/fds/perf.c @@ -13,7 +13,6 @@ #include "perf.h" #include "shm.h" #include "sanitise.h" -#include "udp.h" #include "utils.h" #define MAX_PERF_FDS 10 @@ -27,32 +26,16 @@ static void perffd_destructor(struct object *obj) static void perffd_dump(struct object *obj, bool global) { struct perfobj *po = &obj->perfobj; - struct perf_event_attr *attr = obj->perfobj.eventattr; - struct msg_objcreatedperf *objmsg; - char *p = (char *)attr; // unsigned int i; - unsigned int perfsize = sizeof(struct perf_event_attr); - output(2, "perf fd: %d pid:%d cpu:%d group_fd:%d flags:%lx\n", - po->fd, po->pid, po->cpu, po->group_fd, po->flags); + output(2, "perf fd: %d pid:%d cpu:%d group_fd:%d flags:%lx global:%d\n", + po->fd, po->pid, po->cpu, po->group_fd, po->flags, global); /* output(2, " perf_event_attr:"); for (i = 0; i < perfsize ; i++) { output(CONT, "%02x ", (unsigned char) p[i]); } output(CONT, "\n"); */ - objmsg = zmalloc(sizeof(struct msg_objcreatedperf) + perfsize); - init_msgobjhdr(&objmsg->hdr, OBJ_CREATED_PERF, global, obj); - objmsg->fd = po->fd; - objmsg->pid = po->pid; - objmsg->cpu = po->cpu; - objmsg->group_fd = po->group_fd; - objmsg->flags = po->flags; - objmsg->eventattrsize = perfsize; - memcpy(&objmsg->eventattr, p, perfsize); - sendudp((char *) objmsg, sizeof(objmsg) + perfsize); - - free(objmsg); } static int open_perf_fds(void) diff --git a/fds/pipes.c b/fds/pipes.c index d3e522f0a..72c33d824 100644 --- a/fds/pipes.c +++ b/fds/pipes.c @@ -15,7 +15,6 @@ #include "sanitise.h" #include "shm.h" #include "trinity.h" -#include "udp.h" static void pipefd_destructor(struct object *obj) { @@ -25,17 +24,11 @@ static void pipefd_destructor(struct object *obj) static void pipefd_dump(struct object *obj, bool global) { struct pipeobj *po = &obj->pipeobj; - struct msg_objcreatedpipe objmsg; - output(2, "pipe fd:%d flags:%x [%s]\n", + output(2, "pipe fd:%d flags:%x [%s] global:%d\n", po->fd, po->flags, - po->reader ? "reader" : "writer"); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_PIPE, global, obj); - objmsg.fd = po->fd; - objmsg.flags = po->flags; - objmsg.reader = po->reader; - sendudp((char *) &objmsg, sizeof(objmsg)); + po->reader ? "reader" : "writer", + global); } static void open_pipe_pair(unsigned int flags) diff --git a/fds/sockets.c b/fds/sockets.c index 48dee9b92..a34c69459 100644 --- a/fds/sockets.c +++ b/fds/sockets.c @@ -17,7 +17,6 @@ #include "sanitise.h" #include "shm.h" #include "trinity.h" -#include "udp.h" #include "uid.h" #include "utils.h" @@ -410,18 +409,11 @@ static void socket_destructor(struct object *obj) static void socket_dump(struct object *obj, bool global) { struct socketinfo *si = &obj->sockinfo; - struct msg_objcreatedsocket objmsg; - output(2, "socket fd:%u domain:%u (%s) type:0x%u protocol:%u\n", + output(2, "socket fd:%u domain:%u (%s) type:0x%u protocol:%u global:%d\n", si->fd, si->triplet.family, get_domain_name(si->triplet.family), - si->triplet.type, si->triplet.protocol); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_SOCKET, global, obj); - objmsg.si.fd = si->fd; - objmsg.si.triplet.family = si->triplet.family; - objmsg.si.triplet.type = si->triplet.type; - objmsg.si.triplet.protocol = si->triplet.protocol; - sendudp((char *) &objmsg, sizeof(objmsg)); + si->triplet.type, si->triplet.protocol, + global); } static int open_sockets(void) diff --git a/fds/testfiles.c b/fds/testfiles.c index 18ffd7e27..af9dbf2ff 100644 --- a/fds/testfiles.c +++ b/fds/testfiles.c @@ -17,7 +17,6 @@ #include "syscalls/syscalls.h" #include "testfile.h" #include "utils.h" -#include "udp.h" #define MAX_TESTFILES 4 #define MAX_TESTFILE_FDS 20 @@ -30,20 +29,9 @@ static void testfile_destructor(struct object *obj) static void testfile_dump(struct object *obj, bool global) { struct fileobj *fo = &obj->testfileobj; - struct msg_objcreatedfile objmsg; - int len = strlen(fo->filename); - - output(2, "testfile fd:%d filename:%s flags:%x fopened:%d fcntl_flags:%x\n", - fo->fd, fo->filename, fo->flags, fo->fopened, fo->fcntl_flags); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_TESTFILE, global, obj); - strncpy(objmsg.filename, fo->filename, len); - memset(objmsg.filename + len, 0, MAX_PATH_LEN - len); - objmsg.flags = fo->flags; - objmsg.fd = fo->fd; - objmsg.fopened = fo->fopened; - objmsg.fcntl_flags = fo->fcntl_flags; - sendudp((char *) &objmsg, sizeof(objmsg)); + + output(2, "testfile fd:%d filename:%s flags:%x fopened:%d fcntl_flags:%x global:%d\n", + fo->fd, fo->filename, fo->flags, fo->fopened, fo->fcntl_flags, global); } static int open_testfile(struct object *obj, char *filename) diff --git a/fds/timerfd.c b/fds/timerfd.c index 57f5b11fa..b315049a8 100644 --- a/fds/timerfd.c +++ b/fds/timerfd.c @@ -14,7 +14,6 @@ #include "sanitise.h" #include "shm.h" #include "compat.h" -#include "udp.h" static void timerfd_destructor(struct object *obj) { @@ -24,15 +23,8 @@ static void timerfd_destructor(struct object *obj) static void timerfd_dump(struct object *obj, bool global) { struct timerfdobj *to = &obj->timerfdobj; - struct msg_objcreatedtimerfd objmsg; - output(2, "timerfd fd:%d clockid:%d flags:%x\n", to->fd, to->clockid, to->flags); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_TIMERFD, global, obj); - objmsg.fd = to->fd; - objmsg.clockid = to->clockid; - objmsg.flags = to->flags; - sendudp((char *) &objmsg, sizeof(objmsg)); + output(2, "timerfd fd:%d clockid:%d flags:%x global:%d\n", to->fd, to->clockid, to->flags, global); } static int __open_timerfd_fds(int clockid) diff --git a/fds/userfaultfd.c b/fds/userfaultfd.c index 8cd16a676..82124c34d 100644 --- a/fds/userfaultfd.c +++ b/fds/userfaultfd.c @@ -15,7 +15,6 @@ #include "shm.h" #include "compat.h" #include "trinity.h" -#include "udp.h" static int userfaultfd_create(__unused__ unsigned int flag) { @@ -34,14 +33,8 @@ static void userfaultfd_destructor(struct object *obj) static void userfaultfd_dump(struct object *obj, bool global) { struct userfaultobj *uo = &obj->userfaultobj; - struct msg_objcreateduserfault objmsg; - output(2, "userfault fd:%d flags:%x\n", uo->fd, uo->flags); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_USERFAULT, global, obj); - objmsg.fd = uo->fd; - objmsg.flags = uo->flags; - sendudp((char *) &objmsg, sizeof(objmsg)); + output(2, "userfault fd:%d flags:%x global:%d\n", uo->fd, uo->flags, global); } static int open_userfaultfds(void) diff --git a/include/child.h b/include/child.h index 6fcd0ad7a..3fc09f00d 100644 --- a/include/child.h +++ b/include/child.h @@ -50,8 +50,6 @@ void set_dontkillme(struct childdata *child, bool state); void reap_child(struct childdata *child); -void log_child_signalled(int childno, pid_t pid, int sig, unsigned long op_nr); - /* Childops */ bool random_syscall(struct childdata *child); bool read_all_files(struct childdata *child); diff --git a/include/log.h b/include/log.h index 18e355584..acb90a0e7 100644 --- a/include/log.h +++ b/include/log.h @@ -9,7 +9,6 @@ void shutdown_logging(void); enum { LOGGING_DISABLED, LOGGING_FILES, - LOGGING_UDP, }; void init_child_logging(struct childdata *child); diff --git a/include/udp.h b/include/udp.h deleted file mode 100644 index d153b482f..000000000 --- a/include/udp.h +++ /dev/null @@ -1,257 +0,0 @@ -#pragma once - -#include -#include -#include "exit.h" -#include "maps.h" -#include "pathnames.h" -#include "socketinfo.h" -#include "types.h" - -#define TRINITY_LOG_PORT 6665 - -#define TRINITY_UDP_VERSION 0 - -extern int logging_enabled; - -enum logmsgtypes { - MAIN_STARTED, - MAIN_EXITING, - - CHILD_SPAWNED, - CHILD_EXITED, - CHILD_SIGNALLED, - - OBJ_CREATED_FILE, - OBJ_CREATED_MAP, - OBJ_CREATED_PIPE, - OBJ_CREATED_PERF, - OBJ_CREATED_EPOLL, - OBJ_CREATED_EVENTFD, - OBJ_CREATED_TIMERFD, - OBJ_CREATED_TESTFILE, - OBJ_CREATED_MEMFD, - OBJ_CREATED_DRM, - OBJ_CREATED_INOTIFY, - OBJ_CREATED_USERFAULT, - OBJ_CREATED_FANOTIFY, - OBJ_CREATED_BPFMAP, - OBJ_CREATED_SOCKET, - OBJ_CREATED_FUTEX, - OBJ_CREATED_SHM, - - OBJ_DESTROYED, - - SYSCALLS_ENABLED, - SYSCALL_PREP, - SYSCALL_RESULT, - - RESEED, - - MAX_LOGMSGTYPE, -}; - -struct trinity_msghdr { - enum logmsgtypes type; - pid_t pid; -}; - -struct trinity_msgobjhdr { - enum logmsgtypes type; - pid_t pid; - bool global; - void *address; -}; - -struct trinity_msgchildhdr { - enum logmsgtypes type; - struct timespec tp; - pid_t pid; - int childno; -}; - -void init_msghdr(struct trinity_msghdr *hdr, enum logmsgtypes type); -void init_msgobjhdr(struct trinity_msgobjhdr *hdr, enum logmsgtypes type, bool global, struct object *obj); -void init_msgchildhdr(struct trinity_msgchildhdr *hdr, enum logmsgtypes type, pid_t pid, int childno); - -void init_udp_logging(char *optarg); -void shutdown_udp_logging(void); -void sendudp(char *buffer, size_t len); - -struct msg_mainstarted { - struct trinity_msghdr hdr; - void * shm_begin; - void * shm_end; - unsigned int initial_seed; -}; - -struct msg_mainexiting { - struct trinity_msghdr hdr; - enum exit_reasons reason; -}; - -struct msg_childspawned { - struct trinity_msgchildhdr hdr; -}; - -struct msg_childexited { - struct trinity_msgchildhdr hdr; - unsigned long op_nr; -}; - -struct msg_childsignalled { - struct trinity_msgchildhdr hdr; - int sig; - unsigned long op_nr; -}; - -struct msg_objcreatedfile { - struct trinity_msgobjhdr hdr; - char filename[MAX_PATH_LEN]; - int flags; - int fd; - bool fopened; - int fcntl_flags; -}; - -struct msg_objcreatedmap { - struct trinity_msgobjhdr hdr; - void *start; - char name[MAPS_NAME_MAX_LEN]; - int prot; - unsigned char type; - unsigned long size; -}; - -struct msg_objcreatedpipe { - struct trinity_msgobjhdr hdr; - int fd; - int flags; - bool reader; -}; - -struct msg_objcreatedperf { - struct trinity_msgobjhdr hdr; - int fd; - pid_t pid; - int cpu; - int group_fd; - unsigned long flags; - int eventattrsize; - // eventattr bytestream follows immediately afterwards. - char eventattr[]; -}; - -struct msg_objcreatedepoll { - struct trinity_msgobjhdr hdr; - int fd; - bool create1; - int flags; -}; - -struct msg_objcreatedeventfd { - struct trinity_msgobjhdr hdr; - int fd; - int count; - int flags; -}; - -struct msg_objcreatedtimerfd { - struct trinity_msgobjhdr hdr; - int fd; - int clockid; - int flags; -}; - -struct msg_objcreatedmemfd { - struct trinity_msgobjhdr hdr; - int fd; - char name[MAX_PATH_LEN]; - int flags; -}; - -struct msg_objcreateddrm { - struct trinity_msgobjhdr hdr; - int fd; -}; - -struct msg_objcreatedinotify { - struct trinity_msgobjhdr hdr; - int fd; - int flags; -}; - -struct msg_objcreateduserfault { - struct trinity_msgobjhdr hdr; - int fd; - int flags; -}; - -struct msg_objcreatedfanotify { - struct trinity_msgobjhdr hdr; - int fd; - int flags; - int eventflags; -}; - -struct msg_objcreatedbpfmap { - struct trinity_msgobjhdr hdr; - int map_type; - int map_fd; -}; - -struct msg_objcreatedsocket { - struct trinity_msgobjhdr hdr; - struct socketinfo si; -}; - -struct msg_objcreatedfutex { - struct trinity_msgobjhdr hdr; - int futex; - pid_t owner; -}; - -struct msg_objcreatedshm { - struct trinity_msgobjhdr hdr; - void *ptr; - int id; - size_t size; - int flags; -}; - -struct msg_objdestroyed { - struct trinity_msgobjhdr hdr; -}; - -struct msg_syscallsenabled { - struct trinity_msghdr hdr; - unsigned int nr_enabled; - bool arch_is_biarch; // whether capable - bool is_64; // whether the list in this msg is 64bit/32bit - int entries[]; -}; - -struct msg_syscallprep { - struct trinity_msgchildhdr hdr; - unsigned long sequence_nr; - unsigned int nr; - bool is32bit; - unsigned long a1; - unsigned long a2; - unsigned long a3; - unsigned long a4; - unsigned long a5; - unsigned long a6; -}; - -struct msg_syscallresult { - struct trinity_msgchildhdr hdr; - unsigned long sequence_nr; - long retval; - int errno_post; -}; - -struct msg_reseed { - struct trinity_msghdr hdr; - unsigned int new_seed; -}; diff --git a/log.c b/log.c index 3c77c085d..f434fb069 100644 --- a/log.c +++ b/log.c @@ -9,58 +9,31 @@ #include "params.h" // logging, quiet_level #include "pids.h" #include "shm.h" -#include "udp.h" void init_logging(void) { - switch (logging) { - case LOGGING_DISABLED: + if (logging == LOGGING_DISABLED) return; - case LOGGING_FILES: - open_main_logfile(); - return; - case LOGGING_UDP: - init_udp_logging(logging_args); - return; - } + open_main_logfile(); } void shutdown_logging(void) { - switch (logging) { - case LOGGING_DISABLED: - return; - case LOGGING_FILES: - close_logfile(&mainlogfile); - return; - case LOGGING_UDP: + if (logging == LOGGING_DISABLED) return; - } + close_logfile(&mainlogfile); } void init_child_logging(struct childdata *child) { - switch (logging) { - case LOGGING_DISABLED: + if (logging == LOGGING_DISABLED) return; - case LOGGING_FILES: - open_child_logfile(child); - return; - case LOGGING_UDP: - shutdown_udp_logging(); - return; - } + open_child_logfile(child); } void shutdown_child_logging(struct childdata *child) { - switch (logging) { - case LOGGING_DISABLED: - return; - case LOGGING_FILES: - close_logfile(&child->logfile); - return; - case LOGGING_UDP: + if (logging == LOGGING_DISABLED) return; - } + close_logfile(&child->logfile); } diff --git a/main.c b/main.c index 60e6272b3..7493f0202 100644 --- a/main.c +++ b/main.c @@ -22,7 +22,6 @@ #include "tables.h" #include "taint.h" #include "trinity.h" -#include "udp.h" static void handle_child(int childno, pid_t childpid, int childstatus); @@ -508,17 +507,6 @@ static void fork_children(void) shm->ready = TRUE; } -void log_child_signalled(int childno, pid_t pid, int sig, unsigned long op_nr) -{ - struct msg_childsignalled childmsg; - - init_msgchildhdr(&childmsg.hdr, CHILD_SIGNALLED, pid, childno); - childmsg.sig = sig; - childmsg.op_nr = op_nr; - - sendudp((char *) &childmsg, sizeof(childmsg)); -} - static void handle_childsig(int childno, int childstatus, bool stop) { struct childdata *child; @@ -560,7 +548,6 @@ static void handle_childsig(int childno, int childstatus, bool stop) else { debugf("got a signal from child %d (pid %d) (%s)\n", childno, pid, strsignal(WTERMSIG(childstatus))); - log_child_signalled(childno, pid, WTERMSIG(childstatus), child->op_nr); } reap_child(shm->children[childno]); if (child->pidstatfile) @@ -584,16 +571,6 @@ static void handle_childsig(int childno, int childstatus, bool stop) } } -static void log_child_exited(struct childdata *child) -{ - struct msg_childexited childmsg; - - init_msgchildhdr(&childmsg.hdr, CHILD_EXITED, - pids[child->num], child->num); - childmsg.op_nr = child->op_nr; - sendudp((char *) &childmsg, sizeof(childmsg)); -} - static void handle_child(int childno, pid_t childpid, int childstatus) { switch (childpid) { @@ -608,8 +585,6 @@ static void handle_child(int childno, pid_t childpid, int childstatus) if (WIFEXITED(childstatus)) { struct childdata *child = shm->children[childno]; - log_child_exited(child); - debugf("Child %d (pid:%u) exited after %ld operations.\n", childno, childpid, child->op_nr); reap_child(shm->children[childno]); @@ -730,38 +705,8 @@ static void taint_check(void) } } -static void log_main_started(void) -{ - struct msg_mainstarted mainmsg; - - if (logging_enabled == FALSE) - return; - - init_msghdr(&mainmsg.hdr, MAIN_STARTED); - mainmsg.shm_begin = shm; - mainmsg.shm_end = shm + shm_size - 1; - mainmsg.initial_seed = shm->seed; - - sendudp((char *) &mainmsg, sizeof(mainmsg)); -} - -static void log_main_exiting(void) -{ - struct msg_mainexiting mainmsg; - - if (logging_enabled == FALSE) - return; - - init_msghdr(&mainmsg.hdr, MAIN_EXITING); - mainmsg.reason = shm->exit_reason; - - sendudp((char *) &mainmsg, sizeof(mainmsg)); -} - void main_loop(void) { - log_main_started(); - fork_children(); while (shm->exit_reason == STILL_RUNNING) { @@ -831,7 +776,6 @@ void main_loop(void) dont_wait: output(0, "Bailing main loop because %s.\n", decode_exit(shm->exit_reason)); - log_main_exiting(); } diff --git a/mm/maps.c b/mm/maps.c index c5e1e6c09..8a5fd0441 100644 --- a/mm/maps.c +++ b/mm/maps.c @@ -11,7 +11,6 @@ #include "random.h" #include "shm.h" #include "utils.h" -#include "udp.h" /* * Return a pointer a previous mmap() that we did, either during startup, @@ -63,24 +62,13 @@ void map_destructor(struct object *obj) void map_dump(struct object *obj, bool global) { struct map *m; - struct msg_objcreatedmap objmsg; char buf[11]; - int len; m = &obj->map; - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_MAP, global, obj); - objmsg.start = m->ptr; - len = strlen(m->name); - memcpy(objmsg.name, m->name, len); - memset(objmsg.name + len, 0, MAPS_NAME_MAX_LEN - len); - objmsg.prot = m->prot; - objmsg.type = m->type; - objmsg.size = m->size; - sendudp((char *) &objmsg, sizeof(objmsg)); - sizeunit(m->size, buf); - output(2, " start: %p size:%s name: %s\n", m->ptr, buf, m->name); + output(2, " start: %p size:%s name: %s global:%d\n", + m->ptr, buf, m->name, global); } /* diff --git a/objects.c b/objects.c index 5311ec056..f8880205f 100644 --- a/objects.c +++ b/objects.c @@ -3,7 +3,6 @@ #include "random.h" #include "shm.h" #include "trinity.h" -#include "udp.h" #include "utils.h" struct object * alloc_object(void) @@ -116,10 +115,6 @@ bool objects_empty(enum objecttype type) void destroy_object(struct object *obj, bool global, enum objecttype type) { struct objhead *head; - struct msg_objdestroyed objmsg; - - init_msgobjhdr(&objmsg.hdr, OBJ_DESTROYED, global, obj); - sendudp((char *) &objmsg, sizeof(objmsg)); list_del(&obj->list); diff --git a/params.c b/params.c index cfdd8b69c..ac76054c0 100644 --- a/params.c +++ b/params.c @@ -18,7 +18,6 @@ #include "tables.h" #include "taint.h" #include "trinity.h" // progname -#include "udp.h" bool set_debug = FALSE; bool do_specific_syscall = FALSE; @@ -151,9 +150,6 @@ static void parse_logging(void) return; } } - - // try the arg as a hostname. - logging = LOGGING_UDP; } void parse_args(int argc, char *argv[]) diff --git a/rand/seed.c b/rand/seed.c index 16b529a1c..386abf076 100644 --- a/rand/seed.c +++ b/rand/seed.c @@ -31,7 +31,6 @@ #include "params.h" // 'user_set_seed' #include "pids.h" #include "random.h" -#include "udp.h" #include "utils.h" /* The actual seed lives in the shm. This variable is used @@ -93,8 +92,6 @@ void set_seed(struct childdata *child) */ void reseed(void) { - struct msg_reseed reseedmsg; - if (getpid() != mainpid) { outputerr("Reseeding should only happen from parent!\n"); exit(EXIT_FAILURE); @@ -102,8 +99,4 @@ void reseed(void) /* We are reseeding. */ shm->seed += max_children; - - init_msghdr(&reseedmsg.hdr, RESEED); - reseedmsg.new_seed = shm->seed; - sendudp((char *) &reseedmsg, sizeof(reseedmsg)); } diff --git a/server/.gitignore b/server/.gitignore deleted file mode 100644 index 5e3e9362e..000000000 --- a/server/.gitignore +++ /dev/null @@ -1 +0,0 @@ -trinityserver diff --git a/server/Makefile b/server/Makefile deleted file mode 100644 index b0458252a..000000000 --- a/server/Makefile +++ /dev/null @@ -1,69 +0,0 @@ -NR_CPUS := $(shell grep -c ^processor /proc/cpuinfo) - -CFLAGS ?= -g -O2 -D_FORTIFY_SOURCE=2 -CFLAGS += -Wall -Wextra -I. -I../include/ -Wimplicit -D_GNU_SOURCE -D__linux__ - -CCSTD := $(shell if $(CC) -std=gnu11 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-std=gnu11"; else echo "-std=gnu99"; fi) -CFLAGS += $(CCSTD) - -CFLAGS += -Wdeclaration-after-statement -CFLAGS += -Wformat=2 -CFLAGS += -Winit-self -CFLAGS += -Wnested-externs -CFLAGS += -Wpacked -CFLAGS += -Wshadow -CFLAGS += -Wundef -CFLAGS += -Wwrite-strings -CFLAGS += -Wno-format-nonliteral -CFLAGS += -Wstrict-prototypes -Wmissing-prototypes - -# gcc only. -ifneq ($(shell $(CC) -v 2>&1 | grep -c "clang"), 1) -CFLAGS += -Wlogical-op -CFLAGS += -Wstrict-aliasing=3 -ifeq ($(DEVEL), 0) -CFLAGS += -Wno-maybe-uninitialized -endif -endif - -# Sometimes useful for debugging. more useful with clang than gcc. -#CFLAGS += -fsanitize=address - -LDFLAGS = -pthread - -V = @ -Q = $(V:1=) -QUIET_CC = $(Q:@=@echo ' CC '$@;) - - -all: trinityserver - -HEADERS := $(patsubst %.h,%.h,$(wildcard *.h)) - -SRCS := $(wildcard *.c) - -OBJS := $(sort $(patsubst %.c,%.o,$(wildcard *.c))) - -DEPDIR= .deps - --include $(SRCS:%.c=$(DEPDIR)/%.d) - -trinityserver: $(OBJS) $(HEADERS) - $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o trinityserver $(OBJS) $(LDLIBS) - -df = $(DEPDIR)/$(*D)/$(*F) - -%.o : %.c - $(QUIET_CC)$(CC) $(CFLAGS) -o $@ -c $< - @mkdir -p $(DEPDIR)/$(*D) - @$(CC) -MM $(CFLAGS) $*.c > $(df).d - @mv -f $(df).d $(df).d.tmp - @sed -e 's|.*:|$*.o:|' <$(df).d.tmp > $(df).d - @sed -e 's/.*://' -e 's/\\$$//' < $(df).d.tmp | fmt -1 | \ - sed -e 's/^ *//' -e 's/$$/:/' >> $(df).d - @rm -f $(df).d.tmp - -clean: - @rm -f $(OBJS) - @rm -f core.* - @rm -f trinityserver diff --git a/server/child.c b/server/child.c deleted file mode 100644 index dbe86dc2e..000000000 --- a/server/child.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "decode.h" -#include "exit.h" -#include "session.h" -#include "socketinfo.h" -#include "trinity.h" -#include "types.h" -#include "udp.h" -#include "utils.h" - -char * decode_child_spawned(char *buf) -{ - struct msg_childspawned *childmsg; - struct timespec *ts; - struct childdata *child; - void *p = zmalloc(1024); - - childmsg = (struct msg_childspawned *) buf; - ts = &childmsg->hdr.tp; - sprintf(p, "%d.%d Child spawned. id:%d pid:%d\n", - (int) ts->tv_sec, (int) ts->tv_nsec, - childmsg->hdr.childno, childmsg->hdr.pid); - - child = &session.children[childmsg->hdr.childno]; - child->childpid = childmsg->hdr.pid; - return p; -} - -char * decode_child_exited(char *buf) -{ - struct msg_childexited *childmsg; - struct timespec *ts; - void *p = zmalloc(1024); - - childmsg = (struct msg_childexited *) buf; - ts = &childmsg->hdr.tp; - sprintf(p, "%d.%d Child exited. id:%d pid:%d lastop:%lu\n", - (int) ts->tv_sec, (int) ts->tv_nsec, - childmsg->hdr.childno, childmsg->hdr.pid, childmsg->op_nr); - return p; -} - -char * decode_child_signalled(char *buf) -{ - struct msg_childsignalled *childmsg; - struct timespec *ts; - void *p = zmalloc(1024); - - childmsg = (struct msg_childsignalled *) buf; - ts = &childmsg->hdr.tp; - sprintf(p, "%d.%d Child signal. id:%d pid:%d signal: %s. After op:%lu\n", - (int) ts->tv_sec, (int) ts->tv_nsec, - childmsg->hdr.childno, childmsg->hdr.pid, strsignal(childmsg->sig), - childmsg->op_nr); - return p; -} diff --git a/server/child.h b/server/child.h deleted file mode 100644 index 6252118d3..000000000 --- a/server/child.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "packet.h" - -struct childdata { - pid_t childpid; - struct packet packets; - unsigned int packetcount; - pthread_mutex_t drainmutex; - pthread_mutex_t packetmutex; - int logfile; -}; diff --git a/server/decode.c b/server/decode.c deleted file mode 100644 index 90a11d828..000000000 --- a/server/decode.c +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "decode.h" - -const struct msgfunc decodefuncs[MAX_LOGMSGTYPE] = { - [MAIN_STARTED] = { decode_main_started }, - [MAIN_EXITING] = { decode_main_exiting }, - [CHILD_SPAWNED] = { decode_child_spawned }, - [CHILD_EXITED] = { decode_child_exited }, - [CHILD_SIGNALLED] = { decode_child_signalled }, - [OBJ_CREATED_FILE] = { decode_obj_created_file }, - [OBJ_CREATED_MAP] = { decode_obj_created_map }, - [OBJ_CREATED_PIPE] = { decode_obj_created_pipe }, - [OBJ_CREATED_PERF] = { decode_obj_created_perf }, - [OBJ_CREATED_EPOLL] = { decode_obj_created_epoll }, - [OBJ_CREATED_EVENTFD] = { decode_obj_created_eventfd }, - [OBJ_CREATED_TIMERFD] = { decode_obj_created_timerfd }, - [OBJ_CREATED_TESTFILE] = { decode_obj_created_testfile }, - [OBJ_CREATED_MEMFD] = { decode_obj_created_memfd }, - [OBJ_CREATED_DRM] = { decode_obj_created_drm }, - [OBJ_CREATED_INOTIFY] = { decode_obj_created_inotify }, - [OBJ_CREATED_USERFAULT] = { decode_obj_created_userfault }, - [OBJ_CREATED_FANOTIFY] = { decode_obj_created_fanotify }, - [OBJ_CREATED_BPFMAP] = { decode_obj_created_bpfmap }, - [OBJ_CREATED_SOCKET] = { decode_obj_created_socket }, - [OBJ_CREATED_FUTEX] = { decode_obj_created_futex }, - [OBJ_CREATED_SHM] = { decode_obj_created_shm }, - [OBJ_DESTROYED] = { decode_obj_destroyed }, - [SYSCALLS_ENABLED] = { decode_syscalls_enabled }, - [SYSCALL_PREP] = { decode_syscall_prep }, - [SYSCALL_RESULT] = { decode_syscall_result }, - [RESEED] = { decode_reseed }, -}; diff --git a/server/decode.h b/server/decode.h deleted file mode 100644 index 8a64523e9..000000000 --- a/server/decode.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -//#include "trinity.h" -#include "udp.h" - -struct msgfunc { - char * (*func)(char *buf); -}; - -extern const struct msgfunc decodefuncs[MAX_LOGMSGTYPE]; - -char *decode_child_spawned(char *buf); -char *decode_child_exited(char *buf); -char *decode_child_signalled(char *buf); - -char *decode_main_started(char *buf); -char *decode_main_exiting(char *buf); -char *decode_reseed(char *buf); - -char *decode_obj_created_file(char *buf); -char *decode_obj_created_map(char *buf); -char *decode_obj_created_pipe(char *buf); -char *decode_obj_created_perf(char *buf); -char *decode_obj_created_epoll(char *buf); -char *decode_obj_created_eventfd(char *buf); -char *decode_obj_created_timerfd(char *buf); -char *decode_obj_created_testfile(char *buf); -char *decode_obj_created_memfd(char *buf); -char *decode_obj_created_drm(char *buf); -char *decode_obj_created_inotify(char *buf); -char *decode_obj_created_userfault(char *buf); -char *decode_obj_created_fanotify(char *buf); -char *decode_obj_created_bpfmap(char *buf); -char *decode_obj_created_socket(char *buf); -char *decode_obj_created_futex(char *buf); -char *decode_obj_created_shm(char *buf); -char *decode_obj_destroyed(char *buf); - -char *decode_syscalls_enabled(char *buf); -char *decode_syscall_prep(char *buf); -char *decode_syscall_result(char *buf); diff --git a/server/logfiles.c b/server/logfiles.c deleted file mode 100644 index e77d16ed7..000000000 --- a/server/logfiles.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "logfiles.h" -#include "utils.h" - -int open_logfile(const char *logfilename) -{ - int fd; - - fd = open(logfilename, O_WRONLY | O_TRUNC | O_CREAT, 0666); - if (!fd) - printf("## couldn't open logfile %s\n", logfilename); - - return fd; -} - -int open_child_logfile(unsigned int num) -{ - char *logfilename; - int fd; - - logfilename = zmalloc(64); - sprintf(logfilename, "trinity-child%u.log", num); - - fd = open_logfile(logfilename); - if (!fd) - exit(EXIT_FAILURE); - - free(logfilename); - return fd; -} diff --git a/server/logfiles.h b/server/logfiles.h deleted file mode 100644 index b3a14738a..000000000 --- a/server/logfiles.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -int open_logfile(const char *logfilename); -int open_child_logfile(unsigned int num); diff --git a/server/main.c b/server/main.c deleted file mode 100644 index 26dbdb03e..000000000 --- a/server/main.c +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "decode.h" -#include "exit.h" -#include "trinity.h" -#include "types.h" -#include "udp.h" -#include "utils.h" - -char * decode_main_started(char *buf) -{ - struct msg_mainstarted *mainmsg; - void *p = zmalloc(1024); - - mainmsg = (struct msg_mainstarted *) buf; - sprintf(p, "Main started. pid:%d shm:%p-%p initial seed: %u\n", - mainmsg->hdr.pid, mainmsg->shm_begin, mainmsg->shm_end, - mainmsg->initial_seed); - return p; -} - -char * decode_main_exiting(char *buf) -{ - struct msg_mainexiting *mainmsg; - void *p = zmalloc(1024); - - mainmsg = (struct msg_mainexiting *) buf; - sprintf(p, "Main exiting. pid:%d Reason: %s\n", mainmsg->hdr.pid, decode_exit(mainmsg->reason)); - return p; -} - -char * decode_reseed(char *buf) -{ - struct msg_reseed *rsmsg; - void *p = zmalloc(1024); - - rsmsg = (struct msg_reseed *) buf; - - sprintf(p, "pid %d Reseed. New seed = %d\n", rsmsg->hdr.pid, rsmsg->new_seed); - return p; -} diff --git a/server/objects.c b/server/objects.c deleted file mode 100644 index 66b046502..000000000 --- a/server/objects.c +++ /dev/null @@ -1,291 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "decode.h" -#include "exit.h" -#include "socketinfo.h" -#include "trinity.h" -#include "types.h" -#include "udp.h" -#include "utils.h" - -char * decode_obj_created_file(char *buf) -{ - struct msg_objcreatedfile *objmsg; - void *p = zmalloc(1024); - - objmsg = (struct msg_objcreatedfile *) buf; - - if (objmsg->fopened) { - sprintf(p, "%s file object created at %p by pid %d: fd %d = fopen(\"%s\") ; fcntl(fd, 0x%x)\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, - objmsg->fd, objmsg->filename, - objmsg->fcntl_flags); - } else { - sprintf(p, "%s file object created at %p by pid %d: fd %d = open(\"%s\", 0x%x)\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, - objmsg->fd, objmsg->filename, objmsg->flags); - } - return p; -} - -char * decode_obj_created_map(char *buf) -{ - struct msg_objcreatedmap *objmsg; - void *p = zmalloc(1024); - const char *maptypes[] = { - "initial anon mmap", - "child created anon mmap", - "mmap'd file", - }; - objmsg = (struct msg_objcreatedmap *) buf; - - sprintf(p, "%s map object created at %p by pid %d: start:%p size:%ld name:%s prot:%x type:%s\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, - objmsg->start, objmsg->size, objmsg->name, objmsg->prot, maptypes[objmsg->type - 1]); - return p; -} - -char * decode_obj_created_pipe(char *buf) -{ - struct msg_objcreatedpipe *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objcreatedpipe *) buf; - - sprintf(p, "%s pipe object created at %p by pid %d: fd:%d flags:%x [%s]\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, - objmsg->fd, objmsg->flags, - objmsg->reader ? "reader" : "writer"); - return p; -} - -char * decode_obj_created_perf(char *buf) -{ - struct msg_objcreatedperf *objmsg; - char *str = zmalloc(1024); - char *p = str; - char *ptr; - int i; - - objmsg = (struct msg_objcreatedperf *) buf; - p += sprintf(p, "%s perf object created at %p by pid %d: fd:%d pid:%d cpu:%d group_fd:%d flags:%lx eventattr len:%d\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, - objmsg->fd, objmsg->pid, objmsg->cpu, objmsg->group_fd, objmsg->flags, - objmsg->eventattrsize); - - p += sprintf(p, "perf_event_attr: "); - ptr = (char *) &objmsg->eventattr; - for (i = 0; i < objmsg->eventattrsize; i++) { - p += sprintf(p, "%02x ", (unsigned char) ptr[i]); - } - p += sprintf(p, "\n"); - return str; -} - -char * decode_obj_created_epoll(char *buf) -{ - struct msg_objcreatedepoll *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objcreatedepoll *) buf; - - sprintf(p, "%s epoll object created at %p by pid %d: fd:%d create1: %s flags:%x\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, objmsg->fd, - objmsg->create1 ? "false" : "true", - objmsg->flags); - return p; -} - -char * decode_obj_created_eventfd(char *buf) -{ - struct msg_objcreatedeventfd *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objcreatedeventfd *) buf; - - sprintf(p, "%s eventfd object created at %p by pid %d: fd:%d count: %d flags:%x\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, objmsg->fd, - objmsg->count, objmsg->flags); - return p; -} - - -char * decode_obj_created_timerfd(char *buf) -{ - struct msg_objcreatedtimerfd *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objcreatedtimerfd *) buf; - - sprintf(p, "%s timerfd object created at %p by pid %d: fd:%d clockid: %d flags:%x\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, objmsg->fd, - objmsg->clockid, objmsg->flags); - return p; -} - -char * decode_obj_created_testfile(char *buf) -{ - struct msg_objcreatedfile *objmsg; - void *p = zmalloc(1024); - - objmsg = (struct msg_objcreatedfile *) buf; - - if (objmsg->fopened) { - sprintf(p, "%s testfile object created at %p by pid %d: fd %d = fopen(\"%s\") ; fcntl(fd, 0x%x)\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, - objmsg->fd, objmsg->filename, - objmsg->fcntl_flags); - } else { - sprintf(p, "%s testfile object created at %p by pid %d: fd %d = open(\"%s\", 0x%x)\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, - objmsg->fd, objmsg->filename, objmsg->flags); - } - return p; -} - -char * decode_obj_created_memfd(char *buf) -{ - struct msg_objcreatedmemfd *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objcreatedmemfd *) buf; - - sprintf(p, "%s memfd object created at %p by pid %d: fd:%d name: %s flags:%x\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, objmsg->fd, - objmsg->name, objmsg->flags); - return p; -} - -char * decode_obj_created_drm(char *buf) -{ - struct msg_objcreateddrm *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objcreateddrm *) buf; - - sprintf(p, "%s drm object created at %p by pid %d: fd:%d\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, objmsg->fd); - return p; -} - -char * decode_obj_created_inotify(char *buf) -{ - struct msg_objcreatedinotify *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objcreatedinotify *) buf; - - sprintf(p, "%s inotify object created at %p by pid %d: fd:%d flags:%x\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, objmsg->fd, objmsg->flags); - return p; -} - -char * decode_obj_created_userfault(char *buf) -{ - struct msg_objcreateduserfault *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objcreateduserfault *) buf; - - sprintf(p, "%s userfault object created at %p by pid %d: fd:%d flags:%x\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, objmsg->fd, objmsg->flags); - return p; -} - -char * decode_obj_created_fanotify(char *buf) -{ - struct msg_objcreatedfanotify *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objcreatedfanotify *) buf; - - sprintf(p, "%s fanotify object created at %p by pid %d: fd:%d flags:%x eventflags:%x\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, objmsg->fd, - objmsg->flags, objmsg->eventflags); - return p; -} - -char * decode_obj_created_bpfmap(char *buf) -{ - struct msg_objcreatedbpfmap *objmsg; - void *p = zmalloc(1024); - const char *bpfmaptypes[] = { - "hash", "array", "prog array", "perf_event_array", - "percpu hash", "percpu array", "stack trace", "cgroup array", - "lru hash", "lru hash (no common LRU)", "LRU percpu hash", "LPM TRIE", - }; - - objmsg = (struct msg_objcreatedbpfmap *) buf; - - sprintf(p, "%s bpf map object created at %p by pid %d: fd:%d type:%s\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, objmsg->map_fd, - bpfmaptypes[objmsg->map_type]); - return p; -} - -char * decode_obj_created_socket(char *buf) -{ - struct msg_objcreatedsocket *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objcreatedsocket *) buf; - - sprintf(p, "%s socket object created at %p by pid %d: fd:%d family:%d type:%d protocol:%d\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, objmsg->si.fd, - objmsg->si.triplet.family, - objmsg->si.triplet.type, - objmsg->si.triplet.protocol); - return p; -} - -char * decode_obj_created_futex(char *buf) -{ - struct msg_objcreatedfutex *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objcreatedfutex *) buf; - - sprintf(p, "%s futex object created at %p by pid %d: futex:%d owner:%d\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, - objmsg->futex, objmsg->owner); - return p; -} - -char * decode_obj_created_shm(char *buf) -{ - struct msg_objcreatedshm *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objcreatedshm *) buf; - - sprintf(p, "%s shm object created at %p by pid %d: id:%u size:%zu flags:%x ptr:%p\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, - objmsg->id, objmsg->size, objmsg->flags, objmsg->ptr); - return p; -} - -char * decode_obj_destroyed(char *buf) -{ - struct msg_objdestroyed *objmsg; - void *p = zmalloc(1024); - objmsg = (struct msg_objdestroyed *) buf; - - sprintf(p, "%s object at %p destroyed by pid %d. type:%d\n", - objmsg->hdr.global ? "global" : "local", - objmsg->hdr.address, objmsg->hdr.pid, - objmsg->hdr.type); - return p; -} diff --git a/server/packet.h b/server/packet.h deleted file mode 100644 index 3880afea3..000000000 --- a/server/packet.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "list.h" - -struct packet { - struct list_head list; - struct timespec tp; - char * data; -}; diff --git a/server/session.h b/server/session.h deleted file mode 100644 index e822279c3..000000000 --- a/server/session.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "child.h" - -// TODO: dynamically allocate -#define MAX_CHILDREN 1024 - -struct fuzzsession { - pid_t mainpid; - unsigned int num_children; - struct childdata children[MAX_CHILDREN]; - pthread_t decodethread; - - pthread_mutex_t packetmutex; - struct packet mainpackets; - int logfile; -}; - -extern struct fuzzsession session; diff --git a/server/syscalls.c b/server/syscalls.c deleted file mode 100644 index cba7091fa..000000000 --- a/server/syscalls.c +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "decode.h" -#include "exit.h" -#include "socketinfo.h" -#include "trinity.h" -#include "types.h" -#include "udp.h" -#include "utils.h" - -char * decode_syscalls_enabled(char *buf) -{ - struct msg_syscallsenabled *scmsg; - char *p = zmalloc(1024); - char *str = p; - int nr; - int i; - - scmsg = (struct msg_syscallsenabled *) buf; - nr = scmsg->nr_enabled; - if (scmsg->arch_is_biarch == TRUE) { - p += sprintf(p, "Enabled %d %s bit syscalls : { ", nr, scmsg->is_64 ? "64" : "32"); - for (i = 0 ; i < nr; i++) - p += sprintf(p, "%d ", scmsg->entries[i]); - sprintf(p, "}\n"); - } else { - p += sprintf(p, "Enabled %d syscalls : { ", nr); - for (i = 0 ; i < nr; i++) - p += sprintf(p, "%d ", scmsg->entries[i]); - sprintf(p, "}\n"); - } - return str; -} - -/* - * TODO: buffer the 'prep' stage, and only output it when we get a 'result' msg with matching - * child/seqnr. - * - if we see another prep from the same child, we must have segv'd. - * (maybe handle this in decode_child_signalled ?) - */ -char * decode_syscall_prep(char *buf) -{ - struct msg_syscallprep *scmsg; - struct timespec *ts; - void *p = zmalloc(1024); - - scmsg = (struct msg_syscallprep *) buf; - ts = &scmsg->hdr.tp; - - sprintf(p, "%d.%d Child %d [%d] syscall prep [op:%ld] %d%s (0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx)\n", - (int) ts->tv_sec, (int) ts->tv_nsec, - scmsg->hdr.childno, scmsg->hdr.pid, scmsg->sequence_nr, scmsg->nr, - scmsg->is32bit ? "[32bit]" : "", - scmsg->a1, scmsg->a2, scmsg->a3, - scmsg->a4, scmsg->a5, scmsg->a6); - return p; -} - -char * decode_syscall_result(char *buf) -{ - struct msg_syscallresult *scmsg; - struct timespec *ts; - void *p = zmalloc(1024); - - scmsg = (struct msg_syscallresult *) buf; - ts = &scmsg->hdr.tp; - - sprintf(p, "%d.%d Child %d [%d] syscall [op:%ld] result %lx %s\n", - (int) ts->tv_sec, (int) ts->tv_nsec, - scmsg->hdr.childno, scmsg->hdr.pid, scmsg->sequence_nr, - scmsg->retval, - scmsg->retval == -1 ? strerror(scmsg->errno_post) : "" - ); - return p; -} diff --git a/server/trinityserver.c b/server/trinityserver.c deleted file mode 100644 index e44291265..000000000 --- a/server/trinityserver.c +++ /dev/null @@ -1,408 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "child.h" -#include "decode.h" -#include "exit.h" -#include "handshake.h" -#include "list.h" -#include "logfiles.h" -#include "packet.h" -#include "session.h" -#include "trinity.h" -#include "types.h" -#include "udp.h" -#include "udp-server.h" -#include "utils.h" - -struct fuzzsession session; - -static enum logmsgtypes get_packet_type(struct packet *pkt) -{ - char *buffer = pkt->data; - return buffer[0]; -} - -static char * decode(struct packet *pkt) -{ - char *str; - enum logmsgtypes type = get_packet_type(pkt); - - str = decodefuncs[type].func((char *) pkt->data); - - list_del(&pkt->list); - free(pkt->data); - free(pkt); - return str; -} - -static void decode_this_packet(struct childdata *child, struct packet *pkt) -{ - char *str = decode(pkt); - int ret; - - ret = write(child->logfile, str, strlen(str)); - if (ret == -1) - printf("error writing to child logfile: %s\n", strerror(errno)); - free(str); - - child->packetcount--; -} - -static void decode_one_child(struct childdata *child) -{ - struct list_head *node = NULL, *tmp; - - pthread_mutex_lock(&child->packetmutex); - if (list_empty(&child->packets.list)) - goto done; - - list_for_each_safe(node, tmp, &child->packets.list) { - struct packet *currpkt; - - currpkt = (struct packet *) node; - - decode_this_packet(child, currpkt); - } -done: - pthread_mutex_unlock(&child->packetmutex); -} - -static void * decoder_func(void *data) -{ - struct fuzzsession *fs = (struct fuzzsession *) data; - - while (1) { - unsigned int i; - - for (i = 0; i < fs->num_children; i++) { - struct childdata *child = &fs->children[i]; - - if (pthread_mutex_trylock(&child->drainmutex) == 0) { - decode_one_child(child); - pthread_mutex_unlock(&child->drainmutex); - } - } - pthread_yield(); - } - - //TODO: if main session exits, we should exit this thread. - return NULL; -} - -static void * decoder_main_func(void *data) -{ - struct fuzzsession *fs = (struct fuzzsession *) data; - struct list_head *node, *tmp; - - while (1) { - // iterate through queue for main - pthread_mutex_lock(&fs->packetmutex); - if (!list_empty(&fs->mainpackets.list)) { - list_for_each_safe(node, tmp, &fs->mainpackets.list) { - if (node != NULL) { - char *str; - int ret; - str = decode((struct packet *)node); - ret = write(fs->logfile, str, strlen(str)); - if (ret == -1) - printf("error writing to main logfile: %s\n", strerror(errno)); - free(str); - } - } - } - pthread_mutex_unlock(&fs->packetmutex); - pthread_yield(); - //TODO: if main session exits, we should exit this thread. - } - return NULL; -} - -/* simple 2-way handshake just to agree on protocol. */ -static bool __handshake(void) -{ - struct hellostruct *hs = (struct hellostruct *) buf; - int i; - int ret; - - /* if we got here, we know we got a correct size message, but the contents - * need to match also for it to be a handshake. - */ - if (strncmp((char *)hs->hello, "Trinity\0", HELLOLEN) != 0) - return FALSE; - - printf("Handshake request. (Pid:%d Numchildren:%d) sending reply (%ld bytes)\n", - hs->mainpid, hs->num_children, strlen(serverreply)); - - session.mainpid = hs->mainpid; - session.num_children = hs->num_children; - //TODO: mkdir("logs/") ; chdir ("logs/") - //TODO mkdir session-mainpid - session.logfile = open_logfile("trinity-main.log"); - - INIT_LIST_HEAD(&session.mainpackets.list); - pthread_mutex_init(&session.packetmutex, NULL); - - for (i = 0; i < hs->num_children; i++) { - struct childdata *child = &session.children[i]; - - child->logfile = open_child_logfile(i); - INIT_LIST_HEAD(&child->packets.list); - child->packetcount = 0; - pthread_mutex_init(&child->packetmutex, NULL); - pthread_mutex_init(&child->drainmutex, NULL); - } - - ret = pthread_create(&session.decodethread, NULL, decoder_func, &session); - assert(!ret); - - printf("Received handshake from %s:%d\n", inet_ntoa(udpclient.sin_addr), ntohs(udpclient.sin_port)); - sendudp(serverreply, strlen(serverreply)); - - return TRUE; -} - -static void handshake(void) -{ - int ret = -1; - -retry: while (ret != sizeof(struct hellostruct)) - ret = readudp(); - - if (__handshake() == FALSE) { - ret = -1; - goto retry; - } -} - -static bool check_handshake(int ret) -{ - if (ret != sizeof(struct hellostruct)) - return FALSE; - - return __handshake(); -} - -static void add_to_main_queue(void *data, int len) -{ - struct packet *pkt = malloc(sizeof(struct packet)); - // TODO: find session from pid in pkt. (easy for now, we only support 1 session) - struct fuzzsession *fs = &session; - pkt->data = malloc(len); - if (pkt->data == NULL) { - free(pkt); - return; - } - memcpy(pkt->data, data, len); - - pthread_mutex_lock(&fs->packetmutex); - list_add_tail(&pkt->list, &fs->mainpackets.list); - pthread_mutex_unlock(&fs->packetmutex); -} - -static void add_to_child_queue(void *data, int len) -{ - struct packet *pkt = malloc(sizeof(struct packet)); - // TODO: find session from pid in pkt. (easy for now, we only support 1 session) - // TODO: might be easier if we have mainpid in pkt to find session. - struct fuzzsession *fs = &session; - struct trinity_msgchildhdr *childhdr; - struct childdata *child; - struct list_head *node, *tmp, *tail; - struct packet *listpkt; - - pkt->data = malloc(len); - if (pkt->data == NULL) { - free(pkt); - return; - } - memcpy(pkt->data, data, len); - - // We know this is a child packet, so we can assume a trinity_msgchildhdr - // FIXME: Not true for objects! - childhdr = (struct trinity_msgchildhdr *) pkt->data; - child = &fs->children[childhdr->childno]; - - pkt->tp = childhdr->tp; - - pthread_mutex_lock(&child->packetmutex); - - if (list_empty(&child->packets.list)) - goto tail_add; - - /* Can we just go at the end ? */ - tail = child->packets.list.prev; - listpkt = (struct packet *) tail; - - if (childhdr->tp.tv_sec > listpkt->tp.tv_sec) - goto tail_add; - - if (childhdr->tp.tv_sec == listpkt->tp.tv_sec) { - if (childhdr->tp.tv_nsec > listpkt->tp.tv_nsec) - goto tail_add; - if (childhdr->tp.tv_nsec == listpkt->tp.tv_nsec) - goto drop_dupe; - } - - /* crap, we've got something out of order, scan the list for the right place - * to insert it. TODO: Might be quicker to search backwards from the tail - */ - list_for_each_safe(node, tmp, &child->packets.list) { - listpkt = (struct packet *) node; - - if (childhdr->tp.tv_sec > listpkt->tp.tv_sec) - continue; - if (childhdr->tp.tv_nsec > listpkt->tp.tv_nsec) - continue; - if (childhdr->tp.tv_nsec == listpkt->tp.tv_nsec) - goto drop_dupe; - - list_add(&pkt->list, node->prev); - goto done; - } - -tail_add: - - list_add_tail(&pkt->list, &child->packets.list); -done: - child->packetcount++; - pthread_mutex_unlock(&child->packetmutex); - return; - -drop_dupe: - free(pkt->data); - free(pkt); - pthread_mutex_unlock(&child->packetmutex); -} - -static struct childdata * get_child_from_pkt(void *data) -{ - struct fuzzsession *fs = &session; - struct trinity_msgchildhdr *childhdr; - - childhdr = (struct trinity_msgchildhdr *) data; - return &fs->children[childhdr->childno]; -} - -static void queue_object_msg(struct trinity_msgobjhdr *obj, int len) -{ - if (obj->global == TRUE) - add_to_main_queue(obj, len); -// TODO: figure out which child created this obj and pass it down -// else -// add_to_child_queue(obj, len); -} - -static void * queue_packets(__unused__ void *data) -{ - int len; - enum logmsgtypes type; - unsigned long numpkts = 0; - - while (1) { - struct childdata *child; - int ret = readudp(); - - if (ret <= 0) - continue; - - len = ret; - - numpkts++; - printf("RX:%lu\r", numpkts); - - /* We may see a new handshake appear at any time - * if a client dies without sending a 'main has exited' message. - * Just re-handshake for now. Later, we'll tear down any context etc. - */ - if (check_handshake(len) == TRUE) - continue; - - type = buf[0]; - - if (type >= MAX_LOGMSGTYPE) { - printf("Unknown msgtype: %d\n", type); - continue; - } - - switch (type) { - case MAIN_STARTED: - case MAIN_EXITING: - case SYSCALLS_ENABLED: - case RESEED: - add_to_main_queue(buf, len); - break; - - case OBJ_CREATED_FILE ... OBJ_DESTROYED: - queue_object_msg((struct trinity_msgobjhdr *) buf, len); - break; - - case CHILD_SPAWNED: - child = get_child_from_pkt(buf); - pthread_mutex_lock(&child->drainmutex); - add_to_child_queue(buf, len); - break; - - case CHILD_EXITED: - add_to_child_queue(buf, len); - child = get_child_from_pkt(buf); - pthread_mutex_unlock(&child->drainmutex); - break; - - case CHILD_SIGNALLED: - add_to_child_queue(buf, len); - //child = get_child_from_pkt(buf); - //FIXME: only if signal = child exits. - //pthread_mutex_unlock(&child->drainmutex); - break; - - case SYSCALL_PREP: - case SYSCALL_RESULT: - add_to_child_queue(buf, len); - break; - - case MAX_LOGMSGTYPE: - break; - }; - } - return NULL; -} - -int main(__unused__ int argc, __unused__ char* argv[]) -{ - pthread_t udpthread, decode_main_thr; - struct fuzzsession *fs = &session; // TODO; find session from packets - int ret; - - if (setup_socket() == FALSE) - goto out; - - handshake(); // TODO: eventually fold into queue_packets - - ret = pthread_create(&udpthread, NULL, queue_packets, NULL); // TODO: pass session down. one thread per session. - assert(!ret); - - while (1) { - ret = pthread_create(&decode_main_thr, NULL, decoder_main_func, fs); - assert(!ret); - pthread_join(decode_main_thr, NULL); - } - - - pthread_exit(NULL); - - close(socketfd); -out: - exit(EXIT_FAILURE); -} diff --git a/server/udp-server.c b/server/udp-server.c deleted file mode 100644 index a04907382..000000000 --- a/server/udp-server.c +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "udp.h" -#include "udp-server.h" - -// TODO: ipv6 - -struct sockaddr_in udpclient; - -int socketfd; - -#define MAXBUF 10240 -char buf[MAXBUF]; - -void sendudp(char *buffer, size_t len) -{ - int ret; - - ret = sendto(socketfd, buffer, len, 0, (struct sockaddr *) &udpclient, sizeof(udpclient)); - if (ret == -1) { - fprintf(stderr, "sendto: %s\n", strerror(errno)); - } -} - -size_t readudp(void) -{ - int ret; - socklen_t addrlen = 0; - - memset(buf, 0, MAXBUF); - - addrlen = sizeof(udpclient); - ret = recvfrom(socketfd, buf, MAXBUF, 0, (struct sockaddr *) &udpclient, &addrlen); - if (ret == -1) - fprintf(stderr, "recvfrom: %s\n", strerror(errno)); - - return ret; -} - -bool setup_socket(void) -{ - struct sockaddr_in udpserver; - int rcvbuf; - int ret; - - socketfd = socket(AF_INET, SOCK_DGRAM, 0); - if (socketfd == -1) { - fprintf(stderr, "Could not create a socket\n"); - return FALSE; - } - - udpserver.sin_family = AF_INET; - udpserver.sin_addr.s_addr = htonl(INADDR_ANY); - udpserver.sin_port = htons(TRINITY_LOG_PORT); - - if (bind(socketfd, (struct sockaddr *) &udpserver, sizeof(udpserver)) != 0) { - fprintf(stderr, "Could not bind to address!\n"); - close(socketfd); - return FALSE; - } - - rcvbuf = 1000000 * 64; //TODO: adjust 64 to max_children - ret = setsockopt(socketfd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf)); - if (ret == 0) - printf("Recieve socket buffer size set to %d\n", rcvbuf); - - return TRUE; -} diff --git a/server/udp-server.h b/server/udp-server.h deleted file mode 100644 index f69331561..000000000 --- a/server/udp-server.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -extern struct sockaddr_in udpclient; - -extern int socketfd; - -#define MAXBUF 10240 -extern char buf[MAXBUF]; - -void sendudp(char *buffer, size_t len); -size_t readudp(void); -bool setup_socket(void); diff --git a/server/utils.c b/server/utils.c deleted file mode 100644 index 67832ccec..000000000 --- a/server/utils.c +++ /dev/null @@ -1,31 +0,0 @@ -//TODO: eventually this file will go away, and we'll just share parts of -// the top-level utils.c - -#include -#include -#include -#include -#include -#include -#include "utils.h" - -void * __zmalloc(size_t size, const char *func) -{ - void *p; - - p = malloc(size); - if (p == NULL) { - /* Maybe we mlockall'd everything. Try and undo that, and retry. */ - munlockall(); - p = malloc(size); - if (p != NULL) - goto done; - - printf("%s: malloc(%zu) failure.\n", func, size); - exit(EXIT_FAILURE); - } - -done: - memset(p, 0, size); - return p; -} diff --git a/syscall.c b/syscall.c index 000244b96..4829b7694 100644 --- a/syscall.c +++ b/syscall.c @@ -24,7 +24,6 @@ #include "tables.h" #include "taint.h" #include "trinity.h" -#include "udp.h" #include "uid.h" #include "utils.h" @@ -185,23 +184,8 @@ static void do_extrafork(struct syscallrecord *rec) void do_syscall(struct syscallrecord *rec) { struct syscallentry *entry; - struct msg_syscallprep scmsg; - struct childdata *child = this_child(); unsigned int call; - init_msgchildhdr(&scmsg.hdr, SYSCALL_PREP, pids[child->num], child->num); - scmsg.sequence_nr = child->op_nr; - scmsg.nr = rec->nr; - scmsg.is32bit = rec->do32bit; - scmsg.a1 = rec->a1; - scmsg.a2 = rec->a2; - scmsg.a3 = rec->a3; - scmsg.a4 = rec->a4; - scmsg.a5 = rec->a5; - scmsg.a6 = rec->a6; - rec->tp = scmsg.hdr.tp; - sendudp((char *) &scmsg, sizeof(scmsg)); - call = rec->nr; entry = syscalls[call].entry; @@ -253,17 +237,8 @@ static void generic_post(const enum argtype type, unsigned long reg) void handle_syscall_ret(struct syscallrecord *rec) { struct syscallentry *entry; - struct msg_syscallresult scmsg; - struct childdata *child = this_child(); unsigned int call; - init_msgchildhdr(&scmsg.hdr, SYSCALL_RESULT, pids[child->num], child->num); - scmsg.hdr.tp = rec->tp; - scmsg.sequence_nr = child->op_nr; - scmsg.retval = rec->retval; - scmsg.errno_post = rec->errno_post; - sendudp((char *) &scmsg, sizeof(scmsg)); - call = rec->nr; entry = syscalls[call].entry; diff --git a/syscalls/futex.c b/syscalls/futex.c index 51d8d55d2..e69769f97 100644 --- a/syscalls/futex.c +++ b/syscalls/futex.c @@ -14,7 +14,6 @@ #include "maps.h" #include "random.h" #include "sanitise.h" -#include "udp.h" #define FUTEX_UNLOCKED (0) #define FUTEX_LOCKED (!FUTEX_UNLOCKED) @@ -114,14 +113,7 @@ static inline void futex_init_lock(struct __lock *thislock) static void dump_futex(struct object *obj, __unused__ bool global) { - struct msg_objcreatedfutex objmsg; - - output(0, "futex: %x owner:%d\n", obj->lock.futex, obj->lock.owner_pid); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_FUTEX, global, obj); - objmsg.futex = obj->lock.futex; - objmsg.owner = obj->lock.owner_pid; - sendudp((char *) &objmsg, sizeof(objmsg)); + output(0, "futex: %x owner:%d global:%d\n", obj->lock.futex, obj->lock.owner_pid, global); } void create_futexes(void) diff --git a/sysv-shm.c b/sysv-shm.c index 5a917c06f..57bc56c9d 100644 --- a/sysv-shm.c +++ b/sysv-shm.c @@ -10,23 +10,13 @@ #include "random.h" #include "sysv-shm.h" #include "objects.h" -#include "udp.h" #include "utils.h" static void dump_sysv_shm(struct object *obj, bool global) { - struct msg_objcreatedshm objmsg; - - output(0, "sysv_shm: id:%u size:%ld flags:%x ptr:%p\n", + output(0, "sysv_shm: id:%u size:%ld flags:%x ptr:%p global:%d\n", obj->sysv_shm.id, obj->sysv_shm.size, - obj->sysv_shm.flags, obj->sysv_shm.ptr); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_SHM, global, obj); - objmsg.ptr = obj->sysv_shm.ptr; - objmsg.id = obj->sysv_shm.id; - objmsg.size = obj->sysv_shm.size; - objmsg.flags = obj->sysv_shm.flags; - sendudp((char *) &objmsg, sizeof(objmsg)); + obj->sysv_shm.flags, obj->sysv_shm.ptr, global); } void create_sysv_shms(void) diff --git a/tables-biarch.c b/tables-biarch.c index 983c5175d..1f7a0ffbf 100644 --- a/tables-biarch.c +++ b/tables-biarch.c @@ -14,7 +14,6 @@ #include "random.h" #include "shm.h" #include "tables.h" -#include "udp.h" #define NOTFOUND (unsigned int)-1 @@ -394,56 +393,3 @@ void display_enabled_syscalls_biarch(void) output(0, "32-bit syscall %d:%s enabled.\n", i, entry->name); } } - -void log_enabled_syscalls_biarch(void) -{ - struct syscallentry *entry; - struct msg_syscallsenabled *udpmsg; - int *entries; - unsigned int i; - unsigned int index = 0; - unsigned int size = sizeof(struct msg_syscallsenabled); - - /* First the 64bit syscalls */ - size += shm->nr_active_64bit_syscalls * sizeof(unsigned int); - udpmsg = zmalloc(size); - init_msghdr(&udpmsg->hdr, SYSCALLS_ENABLED); - udpmsg->nr_enabled = shm->nr_active_64bit_syscalls; - udpmsg->arch_is_biarch = TRUE; - udpmsg->is_64 = TRUE; - entries = udpmsg->entries; - - for_each_64bit_syscall(i) { - entry = syscalls_64bit[i].entry; - if (entry == NULL) - continue; - - if (entry->flags & ACTIVE) - entries[index++] = i; - } - - sendudp((char *) udpmsg, size); - free(udpmsg); - - /* Now send the 32bit syscalls */ - index = 0; - size = sizeof(struct msg_syscallsenabled); - size += shm->nr_active_32bit_syscalls * sizeof(unsigned int); - udpmsg = zmalloc(size); - init_msghdr(&udpmsg->hdr, SYSCALLS_ENABLED); - udpmsg->nr_enabled = shm->nr_active_32bit_syscalls; - udpmsg->arch_is_biarch = TRUE; - udpmsg->is_64 = FALSE; - entries = udpmsg->entries; - - for_each_32bit_syscall(i) { - entry = syscalls_32bit[i].entry; - if (entry == NULL) - continue; - - if (entry->flags & ACTIVE) - entries[index++] = i; - } - sendudp((char *) udpmsg, size); - free(udpmsg); -} diff --git a/tables-uniarch.c b/tables-uniarch.c index c1fe37955..446175083 100644 --- a/tables-uniarch.c +++ b/tables-uniarch.c @@ -14,7 +14,6 @@ #include "random.h" #include "shm.h" #include "tables.h" -#include "udp.h" const struct syscalltable *syscalls; @@ -177,31 +176,3 @@ void display_enabled_syscalls_uniarch(void) output(0, "syscall %d:%s enabled.\n", i, entry->name); } } - -void log_enabled_syscalls_uniarch(void) -{ - struct msg_syscallsenabled *udpmsg; - int *entries; - unsigned int i, index = 0; - unsigned int size; - - size = sizeof(struct msg_syscallsenabled) + (sizeof(int) * shm->nr_active_syscalls); - udpmsg = zmalloc(size); - init_msghdr(&udpmsg->hdr, SYSCALLS_ENABLED); - udpmsg->nr_enabled = shm->nr_active_syscalls; - udpmsg->arch_is_biarch = FALSE; - udpmsg->is_64 = FALSE; - entries = udpmsg->entries; - - for_each_syscall(i) { - struct syscallentry *entry = syscalls[i].entry; - - if (entry == NULL) - continue; - - if (entry->flags & ACTIVE) - entries[index++] = i; - } - sendudp((char *) udpmsg, size); - free(udpmsg); -} diff --git a/tables.c b/tables.c index 8090146aa..ef3e8b089 100644 --- a/tables.c +++ b/tables.c @@ -564,14 +564,6 @@ void display_enabled_syscalls(void) display_enabled_syscalls_uniarch(); } -void log_enabled_syscalls(void) -{ - if (biarch == TRUE) - log_enabled_syscalls_biarch(); - else - log_enabled_syscalls_uniarch(); -} - static void enable_random_syscalls(void) { unsigned int i; @@ -654,7 +646,6 @@ int munge_tables(void) if (verbose == TRUE) display_enabled_syscalls(); - log_enabled_syscalls(); if (validate_syscall_tables() == FALSE) { outputstd("No syscalls were enabled!\n"); diff --git a/trinity.1 b/trinity.1 index 0d75ee961..319603a41 100644 --- a/trinity.1 +++ b/trinity.1 @@ -106,8 +106,6 @@ List all syscalls known on this architecture. \fI\-\-logging \-l\fP off=disable logging. specify a directory where logfiles will be placed. - a remote host to log to over UDP. Needs a trinity server listening on port 6665. - (Note: still in development, partially working) .TP \fI\-\-domain \-P\fP diff --git a/trinity.c b/trinity.c index c24c325d9..6ea4e3f85 100644 --- a/trinity.c +++ b/trinity.c @@ -25,7 +25,6 @@ #include "tables.h" #include "taint.h" #include "trinity.h" -#include "udp.h" #include "uid.h" #include "version.h" diff --git a/udp.c b/udp.c deleted file mode 100644 index 34cbf5020..000000000 --- a/udp.c +++ /dev/null @@ -1,205 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "child.h" -#include "handshake.h" -#include "trinity.h" -#include "udp.h" -#include "utils.h" - -#define MAXBUF 1024 - -int logging_enabled = FALSE; - -static int logsocket = -1; - -static struct sockaddr_in udpserver; - -void init_msghdr(struct trinity_msghdr *hdr, enum logmsgtypes type) -{ - hdr->type = type; - hdr->pid = getpid(); -} - -void init_msgchildhdr(struct trinity_msgchildhdr *hdr, enum logmsgtypes type, pid_t pid, int childno) -{ - clock_gettime(CLOCK_MONOTONIC, &hdr->tp); - - hdr->type = type; - hdr->pid = pid; - hdr->childno = childno; -} - -void init_msgobjhdr(struct trinity_msgobjhdr *hdr, enum logmsgtypes type, bool global, struct object *obj) -{ - hdr->type = type; - hdr->pid = getpid(); - hdr->global = global; - hdr->address = obj; -} - -void sendudp(char *buffer, size_t len) -{ - int ret; - - if (logging_enabled == FALSE) - return; - - ret = sendto(logsocket, buffer, len, 0, (struct sockaddr *) &udpserver, sizeof(udpserver)); - if (ret == -1) { - fprintf(stderr, "sendto: %s\n", strerror(errno)); - } -} - -static bool __handshake(void) -{ - struct hellostruct hello; - int ret; - socklen_t addrlen = sizeof(udpserver); - fd_set rfds; - struct timeval tv; - char buf[MAXBUF]; - - snprintf(hello.hello, HELLOLEN, "Trinity"); - hello.version = TRINITY_UDP_VERSION; - hello.mainpid = getpid(); - hello.num_children = max_children; - - printf("Sending hello to logging server.\n"); - sendudp((char *) &hello, sizeof(struct hellostruct)); - - printf("Waiting for reply from logging server.\n"); - - FD_ZERO(&rfds); - - /* Wait up to five seconds. */ - tv.tv_sec = 5; - tv.tv_usec = 0; - FD_SET(logsocket, &rfds); - - ret = select(logsocket + 1, &rfds, NULL, NULL, &tv); - if (ret == -1) - perror("select()"); - else if (ret) { - if (FD_ISSET(logsocket, &rfds) != TRUE) { - printf("Something happened, but not on logsocket\n"); - return FALSE; - } - ret = recvfrom(logsocket, buf, MAXBUF, 0, (struct sockaddr *) &udpserver, &addrlen); - if (ret == -1) { - printf("recvfrom: %s\n", strerror(errno)); - return FALSE; - } - - if (ret != (int) strlen(serverreply)) { - printf("Got wrong length expected reply: Should be %d but was %d : %s\n", (int) strlen(serverreply), ret, buf); - return FALSE; - } - if (strncmp(buf, serverreply, strlen(serverreply)) != 0) { - printf("Got unrecognized reply: (%d bytes) %s\n", ret, buf); - printf("Expected %d bytes: %s\n", (int) strlen(serverreply), serverreply); - return FALSE; - } - /* handshake complete. */ - return TRUE; - } - return FALSE; -} - -static bool handshake(void) -{ - int try; - - for (try = 1; try < 4; try++) { - int ret = __handshake(); - if (ret == TRUE) { - printf("Got reply from server. Logging enabled.\n"); - return TRUE; - } - printf("No reply within five seconds, resending hello. [%d/3].\n", try); - } - - printf("Logging server seems down. Logging disabled.\n"); - return FALSE; -} - -void init_udp_logging(char *optarg) -{ - struct hostent *he; - struct sockaddr_in udpclient; - struct in_addr **addr_list; - char *ip = NULL; - int ret; - unsigned int i; - int sendbuff; - - if (optarg == NULL) { - logging_enabled = FALSE; - return; - } - - if ((he = gethostbyname(optarg)) == NULL) { - printf("gethostbyname:%s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - - addr_list = (struct in_addr **)he->h_addr_list; - for (i = 0; addr_list[i] != NULL; i++) { - ip = inet_ntoa(*addr_list[i]); - - udpserver.sin_family = AF_INET; - udpserver.sin_addr.s_addr = inet_addr(ip); - udpserver.sin_port = htons(TRINITY_LOG_PORT); - } - - if (ip == NULL) - return; - - printf("Logging to %s\n", ip); - - logsocket = socket(AF_INET, SOCK_DGRAM, 0); - if (logsocket == -1) { - printf("Could not create a socket: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - - udpclient.sin_family = AF_INET; - udpclient.sin_addr.s_addr = INADDR_ANY; - udpclient.sin_port = 0; - - ret = bind(logsocket, (struct sockaddr *) &udpclient, sizeof(udpclient)); - if (ret != 0) { - printf("Could not bind to address: %s\n", strerror(errno)); - close(logsocket); - exit(EXIT_FAILURE); - } - - sendbuff = 1000000 * max_children; - ret = setsockopt(logsocket, SOL_SOCKET, SO_SNDBUF, &sendbuff, sizeof(sendbuff)); - printf("socket buffer size set to: %d. (res:%s)\n", sendbuff, strerror(errno)); - - /* We temporarily turn enabled on, as we need it for sendudp to work. - * If we don't get a valid handshake we turn it back off. - */ - logging_enabled = TRUE; - - if (handshake() == FALSE) { - logging_enabled = FALSE; - close(logsocket); - logsocket = -1; - } -} - -void shutdown_udp_logging(void) -{ - if (logging_enabled == FALSE) - return; - - close(logsocket); -} From 185fa77c09c9e750f5883841ae5145678359d464 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Fri, 27 Dec 2019 10:47:31 -0500 Subject: [PATCH 085/119] remove dead var --- fds/drm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fds/drm.c b/fds/drm.c index fe246a774..1e0a3a650 100644 --- a/fds/drm.c +++ b/fds/drm.c @@ -32,8 +32,6 @@ static void drmfd_destructor(struct object *obj) static void drmfd_dump(struct object *obj, bool global) { - struct msg_objcreateddrm objmsg; - output(2, "drmfd:%d\n", obj->drmfd); } From 44e185242e10920b6e03cfa52e0027fe009826f4 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Mon, 30 Dec 2019 15:55:17 -0800 Subject: [PATCH 086/119] Remove leftover udp.h include. Fix build error. CC fds/drm.o fds/drm.c:26:10: fatal error: udp.h: No such file or directory 26 | #include "udp.h" | ^~~~~~~ Fixes: c927ff98280b ("remove all the udp logging") Signed-off-by: Vinson Lee --- fds/drm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fds/drm.c b/fds/drm.c index 1e0a3a650..cac0ecc06 100644 --- a/fds/drm.c +++ b/fds/drm.c @@ -23,8 +23,6 @@ #include #include -#include "udp.h" - static void drmfd_destructor(struct object *obj) { close(obj->drmfd); From 1c734c75dfed9706c58e6213848dd7111ddb5b47 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 30 Dec 2019 19:04:36 -0500 Subject: [PATCH 087/119] remove more udp detritus --- include/handshake.h | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 include/handshake.h diff --git a/include/handshake.h b/include/handshake.h deleted file mode 100644 index e8fd7160e..000000000 --- a/include/handshake.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "udp.h" -#include "utils.h" - -#define HELLOLEN 8 - -struct hellostruct { - char hello[HELLOLEN]; - int version; - pid_t mainpid; - int num_children; -}; - -static char serverreply[] = "Trinity server v" __stringify(TRINITY_UDP_VERSION) ". Go ahead"; From e53e25cc8dd5bdb5f7d9b4247de9e9921eec81d8 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Thu, 30 Jan 2020 22:09:45 -0800 Subject: [PATCH 088/119] Fix build with GCC 10. CC trinity /usr/bin/ld: debug.o:include/logfile.h:8: multiple definition of `mainlogfile'; child.o:include/logfile.h:8: first defined here /usr/bin/ld: log-files.o:include/logfile.h:8: multiple definition of `mainlogfile'; child.o:include/logfile.h:8: first defined here /usr/bin/ld: log.o:include/logfile.h:8: multiple definition of `mainlogfile'; child.o:include/logfile.h:8: first defined here /usr/bin/ld: main.o:include/logfile.h:8: multiple definition of `mainlogfile'; child.o:include/logfile.h:8: first defined here /usr/bin/ld: output.o:include/logfile.h:8: multiple definition of `mainlogfile'; child.o:include/logfile.h:8: first defined here /usr/bin/ld: params.o:include/logfile.h:8: multiple definition of `mainlogfile'; child.o:include/logfile.h:8: first defined here /usr/bin/ld: shm.o:include/logfile.h:8: multiple definition of `mainlogfile'; child.o:include/logfile.h:8: first defined here /usr/bin/ld: trinity.o:include/logfile.h:8: multiple definition of `mainlogfile'; child.o:include/logfile.h:8: first defined here Fixes: 13856316c259 ("reinstate the log-to-file code for now.") Signed-off-by: Vinson Lee --- include/logfile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/logfile.h b/include/logfile.h index 90ea8b235..2305ac155 100644 --- a/include/logfile.h +++ b/include/logfile.h @@ -5,7 +5,7 @@ FILE *find_logfile_handle(void); void synclogs(void); -FILE *mainlogfile; +extern FILE *mainlogfile; void open_main_logfile(void); void close_logfile(FILE **handle); From 4d2343bd18c7b4db4c59e7a03aac702218305dd0 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Fri, 28 Feb 2020 14:06:19 -0500 Subject: [PATCH 089/119] new io_uring_register opcodes --- syscalls/io_uring_register.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/syscalls/io_uring_register.c b/syscalls/io_uring_register.c index 8eb8468e8..debc5a4bb 100644 --- a/syscalls/io_uring_register.c +++ b/syscalls/io_uring_register.c @@ -9,6 +9,12 @@ #define IORING_UNREGISTER_FILES 3 #define IORING_REGISTER_EVENTFD 4 #define IORING_UNREGISTER_EVENTFD 5 +#define IORING_REGISTER_FILES_UPDATE 6 +#define IORING_REGISTER_EVENTFD_ASYNC 7 +#define IORING_REGISTER_PROBE 8 +#define IORING_REGISTER_PERSONALITY 9 +#define IORING_UNREGISTER_PERSONALITY 10 + static unsigned long io_uring_register_opcodes[] = { IORING_REGISTER_BUFFERS, @@ -17,6 +23,11 @@ static unsigned long io_uring_register_opcodes[] = { IORING_UNREGISTER_FILES, IORING_REGISTER_EVENTFD, IORING_UNREGISTER_EVENTFD, + IORING_REGISTER_FILES_UPDATE, + IORING_REGISTER_EVENTFD_ASYNC, + IORING_REGISTER_PROBE, + IORING_REGISTER_PERSONALITY, + IORING_UNREGISTER_PERSONALITY, }; struct syscallentry syscall_io_uring_register = { From c2d91745cdb929199b608d387cea34e5fc37216c Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 29 Mar 2021 17:18:06 -0400 Subject: [PATCH 090/119] Yet more new io_uring flags --- syscalls/io_uring_register.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/syscalls/io_uring_register.c b/syscalls/io_uring_register.c index debc5a4bb..0d739a99f 100644 --- a/syscalls/io_uring_register.c +++ b/syscalls/io_uring_register.c @@ -14,6 +14,8 @@ #define IORING_REGISTER_PROBE 8 #define IORING_REGISTER_PERSONALITY 9 #define IORING_UNREGISTER_PERSONALITY 10 +#define IORING_REGISTER_RESTRICTIONS 11 +#define IORING_REGISTER_ENABLE_RINGS 12 static unsigned long io_uring_register_opcodes[] = { @@ -28,6 +30,8 @@ static unsigned long io_uring_register_opcodes[] = { IORING_REGISTER_PROBE, IORING_REGISTER_PERSONALITY, IORING_UNREGISTER_PERSONALITY, + IORING_REGISTER_RESTRICTIONS, + IORING_REGISTER_ENABLE_RINGS, }; struct syscallentry syscall_io_uring_register = { From 8fc6695728193d667a638e782a354dacf02dbc28 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 29 Mar 2021 17:52:46 -0400 Subject: [PATCH 091/119] syscall update for 5.12-rc5 --- include/syscalls-x86_64.h | 7 +++++++ scripts/hashcheck.sh | 2 +- syscalls/close_range.c | 36 ++++++++++++++++++++++++++++++++ syscalls/epoll_pwait.c | 30 +++++++++++++++++++++++---- syscalls/faccessat.c | 43 +++++++++++++++++++++++++++++++++++++++ syscalls/madvise.c | 28 +++++++++++++++++++++++++ syscalls/mount.c | 30 +++++++++++++++++++++++++++ syscalls/open.c | 17 ++++++++++++++++ syscalls/pidfd_getfd.c | 21 +++++++++++++++++++ syscalls/syscalls.h | 7 +++++++ 10 files changed, 216 insertions(+), 5 deletions(-) create mode 100644 syscalls/close_range.c create mode 100644 syscalls/pidfd_getfd.c diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index a60f4d303..658008365 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -447,4 +447,11 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_fspick }, { .entry = &syscall_pidfd_open }, { .entry = &syscall_clone3 }, + { .entry = &syscall_close_range }, + { .entry = &syscall_openat2 }, + { .entry = &syscall_pidfd_getfd }, + { .entry = &syscall_faccessat2 }, + { .entry = &syscall_process_madvise }, + { .entry = &syscall_epoll_pwait2 }, + { .entry = &syscall_mount_setattr }, }; diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh index a113793d0..3fb0c1cc0 100755 --- a/scripts/hashcheck.sh +++ b/scripts/hashcheck.sh @@ -25,7 +25,7 @@ check() # Note: Commented out checks are likely out of date, but they're for architectures # I don't have time to care about. Step up and contribute if you care. # -check include/uapi/asm-generic/unistd.h 198599d8f761b4dd63db413600419fdad3ddfcbd sys_ +check include/uapi/asm-generic/unistd.h 11c46e9ce6393e7c8a17577c6128b78684395016 sys_ #check arch/alpha/include/uapi/asm/unistd.h 51fa669a21d8f26a0c9de8280a3cfd9c257a0d28 _NR_ #check arch/arm/include/uapi/asm/unistd.h 7c601d436a3ebbe05a9b6813c0ffcf8eedaf101b SYSCALL check arch/x86/entry/syscalls/syscall_32.tbl be7686afac49943e1a89447b1d09f4a6e868f482 sys_ diff --git a/syscalls/close_range.c b/syscalls/close_range.c new file mode 100644 index 000000000..5c5155562 --- /dev/null +++ b/syscalls/close_range.c @@ -0,0 +1,36 @@ +/** + * close_range() - Close all file descriptors in a given range. + * + * @fd: starting file descriptor to close + * @max_fd: last file descriptor to close + * @flags: reserved for future extensions + * + * This closes a range of file descriptors. All file descriptors + * from @fd up to and including @max_fd are closed. + * Currently, errors to close a given file descriptor are ignored. + */ +#include "sanitise.h" +#include "syscall.h" + +#define CLOSE_RANGE_UNSHARE (1U << 1) +#define CLOSE_RANGE_CLOEXEC (1U << 2) + + +static unsigned long close_range_flags[] = { + CLOSE_RANGE_UNSHARE, CLOSE_RANGE_CLOEXEC, +}; + +struct syscallentry syscall_close_range = { + .name = "close_range", + .num_args = 3, + .arg1name = "fd", + .arg1type = ARG_FD, + .arg2name = "max_fd", + .arg2type = ARG_FD, + .arg3name = "flags", + .arg3type = ARG_LIST, + .arg3list = ARGLIST(close_range_flags), + + .flags = AVOID_SYSCALL, + .rettype = RET_ZERO_SUCCESS, +}; diff --git a/syscalls/epoll_pwait.c b/syscalls/epoll_pwait.c index e59a1b0e1..4402eca8d 100644 --- a/syscalls/epoll_pwait.c +++ b/syscalls/epoll_pwait.c @@ -1,7 +1,12 @@ /* - * SYSCALL_DEFINE4(epoll_wait, int, epfd, struct epoll_event __user *, events, - int, maxevents, int, timeout) - * +SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events, + int, maxevents, int, timeout, const sigset_t __user *, sigmask, + size_t, sigsetsize) + +SYSCALL_DEFINE6(epoll_pwait2, int, epfd, struct epoll_event __user *, events, + int, maxevents, const struct __kernel_timespec __user *, timeout, + const sigset_t __user *, sigmask, size_t, sigsetsize) + * When successful, returns the number of file descriptors ready for the requested I/O, * or zero if no file descriptor became ready during the requested timeout milliseconds. * When an error occurs, returns -1 and errno is set appropriately. @@ -10,13 +15,30 @@ struct syscallentry syscall_epoll_pwait = { .name = "epoll_pwait", - .num_args = 4, + .num_args = 6, + .arg1name = "epfd", + .arg1type = ARG_FD, + .arg2name = "events", + .arg2type = ARG_ADDRESS, + .arg3name = "maxevents", + .arg4name = "timeout", + .arg5name = "sigmask", + .arg6name = "sigsetsize", + .rettype = RET_BORING, + .flags = NEED_ALARM, +}; + +struct syscallentry syscall_epoll_pwait2 = { + .name = "epoll_pwait2", + .num_args = 6, .arg1name = "epfd", .arg1type = ARG_FD, .arg2name = "events", .arg2type = ARG_ADDRESS, .arg3name = "maxevents", .arg4name = "timeout", + .arg5name = "sigmask", + .arg6name = "sigsetsize", .rettype = RET_BORING, .flags = NEED_ALARM, }; diff --git a/syscalls/faccessat.c b/syscalls/faccessat.c index 83aefbc75..a26824701 100644 --- a/syscalls/faccessat.c +++ b/syscalls/faccessat.c @@ -19,3 +19,46 @@ struct syscallentry syscall_faccessat = { .flags = NEED_ALARM, .group = GROUP_VFS, }; + +#define AT_FDCWD -100 /* Special value used to indicate + openat should use the current + working directory. */ +#define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */ +#define AT_EACCESS 0x200 /* Test access permitted for + effective IDs, not real IDs. */ +#define AT_REMOVEDIR 0x200 /* Remove directory instead of + unlinking file. */ +#define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */ +#define AT_NO_AUTOMOUNT 0x800 /* Suppress terminal automount traversal */ +#define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname */ + +#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */ +#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */ +#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */ +#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */ + +#define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */ + + +static unsigned long faccessat2_flags[] = { + AT_FDCWD, AT_SYMLINK_NOFOLLOW, AT_EACCESS, AT_REMOVEDIR, + AT_SYMLINK_FOLLOW, AT_NO_AUTOMOUNT, AT_EMPTY_PATH, AT_STATX_SYNC_TYPE, + AT_STATX_SYNC_AS_STAT, AT_STATX_FORCE_SYNC, AT_STATX_DONT_SYNC, AT_RECURSIVE, +}; + +struct syscallentry syscall_faccessat2 = { + .name = "faccessat2", + .num_args = 4, + .arg1name = "dfd", + .arg1type = ARG_FD, + .arg2name = "filename", + .arg2type = ARG_PATHNAME, + .arg3name = "mode", + .arg3type = ARG_MODE_T, + .arg4name = "flags", + .arg4type = ARG_LIST, + .arg4list = ARGLIST(faccessat2_flags), + .rettype = RET_ZERO_SUCCESS, + .flags = NEED_ALARM, + .group = GROUP_VFS, +}; diff --git a/syscalls/madvise.c b/syscalls/madvise.c index b3c77b3e7..e7e08e129 100644 --- a/syscalls/madvise.c +++ b/syscalls/madvise.c @@ -36,3 +36,31 @@ struct syscallentry syscall_madvise = { .group = GROUP_VM, .sanitise = sanitise_madvise, }; + +#define MADV_COLD 20 /* deactivate these pages */ +#define MADV_PAGEOUT 21 /* reclaim these pages */ + +static unsigned long process_madvise_behaviours[] = { + MADV_COLD, MADV_PAGEOUT, +}; +static unsigned long process_madvise_flags[] = { + 0, +}; + +struct syscallentry syscall_process_madvise = { + .name = "process_madvise", + .num_args = 5, + .arg1name = "pidfd", + .arg1type = ARG_FD, + .arg2name = "vec", + .arg3name = "vlen", + .arg3type = ARG_LEN, + .arg4name = "behaviour", + .arg4type = ARG_LIST, + .arg4list = ARGLIST(process_madvise_behaviours), + .arg5name = "flags", + .arg5type = ARG_OP, + .arg5list = ARGLIST(process_madvise_flags), + .group = GROUP_VM, + .sanitise = sanitise_madvise, +}; diff --git a/syscalls/mount.c b/syscalls/mount.c index e3a04318e..97890d74b 100644 --- a/syscalls/mount.c +++ b/syscalls/mount.c @@ -36,3 +36,33 @@ struct syscallentry syscall_mount = { .arg5type = ARG_ADDRESS, .group = GROUP_VFS, }; + +#define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname */ + +#define AT_STATX_SYNC_TYPE 0x6000 /* Type of synchronisation required from statx() */ +#define AT_STATX_SYNC_AS_STAT 0x0000 /* - Do whatever stat() does */ +#define AT_STATX_FORCE_SYNC 0x2000 /* - Force the attributes to be sync'd with the server */ +#define AT_STATX_DONT_SYNC 0x4000 /* - Don't sync attributes with the server */ + +#define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */ + +static unsigned long mount_setattr_flags[] = { + AT_EMPTY_PATH, AT_STATX_SYNC_TYPE, AT_STATX_SYNC_AS_STAT, AT_STATX_FORCE_SYNC, AT_STATX_DONT_SYNC, AT_RECURSIVE, +}; + +struct syscallentry syscall_mount_setattr = { + .name = "mount_setattr", + .num_args = 5, + .arg1name = "dfd", + .arg1type = ARG_FD, + .arg2name = "path", + .arg2type = ARG_PATHNAME, + .arg3name = "flags", + .arg3type = ARG_LIST, + .arg3list = ARGLIST(mount_setattr_flags), + .arg4name = "uattr", + .arg4type = ARG_ADDRESS, + .arg5name = "usize", + .arg5type = ARG_LEN, + .group = GROUP_VFS, +}; diff --git a/syscalls/open.c b/syscalls/open.c index db32170a1..37fd1a42b 100644 --- a/syscalls/open.c +++ b/syscalls/open.c @@ -100,6 +100,23 @@ struct syscallentry syscall_openat = { .sanitise = sanitise_openat, }; +/* + * SYSCALL_DEFINE4(openat2, int, dfd, const char __user *, filename, + struct open_how __user *, how, size_t, usize) + */ +struct syscallentry syscall_openat2 = { + .name = "openat2", + .num_args = 4, + .arg1name = "dfd", + .arg1type = ARG_FD, + .arg2name = "filename", + .arg2type = ARG_PATHNAME, + .arg3name = "how", + .arg4name = "usize", + .arg4type = ARG_LEN, + .flags = NEED_ALARM, +}; + /* * SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd, * struct file_handle __user *, handle, diff --git a/syscalls/pidfd_getfd.c b/syscalls/pidfd_getfd.c new file mode 100644 index 000000000..6e6eaa5b1 --- /dev/null +++ b/syscalls/pidfd_getfd.c @@ -0,0 +1,21 @@ +/* + * SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags) + */ +#include "sanitise.h" + +static unsigned long pidfd_getfd_flags[] = { + 0, +}; + +struct syscallentry syscall_pidfd_getfd = { + .name = "pidfd_getfd", + .num_args = 3, + .arg1name = "pidfd", + .arg1type = ARG_PID, + .arg2name = "fd", + .arg2type = ARG_PID, + .arg3name = "flags", + .arg3type = ARG_LIST, + .arg3list = ARGLIST(pidfd_getfd_flags), + .rettype = RET_PID_T, +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 46884ec8c..f0f75a74b 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -400,6 +400,13 @@ extern struct syscallentry syscall_fsmount; extern struct syscallentry syscall_fspick; extern struct syscallentry syscall_pidfd_open; extern struct syscallentry syscall_clone3; +extern struct syscallentry syscall_close_range; +extern struct syscallentry syscall_openat2; +extern struct syscallentry syscall_pidfd_getfd; +extern struct syscallentry syscall_faccessat2; +extern struct syscallentry syscall_process_madvise; +extern struct syscallentry syscall_epoll_pwait2; +extern struct syscallentry syscall_mount_setattr; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; From ba354ebe2b88df28fd7476d6476612cdfa1bdc4d Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Tue, 30 Mar 2021 13:48:59 -0400 Subject: [PATCH 092/119] Update socketopts to 5.12rc5 --- include/compat.h | 17 ++++++++++++----- scripts/hashcheck.sh | 4 ++-- syscalls/setsockopt.c | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/compat.h b/include/compat.h index 5267998a7..2d043b8a4 100644 --- a/include/compat.h +++ b/include/compat.h @@ -586,6 +586,13 @@ enum kcmp_type { #define SO_DETACH_REUSEPORT_BPF 68 #endif +#ifndef SO_PREFER_BUSY_POLL +#define SO_PREFER_BUSY_POLL 69 +#endif + +#ifndef SO_BUSY_POLL_BUDGET +#define SO_BUSY_POLL_BUDGET 70 +#endif /* linux/tcp.h */ @@ -804,6 +811,11 @@ enum kcmp_type { #define IPV6_RECVFRAGSIZE 77 #endif +/* netfilter/ipset/ipset.h */ +#ifndef SO_IP_SET +#define SO_IP_SET 83 +#endif + #ifndef IPV6_HDRINCL #define IPV6_HDRINCL 36 #endif @@ -1278,11 +1290,6 @@ struct kvm_get_htab_fd { # define SHM_NORESERVE 010000 #endif -/* netfilter/ipset/ipset.h */ -#ifndef SO_IP_SET -#define SO_IP_SET 83 -#endif - /* linux/auto_fs4.h */ #ifndef AUTOFS_IOC_EXPIRE_INDIRECT #define AUTOFS_IOC_EXPIRE_INDIRECT AUTOFS_IOC_EXPIRE_MULTI diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh index 3fb0c1cc0..b294594f5 100755 --- a/scripts/hashcheck.sh +++ b/scripts/hashcheck.sh @@ -29,7 +29,7 @@ check include/uapi/asm-generic/unistd.h 11c46e9ce6393e7c8a17577c6128b78684395 #check arch/alpha/include/uapi/asm/unistd.h 51fa669a21d8f26a0c9de8280a3cfd9c257a0d28 _NR_ #check arch/arm/include/uapi/asm/unistd.h 7c601d436a3ebbe05a9b6813c0ffcf8eedaf101b SYSCALL check arch/x86/entry/syscalls/syscall_32.tbl be7686afac49943e1a89447b1d09f4a6e868f482 sys_ -check arch/x86/entry/syscalls/syscall_64.tbl 83b2c58072648e92afca0504d5a60b456ddfe2ce sys_ +check arch/x86/entry/syscalls/syscall_64.tbl 8c8f94228fc4f325cf635fce25adf411f3714d1e sys_ check arch/x86/entry/syscalls/syscall_64.tbl da39a3ee5e6b4b0d3255bfef95601890afd80709 stub_ #check arch/ia64/kernel/entry.S e6a21b973609ec08cd19b0b8c67830f8570e93ef "data8\ sys_" #check arch/mips/kernel/scall32-o32.S b1501a675dd998fe2af68ae43cd797cf18d67b33 sys_ @@ -40,7 +40,7 @@ check arch/x86/entry/syscalls/syscall_64.tbl da39a3ee5e6b4b0d3255bfef9560189 #check arch/sparc/kernel/systbls_32.S 98100f9dedc82d82ac18a33fd68dc7e4852ffcb8 sys_ # new setsockopt values -check include/uapi/asm-generic/socket.h 08003e14cf68ce62a2caeb8921db3e081a612f09 SO_ +check include/uapi/asm-generic/socket.h e32fa013c2d914164d2a70ecabb3f23563b59de8 SO_ check include/uapi/linux/tcp.h 149a6ee4bb5bb81fd8d44923c5846f85b7130d5e \#define\ TCP_ check include/uapi/linux/in.h 0116e6878df350e74ec730fd9f455efb95e510c8 \#define\ IP_ diff --git a/syscalls/setsockopt.c b/syscalls/setsockopt.c index 91905c9b6..9ac6c39fd 100644 --- a/syscalls/setsockopt.c +++ b/syscalls/setsockopt.c @@ -28,7 +28,7 @@ static const unsigned int socket_opts[] = { SO_COOKIE, SCM_TIMESTAMPING_PKTINFO, SO_PEERGROUPS, SO_ZEROCOPY, SO_TXTIME, SO_BINDTOIFINDEX, SO_TIMESTAMP_NEW, SO_TIMESTAMPNS_NEW, SO_TIMESTAMPING_NEW, SO_RCVTIMEO_NEW, SO_SNDTIMEO_NEW, - SO_DETACH_REUSEPORT_BPF, + SO_DETACH_REUSEPORT_BPF, SO_PREFER_BUSY_POLL, SO_BUSY_POLL_BUDGET, }; static void socket_setsockopt(struct sockopt *so, __unused__ struct socket_triplet *triplet) From d295fa4034e1ba1880e143c1356d80f0332885e1 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Tue, 30 Mar 2021 13:51:54 -0400 Subject: [PATCH 093/119] Update madvise flags --- include/compat.h | 6 ++++++ scripts/hashcheck.sh | 2 +- syscalls/madvise.c | 5 +---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/compat.h b/include/compat.h index 2d043b8a4..41bd10708 100644 --- a/include/compat.h +++ b/include/compat.h @@ -144,6 +144,12 @@ enum { #ifndef MADV_KEEPONFORK #define MADV_KEEPONFORK 19 #endif +#ifndef MADV_COLD +#define MADV_COLD 20 /* deactivate these pages */ +#endif +#ifndef MADV_PAGEOUT +#define MADV_PAGEOUT 21 /* reclaim these pages */ +#endif /* bits/socket.h */ diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh index b294594f5..ebf9970b6 100755 --- a/scripts/hashcheck.sh +++ b/scripts/hashcheck.sh @@ -64,7 +64,7 @@ check include/uapi/asm-generic/fcntl.h 98cf236ce61466e272727683eba11493d41c6b27 check include/linux/splice.h fb753f99bf38f7c041427c442f199aa2049fa329 SPLICE_F_ # new madvise flags -check include/uapi/asm-generic/mman-common.h c6e990af02fd65c13c5e25c2d4e7dffa32724b23 MADV_ +check include/uapi/asm-generic/mman-common.h fdfd95258ab07c7377584912890dd286beae4f9f MADV_ # new mremap flags check include/uapi/linux/mman.h 556bcea4a4581a03a600c2d383c462840f1c0e6c MREMAP_ diff --git a/syscalls/madvise.c b/syscalls/madvise.c index e7e08e129..9cb12f134 100644 --- a/syscalls/madvise.c +++ b/syscalls/madvise.c @@ -21,7 +21,7 @@ static unsigned long madvise_advices[] = { MADV_FREE, MADV_REMOVE, MADV_DONTFORK, MADV_DOFORK, MADV_MERGEABLE, MADV_UNMERGEABLE, MADV_HUGEPAGE, MADV_NOHUGEPAGE, MADV_DONTDUMP, MADV_DODUMP, - MADV_WIPEONFORK, MADV_KEEPONFORK, + MADV_WIPEONFORK, MADV_KEEPONFORK, MADV_COLD, MADV_PAGEOUT, }; struct syscallentry syscall_madvise = { @@ -37,9 +37,6 @@ struct syscallentry syscall_madvise = { .sanitise = sanitise_madvise, }; -#define MADV_COLD 20 /* deactivate these pages */ -#define MADV_PAGEOUT 21 /* reclaim these pages */ - static unsigned long process_madvise_behaviours[] = { MADV_COLD, MADV_PAGEOUT, }; From 03f10b67513763350c6d8d3fd593e2322e59d12b Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Tue, 30 Mar 2021 13:54:01 -0400 Subject: [PATCH 094/119] Update mremap flags for 5.12-rc5 --- include/compat.h | 4 ++++ scripts/hashcheck.sh | 2 +- syscalls/mremap.c | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/compat.h b/include/compat.h index 41bd10708..f6cc57c61 100644 --- a/include/compat.h +++ b/include/compat.h @@ -1277,6 +1277,10 @@ struct kvm_get_htab_fd { #define MLOCK_ONFAULT 0x01 #endif +#ifndef MREMAP_DONTUNMAP +#define MREMAP_DONTUNMAP 4 +#endif + /* linux/nvme_ioctl.h */ #ifndef NVME_IOCTL_RESET #define NVME_IOCTL_RESET _IO('N', 0x44) diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh index ebf9970b6..1578cc678 100755 --- a/scripts/hashcheck.sh +++ b/scripts/hashcheck.sh @@ -67,7 +67,7 @@ check include/linux/splice.h fb753f99bf38f7c041427c442f199aa2049fa329 SPLICE_F_ check include/uapi/asm-generic/mman-common.h fdfd95258ab07c7377584912890dd286beae4f9f MADV_ # new mremap flags -check include/uapi/linux/mman.h 556bcea4a4581a03a600c2d383c462840f1c0e6c MREMAP_ +check include/uapi/linux/mman.h 3465560bc9439e3edabb652ce31d6a0d0e1aa400 MREMAP_ # new IPPROTO's check include/uapi/linux/in.h 80799106aba80b40af5416f0d5cc47dea8b02225 \ \ IPPROTO_ diff --git a/syscalls/mremap.c b/syscalls/mremap.c index 2a44938c2..20d54b0f0 100644 --- a/syscalls/mremap.c +++ b/syscalls/mremap.c @@ -14,6 +14,7 @@ #include "syscall.h" #include "trinity.h" #include "utils.h" +#include "compat.h" static struct map *map; @@ -63,7 +64,7 @@ static void post_mremap(struct syscallrecord *rec) } static unsigned long mremap_flags[] = { - MREMAP_MAYMOVE, MREMAP_FIXED, + MREMAP_MAYMOVE, MREMAP_FIXED, MREMAP_DONTUNMAP, }; struct syscallentry syscall_mremap = { From da65f0aa2bfcb4a2d9a77abfaa2955c6be3d37c9 Mon Sep 17 00:00:00 2001 From: Fabrice Fontaine Date: Sat, 17 Jul 2021 08:02:31 +0200 Subject: [PATCH 095/119] net/proto-ip-raw.c: fix build with kernel >= 5.13 Fix the following build failure with kernel >= 5.13: In file included from /home/buildroot/autobuild/instance-2/output-1/host/powerpc-buildroot-linux-uclibc/sysroot/usr/include/linux/icmp.h:23, from net/proto-ip-raw.c:1: /home/buildroot/autobuild/instance-2/output-1/host/powerpc-buildroot-linux-uclibc/sysroot/usr/include/netinet/in.h:33:5: error: redeclaration of enumerator 'IPPROTO_IP' 33 | IPPROTO_IP = 0, /* Dummy protocol for TCP. */ | ^~~~~~~~~~ /home/buildroot/autobuild/instance-2/output-1/host/powerpc-buildroot-linux-uclibc/sysroot/usr/include/linux/in.h:29:3: note: previous definition of 'IPPROTO_IP' was here 29 | IPPROTO_IP = 0, /* Dummy protocol for TCP */ | ^~~~~~~~~~ Fixes: - http://autobuild.buildroot.org/results/c58119baed8d7711da799e34a5ee1117f46b96f4 Signed-off-by: Fabrice Fontaine --- net/proto-ip-raw.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/proto-ip-raw.c b/net/proto-ip-raw.c index 95f2cb13a..b407bb680 100644 --- a/net/proto-ip-raw.c +++ b/net/proto-ip-raw.c @@ -1,3 +1,4 @@ +#include #include #include "net.h" #include "trinity.h" From b1a0aef9978d4a41e7e601c277d4fb1b0cfbed89 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Thu, 26 Aug 2021 11:17:34 -0400 Subject: [PATCH 096/119] Use fcntl.h for dev_t & mode_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Should fix: In file included from /usr/include/bits/statx.h:31, from /usr/include/sys/stat.h:446, from include/files.h:3, from include/shm.h:6, from syscalls/x86/modify_ldt.c:12: /usr/include/linux/stat.h:57:2: error: unknown type name ‘__s64’ __s64 tv_sec; ^~~~~ /usr/include/linux/stat.h:58:2: error: unknown type name ‘__u32’ __u32 tv_nsec; ^~~~~ /usr/include/linux/stat.h:59:2: error: unknown type name ‘__s32’ __s32 __reserved; ^~~~~ /usr/include/linux/stat.h:101:2: error: unknown type name ‘__u32’ __u32 stx_mask; /* What results were written [uncond] */ --- include/files.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/files.h b/include/files.h index 2a8e0e2d6..ba3cc98ff 100644 --- a/include/files.h +++ b/include/files.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "fd.h" unsigned long get_o_flags(void); From 9b8ff053dab1c14a1c0b2a4f5b8144855886dd62 Mon Sep 17 00:00:00 2001 From: Hongchen Zhang Date: Sun, 26 Sep 2021 16:43:52 +0800 Subject: [PATCH 097/119] protect other children's shm from corruption When one child is corrupt,we want to know who is corrupt. But when it corrupts other one's shm,we can not know who caused the corruption. So protect other children from corruption. Signed-off-by: Hongchen Zhang --- child.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/child.c b/child.c index c86c3ea56..22756d6d3 100644 --- a/child.c +++ b/child.c @@ -189,6 +189,14 @@ static void init_child(struct childdata *child, int childno) { pid_t pid = getpid(); char childname[17]; + unsigned int i; + + for_each_child(i) { + if (child->num != i) + mprotect(shm->children[i], sizeof(struct childdata), PROT_READ); + } + + mprotect(pids, max_children * sizeof(int), PROT_READ); /* Wait for parent to set our childno */ while (pids[childno] != pid) { From a3cab04024c529fc38735625c176ad362589307b Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 11 Oct 2021 15:25:36 -0400 Subject: [PATCH 098/119] Add skeletons for a bunch of new syscalls --- Makefile | 2 +- include/syscalls-x86_64.h | 6 ++++++ syscalls/landlock_add_rule.c | 33 ++++++++++++++++++++++++++++++ syscalls/landlock_create_ruleset.c | 23 +++++++++++++++++++++ syscalls/landlock_restrict_self.c | 19 +++++++++++++++++ syscalls/memfd_secret.c | 19 +++++++++++++++++ syscalls/process_mrelease.c | 17 +++++++++++++++ syscalls/quotactl_fd.c | 17 +++++++++++++++ syscalls/syscalls.h | 6 ++++++ 9 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 syscalls/landlock_add_rule.c create mode 100644 syscalls/landlock_create_ruleset.c create mode 100644 syscalls/landlock_restrict_self.c create mode 100644 syscalls/memfd_secret.c create mode 100644 syscalls/process_mrelease.c create mode 100644 syscalls/quotactl_fd.c diff --git a/Makefile b/Makefile index 77d7f8799..d409dc8e8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION="2019.06" +VERSION="2021.10" INSTALL_PREFIX ?= $(DESTDIR) INSTALL_PREFIX ?= $(HOME) diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index 658008365..8d0b1028e 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -454,4 +454,10 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_process_madvise }, { .entry = &syscall_epoll_pwait2 }, { .entry = &syscall_mount_setattr }, + { .entry = &syscall_quotactl_fd }, + { .entry = &syscall_landlock_create_ruleset }, + { .entry = &syscall_landlock_add_rule }, + { .entry = &syscall_landlock_restrict_self }, + { .entry = &syscall_memfd_secret }, + { .entry = &syscall_process_mrelease }, }; diff --git a/syscalls/landlock_add_rule.c b/syscalls/landlock_add_rule.c new file mode 100644 index 000000000..45dc1579e --- /dev/null +++ b/syscalls/landlock_add_rule.c @@ -0,0 +1,33 @@ +/* + * SYSCALL_DEFINE4(landlock_add_rule, + * const int, ruleset_fd, const enum landlock_rule_type, rule_type, + * const void __user *const, rule_attr, const __u32, flags) + */ +#include "sanitise.h" + +enum landlock_rule_type { + LANDLOCK_RULE_PATH_BENEATH = 1, +}; + +static unsigned long landlock_ruletypes[] = { + LANDLOCK_RULE_PATH_BENEATH, +}; + +// no flags for now +//static unsigned long landlock_add_rule_flags[] = { +// , +//}; + +struct syscallentry syscall_landlock_add_rule = { + .name = "landlock_add_rule", + .num_args = 4, + .arg1name = "ruleset_fd", + .arg1type = ARG_FD, + .arg2name = "rule_type", + .arg2type = ARG_LIST, + .arg2list = ARGLIST(landlock_ruletypes), + .arg3name = "rule_attr", + .arg4name = "flags", +// .arg4type = ARG_LIST, +// .arg4list = ARGLIST(landlock_add_rule_flags), +}; diff --git a/syscalls/landlock_create_ruleset.c b/syscalls/landlock_create_ruleset.c new file mode 100644 index 000000000..ba4c8ac95 --- /dev/null +++ b/syscalls/landlock_create_ruleset.c @@ -0,0 +1,23 @@ +/* + * SYSCALL_DEFINE3(landlock_create_ruleset, + * const struct landlock_ruleset_attr __user *const, attr, + * const size_t, size, const __u32, flags) + */ +#include "sanitise.h" + +#define LANDLOCK_CREATE_RULESET_VERSION (1U << 0) + +static unsigned long landlock_create_ruleset_flags[] = { + LANDLOCK_CREATE_RULESET_VERSION, +}; + +struct syscallentry syscall_landlock_create_ruleset = { + .name = "landlock_create_ruleset", + .num_args = 3, + .arg1name = "attr", + .arg2name = "size", + .arg2type = ARG_LEN, + .arg3name = "flags", + .arg3type = ARG_LIST, + .arg3list = ARGLIST(landlock_create_ruleset_flags), +}; diff --git a/syscalls/landlock_restrict_self.c b/syscalls/landlock_restrict_self.c new file mode 100644 index 000000000..c205df40b --- /dev/null +++ b/syscalls/landlock_restrict_self.c @@ -0,0 +1,19 @@ +/* + * SYSCALL_DEFINE2(landlock_restrict_self, + * const int, ruleset_fd, const __u32, flags) + */ +#include "sanitise.h" + +//static unsigned long landlock_restrict_self_flags[] = { +// , +//}; + +struct syscallentry syscall_landlock_restrict_self = { + .name = "landlock_restrict_self", + .num_args = 2, + .arg1name = "fd", + .arg1type = ARG_FD, + .arg2name = "flags", +// arg2type = ARG_LIST, +// arg2list = ARGLIST(landlock_restrict_self_flags), +}; diff --git a/syscalls/memfd_secret.c b/syscalls/memfd_secret.c new file mode 100644 index 000000000..a298f6208 --- /dev/null +++ b/syscalls/memfd_secret.c @@ -0,0 +1,19 @@ +/* + * SYSCALL_DEFINE1(memfd_secret, unsigned int, flags) + */ + +#include "sanitise.h" +#include "memfd.h" +#include "compat.h" + +static unsigned long memfd_secret_flags[] = { + 0, +}; + +struct syscallentry syscall_memfd_secret = { + .name = "memfd_secret", + .num_args = 1, + .arg1name = "flag", + .arg1type = ARG_LIST, + .arg1list = ARGLIST(memfd_secret_flags), +}; diff --git a/syscalls/process_mrelease.c b/syscalls/process_mrelease.c new file mode 100644 index 000000000..d2692edd9 --- /dev/null +++ b/syscalls/process_mrelease.c @@ -0,0 +1,17 @@ +/* + * SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags) + */ +#include "sanitise.h" + +static unsigned long process_mrelease_flags[] = { + 0, // currently no flags defined, mbz +}; + +struct syscallentry syscall_process_mrelease = { + .name = "process_mrelease", + .num_args = 2, + .arg1name = "pidfd", + .arg2name = "flags", + .arg2type = ARG_LIST, + .arg2list = ARGLIST(process_mrelease_flags), +}; diff --git a/syscalls/quotactl_fd.c b/syscalls/quotactl_fd.c new file mode 100644 index 000000000..90b04d295 --- /dev/null +++ b/syscalls/quotactl_fd.c @@ -0,0 +1,17 @@ +/* + * SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd, + qid_t, id, void __user *, addr) + */ +#include "sanitise.h" + +struct syscallentry syscall_quotactl_fd = { + .name = "quotactl_fd", + .num_args = 4, + .arg1name = "fd", + .arg1type = ARG_FD, + .arg2name = "cmd", + .arg3name = "id", + .arg4name = "addr", + .arg4type = ARG_ADDRESS, + .group = GROUP_VFS, +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index f0f75a74b..1cca794eb 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -407,6 +407,12 @@ extern struct syscallentry syscall_faccessat2; extern struct syscallentry syscall_process_madvise; extern struct syscallentry syscall_epoll_pwait2; extern struct syscallentry syscall_mount_setattr; +extern struct syscallentry syscall_quotactl_fd; +extern struct syscallentry syscall_landlock_create_ruleset; +extern struct syscallentry syscall_landlock_add_rule; +extern struct syscallentry syscall_landlock_restrict_self; +extern struct syscallentry syscall_memfd_secret; +extern struct syscallentry syscall_process_mrelease; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; From eadc80ef4e2c4035131d7f8a3771833abedf7f49 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 11 Oct 2021 15:30:27 -0400 Subject: [PATCH 099/119] new setsockopts --- include/compat.h | 7 +++++++ syscalls/setsockopt.c | 1 + 2 files changed, 8 insertions(+) diff --git a/include/compat.h b/include/compat.h index f6cc57c61..377e99d39 100644 --- a/include/compat.h +++ b/include/compat.h @@ -600,6 +600,13 @@ enum kcmp_type { #define SO_BUSY_POLL_BUDGET 70 #endif +#ifndef SO_NETNS_COOKIE +#define SO_NETNS_COOKIE 71 +#endif + +#ifndef SO_BUF_LOCK +#define SO_BUF_LOCK 72 +#endif /* linux/tcp.h */ #ifndef TCP_COOKIE_TRANSACTIONS diff --git a/syscalls/setsockopt.c b/syscalls/setsockopt.c index 9ac6c39fd..0d41fe95b 100644 --- a/syscalls/setsockopt.c +++ b/syscalls/setsockopt.c @@ -29,6 +29,7 @@ static const unsigned int socket_opts[] = { SO_TXTIME, SO_BINDTOIFINDEX, SO_TIMESTAMP_NEW, SO_TIMESTAMPNS_NEW, SO_TIMESTAMPING_NEW, SO_RCVTIMEO_NEW, SO_SNDTIMEO_NEW, SO_DETACH_REUSEPORT_BPF, SO_PREFER_BUSY_POLL, SO_BUSY_POLL_BUDGET, + SO_NETNS_COOKIE, SO_BUF_LOCK, }; static void socket_setsockopt(struct sockopt *so, __unused__ struct socket_triplet *triplet) From 75c06e1c8539a7fff1d04037e2f117b98493d726 Mon Sep 17 00:00:00 2001 From: Hongchen Zhang Date: Mon, 22 Nov 2021 11:36:16 +0800 Subject: [PATCH 100/119] do not let created timer send SIGINT signal When a child process tests timer_create interface with sigev->sigev_signo equal to SIGINT, and then timer_settime let the timer go.When the timer has expired, a SIGINT would send to our child process. But SIGINT signal means ctrl-c is pressed,and then trinity-main will exit. To Avoid it, do not let timer_create create a timer with sigev->sigev_signo equal to SIGINT. Change-Id: I3aa1b99ff447a4a0a8bc2a9d33cf91f7e48cd275 Signed-off-by: Hongchen Zhang --- syscalls/timer_create.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/syscalls/timer_create.c b/syscalls/timer_create.c index 1bd0ee7f6..974a4a4bc 100644 --- a/syscalls/timer_create.c +++ b/syscalls/timer_create.c @@ -3,7 +3,30 @@ struct sigevent __user *, timer_event_spec, timer_t __user *, created_timer_id) */ +#include + #include "sanitise.h" +#include "random.h" + +static void timer_create_sanitise(struct syscallrecord *rec) +{ + struct sigevent *sigev; + int signo; + + if (RAND_BOOL()) { + sigev = (struct sigevent *) get_writable_address(sizeof(struct sigevent)); + + /* do not let created timer send SIGINT signal */ + do { + signo = random() % _NSIG; + } while (signo == SIGINT); + + sigev->sigev_signo = signo; + } else + sigev = NULL; + + rec->a2 = (unsigned long)sigev; +} struct syscallentry syscall_timer_create = { .name = "timer_create", @@ -13,4 +36,5 @@ struct syscallentry syscall_timer_create = { .arg2type = ARG_ADDRESS, .arg3name = "create_timer_id", .arg3type = ARG_ADDRESS, + .sanitise = timer_create_sanitise, }; From 608712d8bf2dfee14de1bfd0e7c601dce2376808 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 29 Nov 2021 00:50:19 -0500 Subject: [PATCH 101/119] reduce variable scoping --- syscalls/timer_create.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/syscalls/timer_create.c b/syscalls/timer_create.c index 974a4a4bc..095cbedfb 100644 --- a/syscalls/timer_create.c +++ b/syscalls/timer_create.c @@ -11,9 +11,10 @@ static void timer_create_sanitise(struct syscallrecord *rec) { struct sigevent *sigev; - int signo; if (RAND_BOOL()) { + int signo; + sigev = (struct sigevent *) get_writable_address(sizeof(struct sigevent)); /* do not let created timer send SIGINT signal */ From 80fb6169505cf7a81d4621d7f586d5c2525266f4 Mon Sep 17 00:00:00 2001 From: Changbin Du Date: Sun, 9 Jan 2022 12:40:44 +0800 Subject: [PATCH 102/119] add support for riscv64 platform This only adds support for riscv64, riscv32 is not included. The riscv64 syscall table is very close to aarch64 with small difference. Signed-off-by: Changbin Du --- include/arch-riscv64.h | 16 ++ include/arch-syscalls.h | 7 + include/arch.h | 8 + include/syscalls-riscv64.h | 299 ++++++++++++++++++++++++++++++++++ syscalls/riscv_flush_icache.c | 25 +++ syscalls/syscalls.h | 2 + 6 files changed, 357 insertions(+) create mode 100644 include/arch-riscv64.h create mode 100644 include/syscalls-riscv64.h create mode 100644 syscalls/riscv_flush_icache.c diff --git a/include/arch-riscv64.h b/include/arch-riscv64.h new file mode 100644 index 000000000..b1a87805e --- /dev/null +++ b/include/arch-riscv64.h @@ -0,0 +1,16 @@ +#pragma once + +#define PAGE_OFFSET 0xffffffc000000000UL +#define TASK_SIZE (1UL << 39) +#define MODULE_ADDR (PAGE_OFFSET - 0x04000000) +#define KERNEL_ADDR (PAGE_OFFSET + 0x80000) + +#define PAGE_SHIFT 12 +#define PTE_FILE_MAX_BITS 60 + +#define PTRACE_GETREGS 0 +#define PTRACE_GETFPREGS 0 +#define PTRACE_SETREGS 0 +#define PTRACE_SETFPREGS 0 + +#define SYSCALLS syscalls_riscv64 diff --git a/include/arch-syscalls.h b/include/arch-syscalls.h index 3e24d8da4..64cfa1029 100644 --- a/include/arch-syscalls.h +++ b/include/arch-syscalls.h @@ -43,3 +43,10 @@ #ifdef __tile__ #include "syscalls-tile.h" #endif +#if defined(__riscv) || defined(__riscv__) +#if __riscv_xlen == 64 +#include "syscalls-riscv64.h" +#else +#error "riscv32 is not supported yet." +#endif +#endif diff --git a/include/arch.h b/include/arch.h index a641e5bbd..a4baaab03 100644 --- a/include/arch.h +++ b/include/arch.h @@ -54,6 +54,14 @@ #include "arch-tile.h" #endif +#if defined(__riscv) || defined(__riscv__) +#if __riscv_xlen == 64 +#include "arch-riscv64.h" +#else +#error "riscv32 is not supported yet." +#endif +#endif + #ifndef SYSCALL_OFFSET #define SYSCALL_OFFSET 0 #endif diff --git a/include/syscalls-riscv64.h b/include/syscalls-riscv64.h new file mode 100644 index 000000000..e4c53aad1 --- /dev/null +++ b/include/syscalls-riscv64.h @@ -0,0 +1,299 @@ +#pragma once + +/* + * Derived from arch/riscv/include/asm/unistd.h + * (inherits from include/uapi/asm-generic/unistd.h) + */ + +#include "sanitise.h" +#include "syscall.h" +#include "syscalls/syscalls.h" + +struct syscalltable syscalls_riscv64[] = { +/* 0 */ { .entry = &syscall_io_setup }, +/* 1 */ { .entry = &syscall_io_destroy }, +/* 2 */ { .entry = &syscall_io_submit }, +/* 3 */ { .entry = &syscall_io_cancel }, +/* 4 */ { .entry = &syscall_io_getevents }, +/* 5 */ { .entry = &syscall_setxattr }, +/* 6 */ { .entry = &syscall_lsetxattr }, +/* 7 */ { .entry = &syscall_fsetxattr }, +/* 8 */ { .entry = &syscall_getxattr }, +/* 9 */ { .entry = &syscall_lgetxattr }, +/* 10 */ { .entry = &syscall_fgetxattr }, +/* 11 */ { .entry = &syscall_listxattr }, +/* 12 */ { .entry = &syscall_llistxattr }, +/* 13 */ { .entry = &syscall_flistxattr }, +/* 14 */ { .entry = &syscall_removexattr }, +/* 15 */ { .entry = &syscall_lremovexattr }, +/* 16 */ { .entry = &syscall_fremovexattr }, +/* 17 */ { .entry = &syscall_getcwd }, +/* 18 */ { .entry = &syscall_lookup_dcookie }, +/* 19 */ { .entry = &syscall_eventfd2 }, +/* 20 */ { .entry = &syscall_epoll_create1 }, +/* 21 */ { .entry = &syscall_epoll_ctl }, +/* 22 */ { .entry = &syscall_epoll_pwait }, +/* 23 */ { .entry = &syscall_dup }, +/* 24 */ { .entry = &syscall_dup3 }, +/* 25 */ { .entry = &syscall_fcntl }, +/* 26 */ { .entry = &syscall_inotify_init1 }, +/* 27 */ { .entry = &syscall_inotify_add_watch }, +/* 28 */ { .entry = &syscall_inotify_rm_watch }, +/* 29 */ { .entry = &syscall_ioctl }, +/* 30 */ { .entry = &syscall_ioprio_set }, +/* 31 */ { .entry = &syscall_ioprio_get }, +/* 32 */ { .entry = &syscall_flock }, +/* 33 */ { .entry = &syscall_mknodat }, +/* 34 */ { .entry = &syscall_mkdirat }, +/* 35 */ { .entry = &syscall_unlinkat }, +/* 36 */ { .entry = &syscall_symlinkat }, +/* 37 */ { .entry = &syscall_linkat }, +/* 38 */ { .entry = &syscall_ni_syscall }, +/* 39 */ { .entry = &syscall_umount }, +/* 40 */ { .entry = &syscall_mount }, +/* 41 */ { .entry = &syscall_pivot_root }, +/* 42 */ { .entry = &syscall_ni_syscall }, +/* 43 */ { .entry = &syscall_statfs }, +/* 44 */ { .entry = &syscall_fstatfs }, +/* 45 */ { .entry = &syscall_truncate }, +/* 46 */ { .entry = &syscall_ftruncate }, +/* 47 */ { .entry = &syscall_fallocate }, +/* 48 */ { .entry = &syscall_faccessat }, +/* 49 */ { .entry = &syscall_chdir }, +/* 50 */ { .entry = &syscall_fchdir }, +/* 51 */ { .entry = &syscall_chroot }, +/* 52 */ { .entry = &syscall_fchmod }, +/* 53 */ { .entry = &syscall_fchmodat }, +/* 54 */ { .entry = &syscall_fchownat }, +/* 55 */ { .entry = &syscall_fchown }, +/* 56 */ { .entry = &syscall_openat }, +/* 57 */ { .entry = &syscall_close }, +/* 58 */ { .entry = &syscall_vhangup }, +/* 59 */ { .entry = &syscall_pipe2 }, +/* 60 */ { .entry = &syscall_quotactl }, +/* 61 */ { .entry = &syscall_getdents64 }, +/* 62 */ { .entry = &syscall_lseek }, +/* 63 */ { .entry = &syscall_read }, +/* 64 */ { .entry = &syscall_write }, +/* 65 */ { .entry = &syscall_readv }, +/* 66 */ { .entry = &syscall_writev }, +/* 67 */ { .entry = &syscall_pread64 }, +/* 68 */ { .entry = &syscall_pwrite64 }, +/* 69 */ { .entry = &syscall_preadv }, +/* 70 */ { .entry = &syscall_pwritev }, +/* 71 */ { .entry = &syscall_sendfile64 }, +/* 72 */ { .entry = &syscall_pselect6 }, +/* 73 */ { .entry = &syscall_ppoll }, +/* 74 */ { .entry = &syscall_signalfd4 }, +/* 75 */ { .entry = &syscall_vmsplice }, +/* 76 */ { .entry = &syscall_splice }, +/* 77 */ { .entry = &syscall_tee }, +/* 78 */ { .entry = &syscall_readlinkat }, +/* 79 */ { .entry = &syscall_newfstatat }, +/* 80 */ { .entry = &syscall_newfstat }, +/* 81 */ { .entry = &syscall_sync }, +/* 82 */ { .entry = &syscall_fsync }, +/* 83 */ { .entry = &syscall_fdatasync }, +/* 84 */ { .entry = &syscall_sync_file_range }, +/* 85 */ { .entry = &syscall_timerfd_create }, +/* 86 */ { .entry = &syscall_timerfd_settime }, +/* 87 */ { .entry = &syscall_timerfd_gettime }, +/* 88 */ { .entry = &syscall_utimensat }, +/* 89 */ { .entry = &syscall_acct }, +/* 90 */ { .entry = &syscall_capget }, +/* 91 */ { .entry = &syscall_capset }, +/* 92 */ { .entry = &syscall_personality }, +/* 93 */ { .entry = &syscall_exit }, +/* 94 */ { .entry = &syscall_exit_group }, +/* 95 */ { .entry = &syscall_waitid }, +/* 96 */ { .entry = &syscall_set_tid_address }, +/* 97 */ { .entry = &syscall_unshare }, +/* 98 */ { .entry = &syscall_futex }, +/* 99 */ { .entry = &syscall_set_robust_list }, +/* 100 */ { .entry = &syscall_get_robust_list }, +/* 101 */ { .entry = &syscall_nanosleep }, +/* 102 */ { .entry = &syscall_getitimer }, +/* 103 */ { .entry = &syscall_setitimer }, +/* 104 */ { .entry = &syscall_kexec_load }, +/* 105 */ { .entry = &syscall_init_module }, +/* 106 */ { .entry = &syscall_delete_module }, +/* 107 */ { .entry = &syscall_timer_create }, +/* 108 */ { .entry = &syscall_timer_gettime }, +/* 109 */ { .entry = &syscall_timer_getoverrun }, +/* 110 */ { .entry = &syscall_timer_settime }, +/* 111 */ { .entry = &syscall_timer_delete }, +/* 112 */ { .entry = &syscall_clock_settime }, +/* 113 */ { .entry = &syscall_clock_gettime }, +/* 114 */ { .entry = &syscall_clock_getres }, +/* 115 */ { .entry = &syscall_clock_nanosleep }, +/* 116 */ { .entry = &syscall_syslog }, +/* 117 */ { .entry = &syscall_ptrace }, +/* 118 */ { .entry = &syscall_sched_setparam }, +/* 119 */ { .entry = &syscall_sched_setscheduler }, +/* 120 */ { .entry = &syscall_sched_getscheduler }, +/* 121 */ { .entry = &syscall_sched_getparam }, +/* 122 */ { .entry = &syscall_sched_setaffinity }, +/* 123 */ { .entry = &syscall_sched_getaffinity }, +/* 124 */ { .entry = &syscall_sched_yield }, +/* 125 */ { .entry = &syscall_sched_get_priority_max }, +/* 126 */ { .entry = &syscall_sched_get_priority_min }, +/* 127 */ { .entry = &syscall_sched_rr_get_interval }, +/* 128 */ { .entry = &syscall_restart_syscall }, +/* 129 */ { .entry = &syscall_kill }, +/* 130 */ { .entry = &syscall_tkill }, +/* 131 */ { .entry = &syscall_tgkill }, +/* 132 */ { .entry = &syscall_sigaltstack }, +/* 133 */ { .entry = &syscall_rt_sigsuspend }, +/* 134 */ { .entry = &syscall_rt_sigaction }, +/* 135 */ { .entry = &syscall_rt_sigprocmask }, +/* 136 */ { .entry = &syscall_rt_sigpending }, +/* 137 */ { .entry = &syscall_rt_sigtimedwait }, +/* 138 */ { .entry = &syscall_rt_sigqueueinfo }, +/* 139 */ { .entry = &syscall_rt_sigreturn }, +/* 140 */ { .entry = &syscall_setpriority }, +/* 141 */ { .entry = &syscall_getpriority }, +/* 142 */ { .entry = &syscall_reboot }, +/* 143 */ { .entry = &syscall_setregid }, +/* 144 */ { .entry = &syscall_setgid }, +/* 145 */ { .entry = &syscall_setreuid }, +/* 146 */ { .entry = &syscall_setuid }, +/* 147 */ { .entry = &syscall_setresuid }, +/* 148 */ { .entry = &syscall_getresuid }, +/* 149 */ { .entry = &syscall_setresgid }, +/* 150 */ { .entry = &syscall_getresgid }, +/* 151 */ { .entry = &syscall_setfsuid }, +/* 152 */ { .entry = &syscall_setfsgid }, +/* 153 */ { .entry = &syscall_times }, +/* 154 */ { .entry = &syscall_setpgid }, +/* 155 */ { .entry = &syscall_getpgid }, +/* 156 */ { .entry = &syscall_getsid }, +/* 157 */ { .entry = &syscall_setsid }, +/* 158 */ { .entry = &syscall_getgroups }, +/* 159 */ { .entry = &syscall_setgroups }, +/* 160 */ { .entry = &syscall_newuname }, +/* 161 */ { .entry = &syscall_sethostname }, +/* 162 */ { .entry = &syscall_setdomainname }, +/* 163 */ { .entry = &syscall_getrlimit }, +/* 164 */ { .entry = &syscall_setrlimit }, +/* 165 */ { .entry = &syscall_getrusage }, +/* 166 */ { .entry = &syscall_umask }, +/* 167 */ { .entry = &syscall_prctl }, +/* 168 */ { .entry = &syscall_getcpu }, +/* 169 */ { .entry = &syscall_gettimeofday }, +/* 170 */ { .entry = &syscall_settimeofday }, +/* 171 */ { .entry = &syscall_adjtimex }, +/* 172 */ { .entry = &syscall_getpid }, +/* 173 */ { .entry = &syscall_getppid }, +/* 174 */ { .entry = &syscall_getuid }, +/* 175 */ { .entry = &syscall_geteuid }, +/* 176 */ { .entry = &syscall_getgid }, +/* 177 */ { .entry = &syscall_getegid }, +/* 178 */ { .entry = &syscall_gettid }, +/* 179 */ { .entry = &syscall_sysinfo }, +/* 180 */ { .entry = &syscall_mq_open }, +/* 181 */ { .entry = &syscall_mq_unlink }, +/* 182 */ { .entry = &syscall_mq_timedsend }, +/* 183 */ { .entry = &syscall_mq_timedreceive }, +/* 184 */ { .entry = &syscall_mq_notify }, +/* 185 */ { .entry = &syscall_mq_getsetattr }, +/* 186 */ { .entry = &syscall_msgget }, +/* 187 */ { .entry = &syscall_msgctl }, +/* 188 */ { .entry = &syscall_msgrcv }, +/* 189 */ { .entry = &syscall_msgsnd }, +/* 190 */ { .entry = &syscall_semget }, +/* 191 */ { .entry = &syscall_semctl }, +/* 192 */ { .entry = &syscall_semtimedop }, +/* 193 */ { .entry = &syscall_semop }, +/* 194 */ { .entry = &syscall_shmget }, +/* 195 */ { .entry = &syscall_shmctl }, +/* 196 */ { .entry = &syscall_shmat }, +/* 197 */ { .entry = &syscall_shmdt }, +/* 198 */ { .entry = &syscall_socket }, +/* 199 */ { .entry = &syscall_socketpair }, +/* 200 */ { .entry = &syscall_bind }, +/* 201 */ { .entry = &syscall_listen }, +/* 202 */ { .entry = &syscall_accept }, +/* 203 */ { .entry = &syscall_connect }, +/* 204 */ { .entry = &syscall_getsockname }, +/* 205 */ { .entry = &syscall_getpeername }, +/* 206 */ { .entry = &syscall_sendto }, +/* 207 */ { .entry = &syscall_recvfrom }, +/* 208 */ { .entry = &syscall_setsockopt }, +/* 209 */ { .entry = &syscall_getsockopt }, +/* 210 */ { .entry = &syscall_shutdown }, +/* 211 */ { .entry = &syscall_sendmsg }, +/* 212 */ { .entry = &syscall_recvmsg }, +/* 213 */ { .entry = &syscall_readahead }, +/* 214 */ { .entry = &syscall_brk }, +/* 215 */ { .entry = &syscall_munmap }, +/* 216 */ { .entry = &syscall_mremap }, +/* 217 */ { .entry = &syscall_add_key }, +/* 218 */ { .entry = &syscall_request_key }, +/* 219 */ { .entry = &syscall_keyctl }, +/* 220 */ { .entry = &syscall_clone }, +/* 221 */ { .entry = &syscall_execve }, +/* 222 */ { .entry = &syscall_mmap }, +/* 223 */ { .entry = &syscall_fadvise64_64 }, +/* 224 */ { .entry = &syscall_swapon }, +/* 225 */ { .entry = &syscall_swapoff }, +/* 226 */ { .entry = &syscall_mprotect }, +/* 227 */ { .entry = &syscall_msync }, +/* 228 */ { .entry = &syscall_mlock }, +/* 229 */ { .entry = &syscall_munlock }, +/* 230 */ { .entry = &syscall_mlockall }, +/* 231 */ { .entry = &syscall_munlockall }, +/* 232 */ { .entry = &syscall_mincore }, +/* 233 */ { .entry = &syscall_madvise }, +/* 234 */ { .entry = &syscall_remap_file_pages }, +/* 235 */ { .entry = &syscall_mbind }, +/* 236 */ { .entry = &syscall_get_mempolicy }, +/* 237 */ { .entry = &syscall_set_mempolicy }, +/* 238 */ { .entry = &syscall_migrate_pages }, +/* 239 */ { .entry = &syscall_move_pages }, +/* 240 */ { .entry = &syscall_rt_tgsigqueueinfo }, +/* 241 */ { .entry = &syscall_perf_event_open }, +/* 242 */ { .entry = &syscall_accept4 }, +/* 243 */ { .entry = &syscall_recvmmsg }, +/* 244 */ { .entry = &syscall_ni_syscall }, +/* 245 */ { .entry = &syscall_ni_syscall }, +/* 246 */ { .entry = &syscall_ni_syscall }, +/* 247 */ { .entry = &syscall_ni_syscall }, +/* 248 */ { .entry = &syscall_ni_syscall }, +/* 249 */ { .entry = &syscall_ni_syscall }, +/* 250 */ { .entry = &syscall_ni_syscall }, +/* 251 */ { .entry = &syscall_ni_syscall }, +/* 252 */ { .entry = &syscall_ni_syscall }, +/* 253 */ { .entry = &syscall_ni_syscall }, +/* 254 */ { .entry = &syscall_ni_syscall }, +/* 255 */ { .entry = &syscall_ni_syscall }, +/* 256 */ { .entry = &syscall_ni_syscall }, +/* 257 */ { .entry = &syscall_ni_syscall }, +/* 258 */ { .entry = &syscall_ni_syscall }, +/* 259 */ { .entry = &syscall_riscv_flush_icache }, +/* 260 */ { .entry = &syscall_wait4 }, +/* 261 */ { .entry = &syscall_prlimit64 }, +/* 262 */ { .entry = &syscall_fanotify_init }, +/* 263 */ { .entry = &syscall_fanotify_mark }, +/* 264 */ { .entry = &syscall_name_to_handle_at }, +/* 265 */ { .entry = &syscall_open_by_handle_at }, +/* 266 */ { .entry = &syscall_clock_adjtime }, +/* 267 */ { .entry = &syscall_syncfs }, +/* 268 */ { .entry = &syscall_setns }, +/* 269 */ { .entry = &syscall_sendmmsg }, +/* 270 */ { .entry = &syscall_process_vm_readv }, +/* 271 */ { .entry = &syscall_process_vm_writev }, +/* 272 */ { .entry = &syscall_kcmp }, +/* 273 */ { .entry = &syscall_finit_module }, +/* 274 */ { .entry = &syscall_sched_setattr }, +/* 275 */ { .entry = &syscall_sched_getattr }, +/* 276 */ { .entry = &syscall_renameat2 }, +/* 277 */ { .entry = &syscall_seccomp }, +/* 278 */ { .entry = &syscall_getrandom }, +/* 279 */ { .entry = &syscall_memfd_create }, +#ifdef USE_BPF +/* 280 */ { .entry = &syscall_bpf }, +#else + { .entry = NULL }, +#endif +/* 281 */ { .entry = &syscall_execveat }, +}; diff --git a/syscalls/riscv_flush_icache.c b/syscalls/riscv_flush_icache.c new file mode 100644 index 000000000..33d083a17 --- /dev/null +++ b/syscalls/riscv_flush_icache.c @@ -0,0 +1,25 @@ +/* + * SYSCALL_DEFINE4(wait4, pid_t, upid, int __user *, stat_addr, + int, options, struct rusage __user *, ru) + */ +#include "sanitise.h" + +#ifndef SYS_RISCV_FLUSH_ICACHE_LOCAL +#define SYS_RISCV_FLUSH_ICACHE_LOCAL 1UL +#endif + +static unsigned long riscv_flush_icache_flags[] = { + SYS_RISCV_FLUSH_ICACHE_LOCAL, +}; + +struct syscallentry syscall_riscv_flush_icache = { + .name = "riscv_flush_icache", + .num_args = 3, + .arg1name = "start", + .arg1type = ARG_ADDRESS, + .arg2name = "end", + .arg2type = ARG_ADDRESS, + .arg3name = "flags", + .arg3type = ARG_OP, + .arg3list = ARGLIST(riscv_flush_icache_flags), +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 1cca794eb..b053056ea 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -420,4 +420,6 @@ extern struct syscallentry syscall_s390_pci_mmio_read; extern struct syscallentry syscall_s390_guarded_storage; extern struct syscallentry syscall_s390_sthyi; +extern struct syscallentry syscall_riscv_flush_icache; + unsigned int random_fcntl_setfl_flags(void); From 762f31d2766f3a5cb85f023a929892bf928d6142 Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Tue, 8 Mar 2022 16:56:16 -0500 Subject: [PATCH 103/119] Fix compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fds/drm.c: In function ‘drmfd_dump’: fds/drm.c:31:49: warning: unused parameter ‘global’ [-Wunused-parameter] 31 | static void drmfd_dump(struct object *obj, bool global) | ~~~~~^~~~~~ Print 'global' to fix warning. --- fds/drm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fds/drm.c b/fds/drm.c index cac0ecc06..98ca3f2b9 100644 --- a/fds/drm.c +++ b/fds/drm.c @@ -30,7 +30,7 @@ static void drmfd_destructor(struct object *obj) static void drmfd_dump(struct object *obj, bool global) { - output(2, "drmfd:%d\n", obj->drmfd); + output(2, "drmfd:%d global:%d\n", obj->drmfd, global); } static int create_dumb(__unused__ int fd) From 57081b991f2a89afe1cd4496be3b3856e0b778e2 Mon Sep 17 00:00:00 2001 From: Chen Li Date: Thu, 6 May 2021 12:30:24 +0800 Subject: [PATCH 104/119] panic when fd number is close to limition Trinity on cpus which have many cores may open large number of child->pidstatfile, and may be reach the limition(1024 on most platforms), so just panic and warn user to increase the limition. --- include/trinity.h | 1 + include/utils.h | 2 ++ main.c | 9 +++++++++ trinity.c | 4 ++++ utils.c | 21 +++++++++++++++++++++ 5 files changed, 37 insertions(+) diff --git a/include/trinity.h b/include/trinity.h index 33d8c49c5..cfb5b74eb 100644 --- a/include/trinity.h +++ b/include/trinity.h @@ -3,6 +3,7 @@ #include "types.h" extern unsigned int num_online_cpus; +extern struct rlimit max_files_rlimit; extern bool no_bind_to_cpu; extern char *progname; diff --git a/include/utils.h b/include/utils.h index fe150d7aa..046c4c381 100644 --- a/include/utils.h +++ b/include/utils.h @@ -55,6 +55,8 @@ void kill_pid(pid_t pid); void freeptr(unsigned long *p); +int get_num_fds(void); + #define __stringify_1(x...) #x #define __stringify(x...) __stringify_1(x) diff --git a/main.c b/main.c index 7493f0202..c3ac2cd8e 100644 --- a/main.c +++ b/main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,7 @@ #include "tables.h" #include "taint.h" #include "trinity.h" +#include "utils.h" static void handle_child(int childno, pid_t childpid, int childstatus); @@ -462,6 +464,13 @@ static bool spawn_child(int childno) /* Child won't get out of init_child until we write the pid */ pids[childno] = pid; + int nr_fds = get_num_fds(); + if ((max_files_rlimit.rlim_cur - nr_fds) < 3) + { + // child->pidstatfile may be NULL below if fd limition is reached. + outputerr("current number of fd: %d, please consider ulimit -n xxx to increase fd limition\n", nr_fds); + panic(EXIT_NO_FDS); + } child->pidstatfile = open_child_pidstat(pid); shm->running_childs++; diff --git a/trinity.c b/trinity.c index 6ea4e3f85..60c03b8be 100644 --- a/trinity.c +++ b/trinity.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,7 @@ unsigned int page_size; unsigned int num_online_cpus; bool no_bind_to_cpu; unsigned int max_children; +struct rlimit max_files_rlimit; /* * just in case we're not using the test.sh harness, we @@ -107,6 +109,8 @@ int main(int argc, char* argv[]) mainpid = getpid(); + getrlimit(RLIMIT_NOFILE, &max_files_rlimit); + page_size = getpagesize(); num_online_cpus = sysconf(_SC_NPROCESSORS_ONLN); max_children = num_online_cpus * 4; /* possibly overridden in params. */ diff --git a/utils.c b/utils.c index 93bb787d5..d2b8482c1 100644 --- a/utils.c +++ b/utils.c @@ -1,9 +1,13 @@ +#include #include +#include #include +#include #include #include #include #include +#include #include "debug.h" #include "pids.h" #include "random.h" @@ -107,3 +111,20 @@ void freeptr(unsigned long *p) free(ptr); *p = 0L; } + +int get_num_fds(void) +{ + int fd_count; + char buf[64]; + struct dirent *dp; + + snprintf(buf, 64, "/proc/%i/fd/", mainpid); + + fd_count = 0; + DIR *dir = opendir(buf); + while ((dp = readdir(dir)) != NULL) { + fd_count++; + } + closedir(dir); + return fd_count; +} From 2a6d0f71492db51e9d6c2c777c29ffa78eedad9b Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Wed, 9 Mar 2022 01:32:49 -0500 Subject: [PATCH 105/119] remove -Wdeclaration-after-statement nukes those warnings like.. main.c:467:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] because it isn't 1990 any more. --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index d409dc8e8..eae1bd7e7 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,6 @@ ifneq ($(SYSROOT),) CFLAGS += --sysroot=$(SYSROOT) endif #CFLAGS += $(shell if $(CC) -m32 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-m32"; fi) -CFLAGS += -Wdeclaration-after-statement CFLAGS += -Wformat=2 CFLAGS += -Winit-self CFLAGS += -Wnested-externs From 74a370deb66da7cf20e8baf6c3fab233dd0182dc Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Wed, 9 Mar 2022 01:38:03 -0500 Subject: [PATCH 106/119] fix unlikely overflow in stallcounter this needs >10000 threads, but gcc has started warning, so this shuts it up --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index c3ac2cd8e..10b5202e4 100644 --- a/main.c +++ b/main.c @@ -688,7 +688,7 @@ static void print_stats(void) if (shm->stats.op_count - lastcount > 10000) { char stalltxt[]=" STALLED:XXXX"; - if (stall_count > 0) + if (stall_count > 0 && stall_count < 10000) sprintf(stalltxt, " STALLED:%u", stall_count); output(0, "%ld iterations. [F:%ld S:%ld HI:%ld%s]\n", shm->stats.op_count, From 3f8670b2d8b9988fe13f76c96024287fd093fce0 Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Wed, 9 Mar 2022 15:34:28 -0500 Subject: [PATCH 107/119] Ignore compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both sockaddr_pn and sockaddr_pppox are defined as "packed" on x86-64, unlike struct sockaddr, which generates warnings like this: net/proto-phonet.c: In function ‘phonet_gen_sockaddr’: net/proto-phonet.c:22:18: warning: converting a packed ‘struct sockaddr_pn’ pointer (alignment 1) to a ‘struct sockaddr’ pointer (alignment 2) may result in an unaligned pointer value [-Waddress-of-packed-member] 22 | *addr = (struct sockaddr *) pn; | ^~~~~~~~ In file included from net/proto-phonet.c:5: /usr/include/linux/phonet.h:102:8: note: defined here 102 | struct sockaddr_pn { | ^~~~~~~~~~~ In file included from /usr/include/x86_64-linux-gnu/sys/socket.h:33, from net/proto-phonet.c:2: /usr/include/x86_64-linux-gnu/bits/socket.h:178:8: note: defined here 178 | struct sockaddr | ^~~~~~~~ I'm pretty sure the alignment is fine as other things would be broken if they weren't, so just ignore the warnings in these two files. --- net/proto-phonet.c | 2 ++ net/proto-pppox.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/net/proto-phonet.c b/net/proto-phonet.c index 5407979bb..31da5d7d1 100644 --- a/net/proto-phonet.c +++ b/net/proto-phonet.c @@ -9,6 +9,8 @@ #include "utils.h" #include "compat.h" +#pragma GCC diagnostic ignored "-Waddress-of-packed-member" + static void phonet_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen) { struct sockaddr_pn *pn; diff --git a/net/proto-pppox.c b/net/proto-pppox.c index 0a0190ff7..5dcf689fa 100644 --- a/net/proto-pppox.c +++ b/net/proto-pppox.c @@ -13,6 +13,8 @@ #include "utils.h" #include "compat.h" +#pragma GCC diagnostic ignored "-Waddress-of-packed-member" + static void pppox_PX_PROTO_OE(struct sockaddr **addr, socklen_t *addrlen) { struct sockaddr_pppox *pppox; From 5714d4173f2de6408079e94caad8c67ba4b534af Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Sat, 27 Aug 2022 21:31:04 -0400 Subject: [PATCH 108/119] fix warning about pragma diagnostic pop without push --- ioctls/sgx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ioctls/sgx.c b/ioctls/sgx.c index 1fcb01f8e..1fd09b368 100644 --- a/ioctls/sgx.c +++ b/ioctls/sgx.c @@ -32,6 +32,7 @@ #define SGX_IOC_ENCLAVE_PAGE_REMOVE \ _IOW(SGX_MAGIC, 0x0d, unsigned long) +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpacked" /** * struct sgx_enclave_create - parameter structure for the From ee70baf261a76ecc2d20048cf3ce86dd0bbcbe5c Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Tue, 13 Sep 2022 00:42:54 -0400 Subject: [PATCH 109/119] futex_waitv skeleton --- include/syscalls-x86_64.h | 1 + syscalls/futex_waitv.c | 31 +++++++++++++++++++++++++++++++ syscalls/syscalls.h | 1 + 3 files changed, 33 insertions(+) create mode 100644 syscalls/futex_waitv.c diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index 8d0b1028e..159e5710d 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -460,4 +460,5 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_landlock_restrict_self }, { .entry = &syscall_memfd_secret }, { .entry = &syscall_process_mrelease }, + { .entry = &syscall_futex_waitv }, }; diff --git a/syscalls/futex_waitv.c b/syscalls/futex_waitv.c new file mode 100644 index 000000000..6da98abf8 --- /dev/null +++ b/syscalls/futex_waitv.c @@ -0,0 +1,31 @@ +/* + * SYSCALL_DEFINE5(futex_waitv, struct futex_waitv __user *, waiters, + unsigned int, nr_futexes, unsigned int, flags, + struct __kernel_timespec __user *, timeout, clockid_t, clockid) + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "sanitise.h" + +static void sanitise_futex_waitv(struct syscallrecord *rec) +{ + rec->a3 = 0; // no flags right now +} + +struct syscallentry syscall_futex_waitv = { + .name = "futex_waitv", + .num_args = 5, + .arg1name = "waiters", + .arg2name = "nr_futexes", + .arg3name = "flags", + .arg4name = "timeout", + .arg5name = "clockid", + .flags = NEED_ALARM | IGNORE_ENOSYS, + .sanitise = sanitise_futex_waitv, +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index b053056ea..3a7230de5 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -413,6 +413,7 @@ extern struct syscallentry syscall_landlock_add_rule; extern struct syscallentry syscall_landlock_restrict_self; extern struct syscallentry syscall_memfd_secret; extern struct syscallentry syscall_process_mrelease; +extern struct syscallentry syscall_futex_waitv; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; From e63e484304de349150298c2e9fad38dfeae0b1cb Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Tue, 13 Sep 2022 00:46:16 -0400 Subject: [PATCH 110/119] set_mempolicy_home_node skeleton --- include/syscalls-x86_64.h | 1 + syscalls/set_mempolicy_home_node.c | 20 ++++++++++++++++++++ syscalls/syscalls.h | 1 + 3 files changed, 22 insertions(+) create mode 100644 syscalls/set_mempolicy_home_node.c diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index 159e5710d..2b7bf7d9f 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -461,4 +461,5 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_memfd_secret }, { .entry = &syscall_process_mrelease }, { .entry = &syscall_futex_waitv }, + { .entry = &syscall_set_mempolicy_home_node }, }; diff --git a/syscalls/set_mempolicy_home_node.c b/syscalls/set_mempolicy_home_node.c new file mode 100644 index 000000000..63f0c7227 --- /dev/null +++ b/syscalls/set_mempolicy_home_node.c @@ -0,0 +1,20 @@ +/* + * SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, len, unsigned long, home_node, unsigned long, flags) + */ +#include "sanitise.h" + +static void sanitise_set_mempolicy_home_node(struct syscallrecord *rec) +{ + rec->a4 = 0; // no flags right now +} + +struct syscallentry syscall_set_mempolicy_home_node = { + .name = "set_mempolicy_home_node", + .num_args = 4, + .arg1name = "start", + .arg2name = "len", + .arg2type = ARG_LEN, + .arg3name = "home_node", + .arg4name = "flags", + .sanitise = sanitise_set_mempolicy_home_node, +}; diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 3a7230de5..cfa59a6a8 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -414,6 +414,7 @@ extern struct syscallentry syscall_landlock_restrict_self; extern struct syscallentry syscall_memfd_secret; extern struct syscallentry syscall_process_mrelease; extern struct syscallentry syscall_futex_waitv; +extern struct syscallentry syscall_set_mempolicy_home_node; extern struct syscallentry syscall_runtime_instr; extern struct syscallentry syscall_s390_pci_mmio_write; From 99a1822383a676e0bacfe1cd8ff0e2e2dfb8ba76 Mon Sep 17 00:00:00 2001 From: Fabrice Fontaine Date: Sun, 8 Jan 2023 20:50:18 +0100 Subject: [PATCH 111/119] drop decnet Drop decnet as it has been removed since kernel 6.1 and https://github.com/torvalds/linux/commit/1202cdd665315c525b5237e96e0bedc76d7e754f resulting in the following build failure: net/proto-decnet.c:5:10: fatal error: linux/dn.h: No such file or directory 5 | #include | ^~~~~~~~~~~~ Fixes: - http://autobuild.buildroot.org/results/47e0a5e0b6fcf33ab4f9848d5d8c2be9e5283950 Signed-off-by: Fabrice Fontaine --- include/net.h | 1 - net/proto-decnet.c | 59 ---------------------------------------------- net/proto-unix.c | 1 - net/protocols.c | 1 - 4 files changed, 62 deletions(-) delete mode 100644 net/proto-decnet.c diff --git a/include/net.h b/include/net.h index 99d55363f..791e80900 100644 --- a/include/net.h +++ b/include/net.h @@ -80,7 +80,6 @@ extern const struct netproto proto_atmpvc; extern const struct netproto proto_atmsvc; extern const struct netproto proto_x25; extern const struct netproto proto_rose; -extern const struct netproto proto_decnet; extern const struct netproto proto_llc; extern const struct netproto proto_netlink; extern const struct netproto proto_packet; diff --git a/net/proto-decnet.c b/net/proto-decnet.c deleted file mode 100644 index 7711cf007..000000000 --- a/net/proto-decnet.c +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "net.h" -#include "random.h" -#include "utils.h" // RAND_ARRAY -#include "compat.h" - -static void decnet_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen) -{ - struct sockaddr_dn *dn; - unsigned int i; - - dn = zmalloc(sizeof(struct sockaddr_dn)); - - dn->sdn_family = PF_DECnet; - dn->sdn_flags = rnd(); - dn->sdn_objnum = rnd(); - dn->sdn_objnamel = rnd() % 16; - for (i = 0; i < dn->sdn_objnamel; i++) - dn->sdn_objname[i] = rnd(); - dn->sdn_add.a_len = RAND_BOOL(); - dn->sdn_add.a_addr[0] = rnd(); - dn->sdn_add.a_addr[1] = rnd(); - *addr = (struct sockaddr *) dn; - *addrlen = sizeof(struct sockaddr_dn); -} - -static const unsigned int decnet_opts[] = { - SO_CONDATA, SO_CONACCESS, SO_PROXYUSR, SO_LINKINFO, - DSO_CONDATA, DSO_DISDATA, DSO_CONACCESS, DSO_ACCEPTMODE, - DSO_CONACCEPT, DSO_CONREJECT, DSO_LINKINFO, DSO_STREAM, - DSO_SEQPACKET, DSO_MAXWINDOW, DSO_NODELAY, DSO_CORK, - DSO_SERVICES, DSO_INFO -}; - -static void decnet_setsockopt(struct sockopt *so, __unused__ struct socket_triplet *triplet) -{ - so->level = SOL_DECNET; - so->optname = RAND_ARRAY(decnet_opts); - - // TODO: set optlen correctly -} - -static struct socket_triplet decnet_triplets[] = { - { .family = PF_DECnet, .protocol = DNPROTO_NSP, .type = SOCK_SEQPACKET }, - { .family = PF_DECnet, .protocol = DNPROTO_NSP, .type = SOCK_STREAM }, -}; - -const struct netproto proto_decnet = { - .name = "decnet", - .setsockopt = decnet_setsockopt, - .gen_sockaddr = decnet_gen_sockaddr, - .valid_triplets = decnet_triplets, - .nr_triplets = ARRAY_SIZE(decnet_triplets), -}; diff --git a/net/proto-unix.c b/net/proto-unix.c index f7427a227..119c14293 100644 --- a/net/proto-unix.c +++ b/net/proto-unix.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include "net.h" #include "random.h" diff --git a/net/protocols.c b/net/protocols.c index ea64d5f5d..278f08b53 100644 --- a/net/protocols.c +++ b/net/protocols.c @@ -18,7 +18,6 @@ const struct protoptr net_protocols[TRINITY_PF_MAX] = { #ifdef USE_IPV6 [PF_INET6] = { .proto = &proto_inet6 }, #endif - [PF_DECnet] = { .proto = &proto_decnet }, [PF_PACKET] = { .proto = &proto_packet }, #ifdef USE_NETECONET [PF_ECONET] = { .proto = &proto_econet }, From 09ddd021db5673074e05f980e998a640ec7a4df9 Mon Sep 17 00:00:00 2001 From: zhangya <461177348@qq.com> Date: Sun, 3 May 2020 16:09:27 +0800 Subject: [PATCH 112/119] fix: previous_op_count may more than op_count case process data compete. I met this under mips64 debian --- main.c | 6 +++++- shm.c | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) mode change 100644 => 100755 main.c diff --git a/main.c b/main.c old mode 100644 new mode 100755 index 10b5202e4..64c6bc0d9 --- a/main.c +++ b/main.c @@ -39,7 +39,11 @@ static int shm_is_corrupt(void) { unsigned int i; - if (shm->stats.op_count < shm->stats.previous_op_count) { + unsigned long current_previous_op_count = shm->stats.previous_op_count; + unsigned long current_op_count = shm->stats.op_count; + + //if (shm->stats.op_count < shm->stats.previous_op_count) { + if (current_op_count < current_previous_op_count) { output(0, "Execcount went backwards! (old:%ld new:%ld):\n", shm->stats.previous_op_count, shm->stats.op_count); panic(EXIT_SHM_CORRUPTION); diff --git a/shm.c b/shm.c index 575b583b1..39ae5afd3 100644 --- a/shm.c +++ b/shm.c @@ -49,6 +49,7 @@ void init_shm(void) shm->debug = TRUE; shm->stats.op_count = 0; + shm->stats.previous_op_count = 0; shm->seed = init_seed(seed); From 87f15303f1487de58fcb012560cb2eac59229a64 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 9 Jan 2023 17:01:48 -0500 Subject: [PATCH 113/119] periodic version bump --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index eae1bd7e7..88520a91b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION="2021.10" +VERSION="2023.01" INSTALL_PREFIX ?= $(DESTDIR) INSTALL_PREFIX ?= $(HOME) From ca07c86b2aeeb91213922eaf481c9e224679a7fd Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Fri, 17 Mar 2023 20:28:24 +0100 Subject: [PATCH 114/119] kvm: drop KVM_SET_MEMORY_REGION (#42) It was dropped in upstream in commit 61e15f871241 (KVM: Delete all references to removed KVM_SET_MEMORY_REGION ioctl). Co-authored-by: Jiri Slaby --- ioctls/kvm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ioctls/kvm.c b/ioctls/kvm.c index 14c55ef10..30aeed7a9 100644 --- a/ioctls/kvm.c +++ b/ioctls/kvm.c @@ -8,7 +8,6 @@ #include "utils.h" static const struct ioctl kvm_ioctls[] = { - IOCTL(KVM_SET_MEMORY_REGION), IOCTL(KVM_CREATE_VCPU), IOCTL(KVM_GET_DIRTY_LOG), IOCTL(KVM_SET_NR_MMU_PAGES), From abe9de860a9083a9a3c73b7230b572b458c06c71 Mon Sep 17 00:00:00 2001 From: Weisson-Han <126548767+Weisson-Han@users.noreply.github.com> Date: Wed, 26 Apr 2023 13:39:54 +0800 Subject: [PATCH 115/119] Avoid array access out of bounds error during initialzation of fd providers. (#43) Signed-off-by: Weisson Co-authored-by: Weisson --- syscalls/setsockopt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syscalls/setsockopt.c b/syscalls/setsockopt.c index 0d41fe95b..2ac345646 100644 --- a/syscalls/setsockopt.c +++ b/syscalls/setsockopt.c @@ -94,7 +94,7 @@ static void do_random_sso(struct sockopt *so, struct socket_triplet *triplet) retry: switch (rnd() % 4) { case 0: /* do a random protocol, even if it doesn't match this socket. */ - i = rnd() % PF_MAX; + i = rnd() % TRINITY_PF_MAX; proto = net_protocols[i].proto; if (proto != NULL) { if (proto->setsockopt != NULL) { From 3cebd54dceb7e63054b227ea21ed39eac20bd9f6 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Wed, 3 May 2023 23:08:40 -0400 Subject: [PATCH 116/119] update i386 syscall list --- include/syscalls-i386.h | 15 +++++++++++++++ scripts/hashcheck.sh | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/syscalls-i386.h b/include/syscalls-i386.h index 847e2dea5..ce8e211ec 100644 --- a/include/syscalls-i386.h +++ b/include/syscalls-i386.h @@ -440,4 +440,19 @@ struct syscalltable syscalls_i386[] = { { .entry = &syscall_fspick }, { .entry = &syscall_pidfd_open }, { .entry = &syscall_clone3 }, + { .entry = &syscall_close_range }, + { .entry = &syscall_openat2 }, + { .entry = &syscall_pidfd_getfd }, + { .entry = &syscall_faccessat2 }, + { .entry = &syscall_process_madvise }, + { .entry = &syscall_epoll_pwait2 }, + { .entry = &syscall_mount_setattr }, + { .entry = &syscall_quotactl_fd }, + { .entry = &syscall_landlock_create_ruleset }, + { .entry = &syscall_landlock_add_rule }, + { .entry = &syscall_landlock_restrict_self }, + { .entry = &syscall_memfd_secret }, + { .entry = &syscall_process_mrelease }, + { .entry = &syscall_futex_waitv }, + { .entry = &syscall_set_mempolicy_home_node }, }; diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh index 1578cc678..d82074bbe 100755 --- a/scripts/hashcheck.sh +++ b/scripts/hashcheck.sh @@ -28,8 +28,8 @@ check() check include/uapi/asm-generic/unistd.h 11c46e9ce6393e7c8a17577c6128b78684395016 sys_ #check arch/alpha/include/uapi/asm/unistd.h 51fa669a21d8f26a0c9de8280a3cfd9c257a0d28 _NR_ #check arch/arm/include/uapi/asm/unistd.h 7c601d436a3ebbe05a9b6813c0ffcf8eedaf101b SYSCALL -check arch/x86/entry/syscalls/syscall_32.tbl be7686afac49943e1a89447b1d09f4a6e868f482 sys_ -check arch/x86/entry/syscalls/syscall_64.tbl 8c8f94228fc4f325cf635fce25adf411f3714d1e sys_ +check arch/x86/entry/syscalls/syscall_32.tbl a2232d6f101274762e9fab44dabb07d86a3719ee sys_ +check arch/x86/entry/syscalls/syscall_64.tbl 60d2554683c0a8638f6a874f2ff74ede49435564 sys_ check arch/x86/entry/syscalls/syscall_64.tbl da39a3ee5e6b4b0d3255bfef95601890afd80709 stub_ #check arch/ia64/kernel/entry.S e6a21b973609ec08cd19b0b8c67830f8570e93ef "data8\ sys_" #check arch/mips/kernel/scall32-o32.S b1501a675dd998fe2af68ae43cd797cf18d67b33 sys_ From 6823bacb3c2564bff5da3175c574fd6a6af4d8b2 Mon Sep 17 00:00:00 2001 From: chuhu Date: Sat, 1 Jul 2023 01:02:37 +0800 Subject: [PATCH 117/119] ioctls/drm: check i810,mga,r128 and savage support (#44) kernel v6.3-rc1 removed some drm drivers, so add the extra check to make the compile succeed. 7872bc2cb13e drm: Remove the obsolete driver-savage 28483b8666bf drm: Remove the obsolete driver-r128 96ed7db55bef drm: Remove the obsolete driver-mga cab18866fead drm: Remove the obsolete driver-i810 Signed-off-by: Chunyu Hu --- configure | 4 ++++ ioctls/drm.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/configure b/configure index 944c8cf77..bbaf9afce 100755 --- a/configure +++ b/configure @@ -320,6 +320,10 @@ check_header linux/irda.h USE_IRDA check_header linux/rds.h USE_RDS check_header linux/vfio.h USE_VFIO check_header drm/drm.h USE_DRM +check_header drm/i810_drm.h USE_DRM_I810 +check_header drm/mga_drm.h USE_DRM_MGA +check_header drm/r128_drm.h USE_DRM_R128 +check_header drm/savage_drm.h USE_DRM_SAVAGE check_header drm/exynos_drm.h USE_DRM_EXYNOS check_header sound/compress_offload.h USE_SNDDRV_COMPRESS_OFFLOAD check_header linux/kvm.h USE_KVM diff --git a/ioctls/drm.c b/ioctls/drm.c index 81ed36824..a07a84369 100644 --- a/ioctls/drm.c +++ b/ioctls/drm.c @@ -8,13 +8,21 @@ #ifdef USE_DRM_EXYNOS #include #endif +#ifdef USE_DRM_I810 #include +#endif #include +#ifdef USE_DRM_MGA #include +#endif #include +#ifdef USE_DRM_R128 #include +#endif #include +#ifdef USE_DRM_SAVAGE #include +#endif #include "ioctls.h" #include "utils.h" @@ -293,6 +301,7 @@ static const struct ioctl drm_ioctls[] = { #endif #endif +#ifdef USE_DRM_I810 /* i810_drm.h */ IOCTL(DRM_IOCTL_I810_INIT), IOCTL(DRM_IOCTL_I810_VERTEX), @@ -309,6 +318,7 @@ static const struct ioctl drm_ioctls[] = { IOCTL(DRM_IOCTL_I810_MC), IOCTL(DRM_IOCTL_I810_RSTATUS), IOCTL(DRM_IOCTL_I810_FLIP), +#endif /* i915_drm.h */ IOCTL(DRM_IOCTL_I915_INIT), @@ -378,6 +388,7 @@ static const struct ioctl drm_ioctls[] = { IOCTL(DRM_IOCTL_I915_REG_READ), #endif +#ifdef USE_DRM_MGA /* mga_drm.h */ IOCTL(DRM_IOCTL_MGA_INIT), IOCTL(DRM_IOCTL_MGA_FLUSH), @@ -401,6 +412,7 @@ static const struct ioctl drm_ioctls[] = { IOCTL(DRM_IOCTL_NOUVEAU_GROBJ_ALLOC), IOCTL(DRM_IOCTL_NOUVEAU_NOTIFIEROBJ_ALLOC), IOCTL(DRM_IOCTL_NOUVEAU_GPUOBJ_FREE), +#endif #ifdef DRM_IOCTL_NOUVEAU_GEM_NEW IOCTL(DRM_IOCTL_NOUVEAU_GEM_NEW), #endif @@ -417,6 +429,7 @@ static const struct ioctl drm_ioctls[] = { IOCTL(DRM_IOCTL_NOUVEAU_GEM_INFO), #endif +#ifdef USE_DRM_R128 /* r128_drm.h */ IOCTL(DRM_IOCTL_R128_INIT), IOCTL(DRM_IOCTL_R128_CCE_START), @@ -435,6 +448,7 @@ static const struct ioctl drm_ioctls[] = { IOCTL(DRM_IOCTL_R128_FULLSCREEN), IOCTL(DRM_IOCTL_R128_GETPARAM), IOCTL(DRM_IOCTL_R128_FLIP), +#endif /* radeon_drm.h */ IOCTL(DRM_IOCTL_RADEON_CP_INIT), From e71872454d26baf37ae1d12e9b04a73d64179555 Mon Sep 17 00:00:00 2001 From: chuhu Date: Tue, 11 Jul 2023 02:57:35 +0800 Subject: [PATCH 118/119] ioctls/drm: fix DRM_MGA check (#45) Some IOCTL_NOUVEAU tests are checked under USE_DRM_MGA macro, this is not correct, correct it. Fixes: 6823bacb (ioctls/drm: check i810,mga,r128 and savage support (#44)) Signed-off-by: Chunyu Hu --- ioctls/drm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ioctls/drm.c b/ioctls/drm.c index a07a84369..d938f7075 100644 --- a/ioctls/drm.c +++ b/ioctls/drm.c @@ -403,6 +403,7 @@ static const struct ioctl drm_ioctls[] = { IOCTL(DRM_IOCTL_MGA_SET_FENCE), IOCTL(DRM_IOCTL_MGA_WAIT_FENCE), IOCTL(DRM_IOCTL_MGA_DMA_BOOTSTRAP), +#endif /* nouveau_drm.h */ IOCTL(DRM_IOCTL_NOUVEAU_GETPARAM), @@ -412,7 +413,6 @@ static const struct ioctl drm_ioctls[] = { IOCTL(DRM_IOCTL_NOUVEAU_GROBJ_ALLOC), IOCTL(DRM_IOCTL_NOUVEAU_NOTIFIEROBJ_ALLOC), IOCTL(DRM_IOCTL_NOUVEAU_GPUOBJ_FREE), -#endif #ifdef DRM_IOCTL_NOUVEAU_GEM_NEW IOCTL(DRM_IOCTL_NOUVEAU_GEM_NEW), #endif From dd950fa33ed5d60758923ca182f4f71f78640208 Mon Sep 17 00:00:00 2001 From: wuruilong Date: Wed, 13 Sep 2023 01:28:53 +0000 Subject: [PATCH 119/119] add support for loongarch --- include/arch-loongarch.h | 16 ++ include/arch-syscalls.h | 3 + include/arch.h | 4 + include/syscalls-loongarch-64.h | 458 ++++++++++++++++++++++++++++++++ include/syscalls-loongarch.h | 4 + ioctls/autofs.c | 1 + ioctls/scsi.c | 2 +- syscalls/vmsplice.c | 2 - sysv-shm.c | 5 +- 9 files changed, 489 insertions(+), 6 deletions(-) create mode 100644 include/arch-loongarch.h create mode 100644 include/syscalls-loongarch-64.h create mode 100644 include/syscalls-loongarch.h diff --git a/include/arch-loongarch.h b/include/arch-loongarch.h new file mode 100644 index 000000000..81452c29a --- /dev/null +++ b/include/arch-loongarch.h @@ -0,0 +1,16 @@ +#pragma once + +#define PAGE_OFFSET 0x9000000000000000 +#define TASK_SIZE (PAGE_OFFSET) +#define MODULE_ADDR 0xffff800000000000 +#define KERNEL_ADDR 0x9000000000000000 + +#define PAGE_SHIFT 14 +#define PTE_FILE_MAX_BITS 31 + +#define PTRACE_GETREGS 0 +#define PTRACE_GETFPREGS 0 +#define PTRACE_SETREGS 0 +#define PTRACE_SETFPREGS 0 + +#define SYSCALLS syscalls_loongarch diff --git a/include/arch-syscalls.h b/include/arch-syscalls.h index 64cfa1029..5a933175a 100644 --- a/include/arch-syscalls.h +++ b/include/arch-syscalls.h @@ -50,3 +50,6 @@ #error "riscv32 is not supported yet." #endif #endif +#ifdef __loongarch__ +#include "syscalls-loongarch.h" +#endif diff --git a/include/arch.h b/include/arch.h index a4baaab03..348b5671c 100644 --- a/include/arch.h +++ b/include/arch.h @@ -62,6 +62,10 @@ #endif #endif +#ifdef __loongarch__ +#include "arch-loongarch.h" +#endif + #ifndef SYSCALL_OFFSET #define SYSCALL_OFFSET 0 #endif diff --git a/include/syscalls-loongarch-64.h b/include/syscalls-loongarch-64.h new file mode 100644 index 000000000..8e9236421 --- /dev/null +++ b/include/syscalls-loongarch-64.h @@ -0,0 +1,458 @@ +#pragma once + +/* + * inherits from include/uapi/asm-generic/unistd.h + */ + +#include "sanitise.h" +#include "syscall.h" +#include "syscalls/syscalls.h" + +struct syscalltable syscalls_loongarch[] = { +/* 0 */ { .entry = &syscall_io_setup }, +/* 1 */ { .entry = &syscall_io_destroy }, +/* 2 */ { .entry = &syscall_io_submit }, +/* 3 */ { .entry = &syscall_io_cancel }, +/* 4 */ { .entry = &syscall_io_getevents }, +/* 5 */ { .entry = &syscall_setxattr }, +/* 6 */ { .entry = &syscall_lsetxattr }, +/* 7 */ { .entry = &syscall_fsetxattr }, +/* 8 */ { .entry = &syscall_getxattr }, +/* 9 */ { .entry = &syscall_lgetxattr }, +/* 10 */ { .entry = &syscall_fgetxattr }, +/* 11 */ { .entry = &syscall_listxattr }, +/* 12 */ { .entry = &syscall_llistxattr }, +/* 13 */ { .entry = &syscall_flistxattr }, +/* 14 */ { .entry = &syscall_removexattr }, +/* 15 */ { .entry = &syscall_lremovexattr }, +/* 16 */ { .entry = &syscall_fremovexattr }, +/* 17 */ { .entry = &syscall_getcwd }, +/* 18 */ { .entry = &syscall_lookup_dcookie }, +/* 19 */ { .entry = &syscall_eventfd2 }, +/* 20 */ { .entry = &syscall_epoll_create1 }, +/* 21 */ { .entry = &syscall_epoll_ctl }, +/* 22 */ { .entry = &syscall_epoll_pwait }, +/* 23 */ { .entry = &syscall_dup }, +/* 24 */ { .entry = &syscall_dup3 }, +/* 25 */ { .entry = &syscall_fcntl }, +/* 26 */ { .entry = &syscall_inotify_init1 }, +/* 27 */ { .entry = &syscall_inotify_add_watch }, +/* 28 */ { .entry = &syscall_inotify_rm_watch }, +/* 29 */ { .entry = &syscall_ioctl }, +/* 30 */ { .entry = &syscall_ioprio_set }, +/* 31 */ { .entry = &syscall_ioprio_get }, +/* 32 */ { .entry = &syscall_flock }, +/* 33 */ { .entry = &syscall_mknodat }, +/* 34 */ { .entry = &syscall_mkdirat }, +/* 35 */ { .entry = &syscall_unlinkat }, +/* 36 */ { .entry = &syscall_symlinkat }, +/* 37 */ { .entry = &syscall_linkat }, +/* 38 */ { .entry = NULL }, +/* 39 */ { .entry = &syscall_umount }, +/* 40 */ { .entry = &syscall_mount }, +/* 41 */ { .entry = &syscall_pivot_root }, +/* 42 */ { .entry = &syscall_ni_syscall }, +/* 43 */ { .entry = &syscall_statfs }, +/* 44 */ { .entry = &syscall_fstatfs }, +/* 45 */ { .entry = &syscall_truncate }, +/* 46 */ { .entry = &syscall_ftruncate }, +/* 47 */ { .entry = &syscall_fallocate }, +/* 48 */ { .entry = &syscall_faccessat }, +/* 49 */ { .entry = &syscall_chdir }, +/* 50 */ { .entry = &syscall_fchdir }, +/* 51 */ { .entry = &syscall_chroot }, +/* 52 */ { .entry = &syscall_fchmod }, +/* 53 */ { .entry = &syscall_fchmodat }, +/* 54 */ { .entry = &syscall_fchownat }, +/* 55 */ { .entry = &syscall_fchown }, +/* 56 */ { .entry = &syscall_openat }, +/* 57 */ { .entry = &syscall_close }, +/* 58 */ { .entry = &syscall_vhangup }, +/* 59 */ { .entry = &syscall_pipe2 }, +/* 60 */ { .entry = &syscall_quotactl }, +/* 61 */ { .entry = &syscall_getdents64 }, +/* 62 */ { .entry = &syscall_lseek }, +/* 63 */ { .entry = &syscall_read }, +/* 64 */ { .entry = &syscall_write }, +/* 65 */ { .entry = &syscall_readv }, +/* 66 */ { .entry = &syscall_writev }, +/* 67 */ { .entry = &syscall_pread64 }, +/* 68 */ { .entry = &syscall_pwrite64 }, +/* 69 */ { .entry = &syscall_preadv }, +/* 70 */ { .entry = &syscall_pwritev }, +/* 71 */ { .entry = &syscall_sendfile64 }, +/* 72 */ { .entry = &syscall_pselect6 }, +/* 73 */ { .entry = &syscall_ppoll }, +/* 74 */ { .entry = &syscall_signalfd4 }, +/* 75 */ { .entry = &syscall_vmsplice }, +/* 76 */ { .entry = &syscall_splice }, +/* 77 */ { .entry = &syscall_tee }, +/* 78 */ { .entry = &syscall_readlinkat }, +/* 79 */ { .entry = NULL }, +/* 80 */ { .entry = NULL }, +/* 81 */ { .entry = &syscall_sync }, +/* 82 */ { .entry = &syscall_fsync }, +/* 83 */ { .entry = &syscall_fdatasync }, +/* 84 */ { .entry = &syscall_sync_file_range }, +/* 85 */ { .entry = &syscall_timerfd_create }, +/* 86 */ { .entry = &syscall_timerfd_settime }, +/* 87 */ { .entry = &syscall_timerfd_gettime }, +/* 88 */ { .entry = &syscall_utimensat }, +/* 89 */ { .entry = &syscall_acct }, +/* 90 */ { .entry = &syscall_capget }, +/* 91 */ { .entry = &syscall_capset }, +/* 92 */ { .entry = &syscall_personality }, +/* 93 */ { .entry = &syscall_exit }, +/* 94 */ { .entry = &syscall_exit_group }, +/* 95 */ { .entry = &syscall_waitid }, +/* 96 */ { .entry = &syscall_set_tid_address }, +/* 97 */ { .entry = &syscall_unshare }, +/* 98 */ { .entry = &syscall_futex }, +/* 99 */ { .entry = &syscall_set_robust_list }, +/* 100 */ { .entry = &syscall_get_robust_list }, +/* 101 */ { .entry = &syscall_nanosleep }, +/* 102 */ { .entry = &syscall_getitimer }, +/* 103 */ { .entry = &syscall_setitimer }, +/* 104 */ { .entry = &syscall_kexec_load }, +/* 105 */ { .entry = &syscall_init_module }, +/* 106 */ { .entry = &syscall_delete_module }, +/* 107 */ { .entry = &syscall_timer_create }, +/* 108 */ { .entry = &syscall_timer_gettime }, +/* 109 */ { .entry = &syscall_timer_getoverrun }, +/* 110 */ { .entry = &syscall_timer_settime }, +/* 111 */ { .entry = &syscall_timer_delete }, +/* 112 */ { .entry = &syscall_clock_settime }, +/* 113 */ { .entry = &syscall_clock_gettime }, +/* 114 */ { .entry = &syscall_clock_getres }, +/* 115 */ { .entry = &syscall_clock_nanosleep }, +/* 116 */ { .entry = &syscall_syslog }, +/* 117 */ { .entry = &syscall_ptrace }, +/* 118 */ { .entry = &syscall_sched_setparam }, +/* 119 */ { .entry = &syscall_sched_setscheduler }, +/* 120 */ { .entry = &syscall_sched_getscheduler }, +/* 121 */ { .entry = &syscall_sched_getparam }, +/* 122 */ { .entry = &syscall_sched_setaffinity }, +/* 123 */ { .entry = &syscall_sched_getaffinity }, +/* 124 */ { .entry = &syscall_sched_yield }, +/* 125 */ { .entry = &syscall_sched_get_priority_max }, +/* 126 */ { .entry = &syscall_sched_get_priority_min }, +/* 127 */ { .entry = &syscall_sched_rr_get_interval }, +/* 128 */ { .entry = &syscall_restart_syscall }, +/* 129 */ { .entry = &syscall_kill }, +/* 130 */ { .entry = &syscall_tkill }, +/* 131 */ { .entry = &syscall_tgkill }, +/* 132 */ { .entry = &syscall_sigaltstack }, +/* 133 */ { .entry = &syscall_rt_sigsuspend }, +/* 134 */ { .entry = &syscall_rt_sigaction }, +/* 135 */ { .entry = &syscall_rt_sigprocmask }, +/* 136 */ { .entry = &syscall_rt_sigpending }, +/* 137 */ { .entry = &syscall_rt_sigtimedwait }, +/* 138 */ { .entry = &syscall_rt_sigqueueinfo }, +/* 139 */ { .entry = &syscall_rt_sigreturn }, +/* 140 */ { .entry = &syscall_setpriority }, +/* 141 */ { .entry = &syscall_getpriority }, +/* 142 */ { .entry = &syscall_reboot }, +/* 143 */ { .entry = &syscall_setregid }, +/* 144 */ { .entry = &syscall_setgid }, +/* 145 */ { .entry = &syscall_setreuid }, +/* 146 */ { .entry = &syscall_setuid }, +/* 147 */ { .entry = &syscall_setresuid }, +/* 148 */ { .entry = &syscall_getresuid }, +/* 149 */ { .entry = &syscall_setresgid }, +/* 150 */ { .entry = &syscall_getresgid }, +/* 151 */ { .entry = &syscall_setfsuid }, +/* 152 */ { .entry = &syscall_setfsgid }, +/* 153 */ { .entry = &syscall_times }, +/* 154 */ { .entry = &syscall_setpgid }, +/* 155 */ { .entry = &syscall_getpgid }, +/* 156 */ { .entry = &syscall_getsid }, +/* 157 */ { .entry = &syscall_setsid }, +/* 158 */ { .entry = &syscall_getgroups }, +/* 159 */ { .entry = &syscall_setgroups }, +/* 160 */ { .entry = &syscall_newuname }, +/* 161 */ { .entry = &syscall_sethostname }, +/* 162 */ { .entry = &syscall_setdomainname }, +/* 163 */ { .entry = NULL }, +/* 164 */ { .entry = NULL }, +/* 165 */ { .entry = &syscall_getrusage }, +/* 166 */ { .entry = &syscall_umask }, +/* 167 */ { .entry = &syscall_prctl }, +/* 168 */ { .entry = &syscall_getcpu }, +/* 169 */ { .entry = &syscall_gettimeofday }, +/* 170 */ { .entry = &syscall_settimeofday }, +/* 171 */ { .entry = &syscall_adjtimex }, +/* 172 */ { .entry = &syscall_getpid }, +/* 173 */ { .entry = &syscall_getppid }, +/* 174 */ { .entry = &syscall_getuid }, +/* 175 */ { .entry = &syscall_geteuid }, +/* 176 */ { .entry = &syscall_getgid }, +/* 177 */ { .entry = &syscall_getegid }, +/* 178 */ { .entry = &syscall_gettid }, +/* 179 */ { .entry = &syscall_sysinfo }, +/* 180 */ { .entry = &syscall_mq_open }, +/* 181 */ { .entry = &syscall_mq_unlink }, +/* 182 */ { .entry = &syscall_mq_timedsend }, +/* 183 */ { .entry = &syscall_mq_timedreceive }, +/* 184 */ { .entry = &syscall_mq_notify }, +/* 185 */ { .entry = &syscall_mq_getsetattr }, +/* 186 */ { .entry = &syscall_msgget }, +/* 187 */ { .entry = &syscall_msgctl }, +/* 188 */ { .entry = &syscall_msgrcv }, +/* 189 */ { .entry = &syscall_msgsnd }, +/* 190 */ { .entry = &syscall_semget }, +/* 191 */ { .entry = &syscall_semctl }, +/* 192 */ { .entry = &syscall_semtimedop }, +/* 193 */ { .entry = &syscall_semop }, +/* 194 */ { .entry = &syscall_shmget }, +/* 195 */ { .entry = &syscall_shmctl }, +/* 196 */ { .entry = &syscall_shmat }, +/* 197 */ { .entry = &syscall_shmdt }, +/* 198 */ { .entry = &syscall_socket }, +/* 199 */ { .entry = &syscall_socketpair }, +/* 200 */ { .entry = &syscall_bind }, +/* 201 */ { .entry = &syscall_listen }, +/* 202 */ { .entry = &syscall_accept }, +/* 203 */ { .entry = &syscall_connect }, +/* 204 */ { .entry = &syscall_getsockname }, +/* 205 */ { .entry = &syscall_getpeername }, +/* 206 */ { .entry = &syscall_sendto }, +/* 207 */ { .entry = &syscall_recvfrom }, +/* 208 */ { .entry = &syscall_setsockopt }, +/* 209 */ { .entry = &syscall_getsockopt }, +/* 210 */ { .entry = &syscall_shutdown }, +/* 211 */ { .entry = &syscall_sendmsg }, +/* 212 */ { .entry = &syscall_recvmsg }, +/* 213 */ { .entry = &syscall_readahead }, +/* 214 */ { .entry = &syscall_brk }, +/* 215 */ { .entry = &syscall_munmap }, +/* 216 */ { .entry = &syscall_mremap }, +/* 217 */ { .entry = &syscall_add_key }, +/* 218 */ { .entry = &syscall_request_key }, +/* 219 */ { .entry = &syscall_keyctl }, +/* 220 */ { .entry = &syscall_clone }, +/* 221 */ { .entry = &syscall_execve }, +/* 222 */ { .entry = &syscall_mmap }, +/* 223 */ { .entry = &syscall_fadvise64_64 }, +/* 224 */ { .entry = &syscall_swapon }, +/* 225 */ { .entry = &syscall_swapoff }, +/* 226 */ { .entry = &syscall_mprotect }, +/* 227 */ { .entry = &syscall_msync }, +/* 228 */ { .entry = &syscall_mlock }, +/* 229 */ { .entry = &syscall_munlock }, +/* 230 */ { .entry = &syscall_mlockall }, +/* 231 */ { .entry = &syscall_munlockall }, +/* 232 */ { .entry = &syscall_mincore }, +/* 233 */ { .entry = &syscall_madvise }, +/* 234 */ { .entry = &syscall_remap_file_pages }, +/* 235 */ { .entry = &syscall_mbind }, +/* 236 */ { .entry = &syscall_get_mempolicy }, +/* 237 */ { .entry = &syscall_set_mempolicy }, +/* 238 */ { .entry = &syscall_migrate_pages }, +/* 239 */ { .entry = &syscall_move_pages }, +/* 240 */ { .entry = &syscall_rt_tgsigqueueinfo }, +/* 241 */ { .entry = &syscall_perf_event_open }, +/* 242 */ { .entry = &syscall_accept4 }, +/* 243 */ { .entry = &syscall_recvmmsg }, +/* 244 */ { .entry = &syscall_ni_syscall }, +/* 245 */ { .entry = &syscall_ni_syscall }, +/* 246 */ { .entry = &syscall_ni_syscall }, +/* 247 */ { .entry = &syscall_ni_syscall }, +/* 248 */ { .entry = &syscall_ni_syscall }, +/* 249 */ { .entry = &syscall_ni_syscall }, +/* 250 */ { .entry = &syscall_ni_syscall }, +/* 251 */ { .entry = &syscall_ni_syscall }, +/* 252 */ { .entry = &syscall_ni_syscall }, +/* 253 */ { .entry = &syscall_ni_syscall }, +/* 254 */ { .entry = &syscall_ni_syscall }, +/* 255 */ { .entry = &syscall_ni_syscall }, +/* 256 */ { .entry = &syscall_ni_syscall }, +/* 257 */ { .entry = &syscall_ni_syscall }, +/* 258 */ { .entry = &syscall_ni_syscall }, +/* 259 */ { .entry = &syscall_ni_syscall }, +/* 260 */ { .entry = &syscall_wait4 }, +/* 261 */ { .entry = &syscall_prlimit64 }, +/* 262 */ { .entry = &syscall_fanotify_init }, +/* 263 */ { .entry = &syscall_fanotify_mark }, +/* 264 */ { .entry = &syscall_name_to_handle_at }, +/* 265 */ { .entry = &syscall_open_by_handle_at }, +/* 266 */ { .entry = &syscall_clock_adjtime }, +/* 267 */ { .entry = &syscall_syncfs }, +/* 268 */ { .entry = &syscall_setns }, +/* 269 */ { .entry = &syscall_sendmmsg }, +/* 270 */ { .entry = &syscall_process_vm_readv }, +/* 271 */ { .entry = &syscall_process_vm_writev }, +/* 272 */ { .entry = &syscall_kcmp }, +/* 273 */ { .entry = &syscall_finit_module }, +/* 274 */ { .entry = &syscall_sched_setattr }, +/* 275 */ { .entry = &syscall_sched_getattr }, +/* 276 */ { .entry = &syscall_renameat2 }, +/* 277 */ { .entry = &syscall_seccomp }, +/* 278 */ { .entry = &syscall_getrandom }, +/* 279 */ { .entry = &syscall_memfd_create }, +#ifdef USE_BPF +/* 280 */ { .entry = &syscall_bpf }, +#else + { .entry = NULL }, +#endif +/* 281 */ { .entry = &syscall_execveat }, +/* 282 */ { .entry = &syscall_userfaultfd }, +/* 283 */ { .entry = &syscall_membarrier }, +/* 284 */ { .entry = &syscall_mlock2 }, +/* 285 */ { .entry = &syscall_copy_file_range }, +/* 286 */ { .entry = &syscall_preadv2 }, +/* 287 */ { .entry = &syscall_pwritev2 }, +/* 288 */ { .entry = &syscall_pkey_mprotect }, +/* 289 */ { .entry = &syscall_pkey_alloc }, +/* 290 */ { .entry = &syscall_pkey_free }, +/* 291 */ { .entry = &syscall_statx }, +/* 292 */ { .entry = &syscall_io_pgetevents }, +/* 293 */ { .entry = &syscall_rseq }, +/* 294 */ { .entry = &syscall_kexec_file_load }, +/* 295 */ { .entry = NULL }, +/* 296 */ { .entry = NULL }, +/* 297 */ { .entry = NULL }, +/* 298 */ { .entry = NULL }, +/* 299 */ { .entry = NULL }, +/* 300 */ { .entry = NULL }, +/* 301 */ { .entry = NULL }, +/* 302 */ { .entry = NULL }, +/* 303 */ { .entry = NULL }, +/* 304 */ { .entry = NULL }, +/* 305 */ { .entry = NULL }, +/* 306 */ { .entry = NULL }, +/* 307 */ { .entry = NULL }, +/* 308 */ { .entry = NULL }, +/* 309 */ { .entry = NULL }, +/* 310 */ { .entry = NULL }, +/* 311 */ { .entry = NULL }, +/* 312 */ { .entry = NULL }, +/* 313 */ { .entry = NULL }, +/* 314 */ { .entry = NULL }, +/* 315 */ { .entry = NULL }, +/* 316 */ { .entry = NULL }, +/* 317 */ { .entry = NULL }, +/* 318 */ { .entry = NULL }, +/* 319 */ { .entry = NULL }, +/* 320 */ { .entry = NULL }, +/* 321 */ { .entry = NULL }, +/* 322 */ { .entry = NULL }, +/* 323 */ { .entry = NULL }, +/* 324 */ { .entry = NULL }, +/* 325 */ { .entry = NULL }, +/* 326 */ { .entry = NULL }, +/* 327 */ { .entry = NULL }, +/* 328 */ { .entry = NULL }, +/* 329 */ { .entry = NULL }, +/* 330 */ { .entry = NULL }, +/* 331 */ { .entry = NULL }, +/* 332 */ { .entry = NULL }, +/* 333 */ { .entry = NULL }, +/* 334 */ { .entry = NULL }, +/* 335 */ { .entry = NULL }, +/* 336 */ { .entry = NULL }, +/* 337 */ { .entry = NULL }, +/* 338 */ { .entry = NULL }, +/* 339 */ { .entry = NULL }, +/* 340 */ { .entry = NULL }, +/* 341 */ { .entry = NULL }, +/* 342 */ { .entry = NULL }, +/* 343 */ { .entry = NULL }, +/* 344 */ { .entry = NULL }, +/* 345 */ { .entry = NULL }, +/* 346 */ { .entry = NULL }, +/* 347 */ { .entry = NULL }, +/* 348 */ { .entry = NULL }, +/* 349 */ { .entry = NULL }, +/* 350 */ { .entry = NULL }, +/* 351 */ { .entry = NULL }, +/* 352 */ { .entry = NULL }, +/* 353 */ { .entry = NULL }, +/* 354 */ { .entry = NULL }, +/* 355 */ { .entry = NULL }, +/* 356 */ { .entry = NULL }, +/* 357 */ { .entry = NULL }, +/* 358 */ { .entry = NULL }, +/* 359 */ { .entry = NULL }, +/* 360 */ { .entry = NULL }, +/* 361 */ { .entry = NULL }, +/* 362 */ { .entry = NULL }, +/* 363 */ { .entry = NULL }, +/* 364 */ { .entry = NULL }, +/* 365 */ { .entry = NULL }, +/* 366 */ { .entry = NULL }, +/* 367 */ { .entry = NULL }, +/* 368 */ { .entry = NULL }, +/* 369 */ { .entry = NULL }, +/* 370 */ { .entry = NULL }, +/* 371 */ { .entry = NULL }, +/* 372 */ { .entry = NULL }, +/* 373 */ { .entry = NULL }, +/* 374 */ { .entry = NULL }, +/* 375 */ { .entry = NULL }, +/* 376 */ { .entry = NULL }, +/* 377 */ { .entry = NULL }, +/* 378 */ { .entry = NULL }, +/* 379 */ { .entry = NULL }, +/* 380 */ { .entry = NULL }, +/* 381 */ { .entry = NULL }, +/* 382 */ { .entry = NULL }, +/* 383 */ { .entry = NULL }, +/* 384 */ { .entry = NULL }, +/* 385 */ { .entry = NULL }, +/* 386 */ { .entry = NULL }, +/* 387 */ { .entry = NULL }, +/* 388 */ { .entry = NULL }, +/* 389 */ { .entry = NULL }, +/* 390 */ { .entry = NULL }, +/* 391 */ { .entry = NULL }, +/* 392 */ { .entry = NULL }, +/* 393 */ { .entry = NULL }, +/* 394 */ { .entry = NULL }, +/* 395 */ { .entry = NULL }, +/* 396 */ { .entry = NULL }, +/* 397 */ { .entry = NULL }, +/* 398 */ { .entry = NULL }, +/* 399 */ { .entry = NULL }, +/* 400 */ { .entry = NULL }, +/* 401 */ { .entry = NULL }, +/* 402 */ { .entry = NULL }, +/* 403 */ { .entry = NULL }, +/* 404 */ { .entry = NULL }, +/* 405 */ { .entry = NULL }, +/* 406 */ { .entry = NULL }, +/* 407 */ { .entry = NULL }, +/* 408 */ { .entry = NULL }, +/* 409 */ { .entry = NULL }, +/* 410 */ { .entry = NULL }, +/* 411 */ { .entry = NULL }, +/* 412 */ { .entry = NULL }, +/* 413 */ { .entry = NULL }, +/* 414 */ { .entry = NULL }, +/* 415 */ { .entry = NULL }, +/* 416 */ { .entry = NULL }, +/* 417 */ { .entry = NULL }, +/* 418 */ { .entry = NULL }, +/* 419 */ { .entry = NULL }, +/* 420 */ { .entry = NULL }, +/* 421 */ { .entry = NULL }, +/* 422 */ { .entry = NULL }, +/* 423 */ { .entry = NULL }, +/* 424 */ { .entry = &syscall_pidfd_send_signal }, +/* 425 */ { .entry = &syscall_io_uring_setup }, +/* 426 */ { .entry = &syscall_io_uring_enter }, +/* 427 */ { .entry = &syscall_io_uring_register }, +/* 428 */ { .entry = &syscall_open_tree }, +/* 429 */ { .entry = &syscall_move_mount }, +/* 430 */ { .entry = &syscall_fsopen }, +/* 431 */ { .entry = &syscall_fsconfig }, +/* 432 */ { .entry = &syscall_fsmount }, +/* 433 */ { .entry = &syscall_fspick }, +/* 434 */ { .entry = &syscall_pidfd_open }, +/* 435 */ { .entry = &syscall_clone3 }, +/* 436 */ { .entry = &syscall_close_range }, +/* 437 */ { .entry = &syscall_openat2 }, +/* 438 */ { .entry = &syscall_pidfd_getfd }, +/* 439 */ { .entry = &syscall_faccessat2 }, +/* 440 */ { .entry = &syscall_process_madvise }, +}; + diff --git a/include/syscalls-loongarch.h b/include/syscalls-loongarch.h new file mode 100644 index 000000000..e91eed8d1 --- /dev/null +++ b/include/syscalls-loongarch.h @@ -0,0 +1,4 @@ +#include "syscall.h" +#include "syscalls/syscalls.h" + +#include "syscalls-loongarch-64.h" diff --git a/ioctls/autofs.c b/ioctls/autofs.c index 03eacaaeb..dafcbe898 100644 --- a/ioctls/autofs.c +++ b/ioctls/autofs.c @@ -294,6 +294,7 @@ static void autofs_sanitise(const struct ioctl_group *grp, struct syscallrecord case AUTOFS_DEV_IOCTL_EXPIRE: case AUTOFS_DEV_IOCTL_ASKUMOUNT: case AUTOFS_DEV_IOCTL_ISMOUNTPOINT: + rec->a3 = (unsigned long) get_writable_address(sizeof(struct autofs_dev_ioctl)); arg = (struct autofs_dev_ioctl *) rec->a3; init_autofs_dev_ioctl(arg); arg->ioctlfd = get_random_fd(); diff --git a/ioctls/scsi.c b/ioctls/scsi.c index e20c7149f..e3349ddca 100644 --- a/ioctls/scsi.c +++ b/ioctls/scsi.c @@ -80,7 +80,7 @@ static void scsi_sg_io_sanitise(struct syscallrecord *rec) { struct sgio *sgio; - sgio = (struct sgio *) get_address(); + sgio = (struct sgio *) get_writable_address(sizeof(struct sgio)); sgio->cmd[0] = 0x12; sgio->cmd[3] = 0x2; diff --git a/syscalls/vmsplice.c b/syscalls/vmsplice.c index 14706992b..2d8a865f3 100644 --- a/syscalls/vmsplice.c +++ b/syscalls/vmsplice.c @@ -17,8 +17,6 @@ static void sanitise_vmsplice(struct syscallrecord *rec) { if ((rnd() % 10) > 0) rec->a1 = get_rand_pipe_fd(); - - rec->a3 = rnd() % UIO_MAXIOV; } static unsigned long vmsplice_flags[] = { diff --git a/sysv-shm.c b/sysv-shm.c index 57bc56c9d..98e0d7f3e 100644 --- a/sysv-shm.c +++ b/sysv-shm.c @@ -48,7 +48,7 @@ void create_sysv_shms(void) size = page_size * (1 + rnd() % 10); - id = shmget(IPC_PRIVATE, page_size, flags); + id = shmget(IPC_PRIVATE, size, flags); if (id == -1) { free(obj); continue; @@ -57,10 +57,9 @@ void create_sysv_shms(void) obj->sysv_shm.flags = flags; obj->sysv_shm.size = size; - add_object(obj, OBJ_GLOBAL, OBJ_SYSV_SHM); - p = shmat(id, NULL, 0); // TODO: Try alternative flags. if (p != (void *) -1) obj->sysv_shm.ptr = p; + add_object(obj, OBJ_GLOBAL, OBJ_SYSV_SHM); } }