diff --git a/Documentation/TODO b/Documentation/TODO index 9b64e70f9..908fbe6d2 100644 --- a/Documentation/TODO +++ b/Documentation/TODO @@ -1,3 +1,57 @@ +* 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. + - 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. + - 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. + : 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 +64,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 +129,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,12 +207,14 @@ - 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) -* --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 @@ -80,15 +233,36 @@ 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. + - 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 +282,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 +314,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 +342,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 +360,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 +372,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 ----+ + } + diff --git a/Makefile b/Makefile index 32d092865..88520a91b 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,4 @@ -VERSION="1.8pre" - -ifeq (,$(findstring pre,$(VERSION))) -DEVEL = 0 -else -DEVEL = 1 -endif +VERSION="2023.01" INSTALL_PREFIX ?= $(DESTDIR) INSTALL_PREFIX ?= $(HOME) @@ -22,19 +16,10 @@ 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 #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 @@ -46,6 +31,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 @@ -57,9 +44,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. @@ -87,6 +71,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 @@ -94,7 +79,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) \ @@ -104,7 +88,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..22756d6d3 100644 --- a/child.c +++ b/child.c @@ -27,59 +27,8 @@ #include "tables.h" #include "trinity.h" // ARRAY_SIZE #include "uid.h" -#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 @@ -233,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. */ @@ -251,8 +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); + } - log_child_spawned(pid, childno); + mprotect(pids, max_children * sizeof(int), PROT_READ); /* Wait for parent to set our childno */ while (pids[childno] != pid) { @@ -438,36 +382,12 @@ 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; } -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 +397,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 +412,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 +421,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/configure b/configure index dc0a87d8c..bbaf9afce 100755 --- a/configure +++ b/configure @@ -288,14 +288,42 @@ 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 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 +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/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..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, &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..98ca3f2b9 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); @@ -32,13 +30,7 @@ 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); - - init_msgobjhdr(&objmsg.hdr, OBJ_CREATED_DRM, global, obj); - objmsg.fd = obj->drmfd; - sendudp((char *) &objmsg, sizeof(objmsg)); + output(2, "drmfd:%d global:%d\n", obj->drmfd, global); } 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 210678e45..3c47620f7 100644 --- a/fds/memfd.c +++ b/fds/memfd.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "fd.h" #include "memfd.h" @@ -14,8 +15,10 @@ #include "shm.h" #include "compat.h" #include "trinity.h" -#include "udp.h" +#ifndef USE_MEMFD_CREATE + +#ifndef memfd_create static int memfd_create(__unused__ const char *uname, __unused__ unsigned int flag) { #ifdef SYS_memfd_create @@ -24,6 +27,8 @@ static int memfd_create(__unused__ const char *uname, __unused__ unsigned int fl return -ENOSYS; #endif } +#endif +#endif static void memfd_destructor(struct object *obj) { @@ -34,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); - strncpy(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) @@ -55,7 +52,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/fds/perf.c b/fds/perf.c index 290fb6332..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_event_attr:"); +// unsigned int i; + + 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 3619f9dd4..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" @@ -47,7 +46,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 { @@ -249,7 +248,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; } @@ -279,7 +278,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; @@ -365,7 +364,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: @@ -399,7 +399,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, @@ -409,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:%d 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) @@ -437,7 +430,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; } @@ -491,7 +484,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/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/ftrace.c b/ftrace.c index 84a754b99..6a7c80fcf 100644 --- a/ftrace.c +++ b/ftrace.c @@ -53,13 +53,14 @@ static void dump_trace(void) output(0, "Dumped trace to %s\n", ftracedumpname); fail: fsync(traceout); - close(tracein); - -fail_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); } } 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-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/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..5a933175a 100644 --- a/include/arch-syscalls.h +++ b/include/arch-syscalls.h @@ -43,3 +43,13 @@ #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 +#ifdef __loongarch__ +#include "syscalls-loongarch.h" +#endif diff --git a/include/arch.h b/include/arch.h index a641e5bbd..348b5671c 100644 --- a/include/arch.h +++ b/include/arch.h @@ -54,6 +54,18 @@ #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 + +#ifdef __loongarch__ +#include "arch-loongarch.h" +#endif + #ifndef SYSCALL_OFFSET #define SYSCALL_OFFSET 0 #endif diff --git a/include/child.h b/include/child.h index a6d315aa0..3fc09f00d 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; @@ -61,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/compat.h b/include/compat.h index a7e99b903..377e99d39 100644 --- a/include/compat.h +++ b/include/compat.h @@ -138,6 +138,18 @@ 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 +#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 */ @@ -235,6 +247,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 @@ -250,6 +266,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 @@ -362,6 +382,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 @@ -525,8 +562,51 @@ enum kcmp_type { #define SO_PEERGROUPS 59 #endif +#ifndef SO_ZEROCOPY +#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 + +#ifndef SO_DETACH_REUSEPORT_BPF +#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 +#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 @@ -598,6 +678,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 @@ -724,6 +824,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 @@ -1174,6 +1279,15 @@ struct kvm_get_htab_fd { #define POLL_BUSY_LOOP 0x8000 #endif +/* asm/mman.h */ +#ifndef MLOCK_ONFAULT +#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) @@ -1193,7 +1307,20 @@ struct kvm_get_htab_fd { # define SHM_NORESERVE 010000 #endif -/* netfilter/ipset/ipset.h */ -#ifndef SO_IP_SET -#define SO_IP_SET 83 +/* 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 + +/* 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/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); 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"; 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/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); 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. diff --git a/include/net.h b/include/net.h index 6a535be21..791e80900 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) @@ -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; @@ -99,6 +98,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/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/include/syscalls-i386.h b/include/syscalls-i386.h index cfb5cd56a..ce8e211ec 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,65 @@ struct syscalltable syscalls_i386[] = { { .entry = &syscall_pkey_mprotect }, { .entry = &syscall_pkey_alloc }, { .entry = &syscall_pkey_free }, + { .entry = &syscall_statx }, + { .entry = NULL }, /* we don't care about 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 }, + { .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/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/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/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/include/syscalls-s390.h b/include/syscalls-s390.h index 9916e6c6e..077066509 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_oldreaddir }, { .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_runtime_instr }, /* s390_runtime_instr svc */ { .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_s390_pci_mmio_write }, + { .entry = &syscall_s390_pci_mmio_read }, { .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_mlock2 }, + { .entry = &syscall_copy_file_range }, + { .entry = &syscall_preadv2 }, + { .entry = &syscall_pwritev2 }, + { .entry = &syscall_s390_guarded_storage }, + { .entry = &syscall_statx }, + { .entry = &syscall_s390_sthyi }, }; diff --git a/include/syscalls-s390x.h b/include/syscalls-s390x.h index 6dbaffb37..66f3bc566 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 }, @@ -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 }, @@ -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_s390_pci_mmio_write }, + { .entry = &syscall_s390_pci_mmio_read }, { .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_mlock2 }, + { .entry = &syscall_copy_file_range }, + { .entry = &syscall_preadv2 }, + { .entry = &syscall_pwritev2 }, + { .entry = &syscall_s390_guarded_storage }, + { .entry = &syscall_statx }, + { .entry = &syscall_s390_sthyi }, }; diff --git a/include/syscalls-x86_64.h b/include/syscalls-x86_64.h index e225492ca..2b7bf7d9f 100644 --- a/include/syscalls-x86_64.h +++ b/include/syscalls-x86_64.h @@ -344,4 +344,122 @@ struct syscalltable syscalls_x86_64[] = { { .entry = &syscall_pkey_alloc }, { .entry = &syscall_pkey_free }, { .entry = &syscall_statx }, + { .entry = &syscall_io_pgetevents }, + { .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 + { .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 }, + { .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/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/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/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/ioctls/autofs.c b/ioctls/autofs.c index 04a3eb811..dafcbe898 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 */ /* @@ -238,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), @@ -286,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/drm.c b/ioctls/drm.c index 81ed36824..d938f7075 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), @@ -392,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), @@ -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), 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), 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/ioctls/sgx.c b/ioctls/sgx.c new file mode 100644 index 000000000..1fd09b368 --- /dev/null +++ b/ioctls/sgx.c @@ -0,0 +1,113 @@ +/* + * 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 +#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) + +/* 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) + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpacked" +/** + * 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__)); + + +/* SGXv2 */ +struct sgx_range { + unsigned long start_addr; + unsigned int nr_pages; +}; + +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), + 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[] = { + "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) 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), 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); 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 old mode 100644 new mode 100755 index 9cbd56799..64c6bc0d9 --- a/main.c +++ b/main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -22,7 +23,7 @@ #include "tables.h" #include "taint.h" #include "trinity.h" -#include "udp.h" +#include "utils.h" static void handle_child(int childno, pid_t childpid, int childstatus); @@ -38,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); @@ -300,9 +305,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 +405,8 @@ 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", - 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); @@ -466,6 +468,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++; @@ -511,17 +520,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; @@ -563,11 +561,10 @@ 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]); - - fclose(child->pidstatfile); + if (child->pidstatfile) + fclose(child->pidstatfile); child->pidstatfile = NULL; replace_child(childno); @@ -587,16 +584,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) { @@ -611,10 +598,8 @@ 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 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); @@ -707,7 +692,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, @@ -733,38 +718,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) { @@ -783,7 +738,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); } @@ -834,7 +789,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 c237c0006..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); - strncpy(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/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) 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-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" 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/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/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; 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) { 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 = { 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/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), +}; diff --git a/net/protocols.c b/net/protocols.c index 90a60affe..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 }, @@ -26,7 +25,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 }, @@ -55,4 +56,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 }, }; 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/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); 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/pathnames.c b/pathnames.c index 2d5180ad5..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; @@ -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; } } 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/childops/random-syscall.c b/random-syscall.c similarity index 100% rename from childops/random-syscall.c rename to random-syscall.c diff --git a/scripts/hashcheck.sh b/scripts/hashcheck.sh new file mode 100755 index 000000000..d82074bbe --- /dev/null +++ b/scripts/hashcheck.sh @@ -0,0 +1,92 @@ +#!/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 +# 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 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 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_ +#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 e32fa013c2d914164d2a70ecabb3f23563b59de8 SO_ +check include/uapi/linux/tcp.h 149a6ee4bb5bb81fd8d44923c5846f85b7130d5e \#define\ TCP_ +check include/uapi/linux/in.h 0116e6878df350e74ec730fd9f455efb95e510c8 \#define\ IP_ + +# Check for new packet families +check include/linux/socket.h 52069f49a4646e9692c6b3186172fbd1fa681dcf SOL_ +check include/linux/socket.h 02ead19934fd61e127ccfb46445afea2caed4ece AF_ + +# MSG_ flags +check include/linux/socket.h 94a5669653d7098b8c4a4391aeabb593b5940486 \ MSG_ + +# new netlink protos +check include/uapi/linux/netlink.h 97cad03cf941de83421ddcfc5178af06a05cea50 "#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 fdfd95258ab07c7377584912890dd286beae4f9f MADV_ + +# new mremap flags +check include/uapi/linux/mman.h 3465560bc9439e3edabb652ce31d6a0d0e1aa400 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 2b3c44c13ff4df4b9062898f6bb5a3323283ab7d 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 + 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 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 79f5e7535..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 = -lpthread - -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/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); diff --git a/syscall.c b/syscall.c index 3d6f3d728..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" @@ -167,6 +166,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; @@ -183,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; @@ -251,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; @@ -278,7 +255,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++; } 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/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/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/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/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/futex.c b/syscalls/futex.c index c4301057c..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: %lx 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/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/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/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..0d739a99f --- /dev/null +++ b/syscalls/io_uring_register.c @@ -0,0 +1,48 @@ +/* + * 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 +#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 +#define IORING_REGISTER_RESTRICTIONS 11 +#define IORING_REGISTER_ENABLE_RINGS 12 + + +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, + IORING_REGISTER_FILES_UPDATE, + IORING_REGISTER_EVENTFD_ASYNC, + IORING_REGISTER_PROBE, + IORING_REGISTER_PERSONALITY, + IORING_UNREGISTER_PERSONALITY, + IORING_REGISTER_RESTRICTIONS, + IORING_REGISTER_ENABLE_RINGS, +}; + +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/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/madvise.c b/syscalls/madvise.c index 61e574382..9cb12f134 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, MADV_COLD, MADV_PAGEOUT, }; struct syscallentry syscall_madvise = { @@ -35,3 +36,28 @@ struct syscallentry syscall_madvise = { .group = GROUP_VM, .sanitise = sanitise_madvise, }; + +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/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/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, 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, }; 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/move_mount.c b/syscalls/move_mount.c new file mode 100644 index 000000000..1ac8bc7c8 --- /dev/null +++ b/syscalls/move_mount.c @@ -0,0 +1,27 @@ +/* + * SYSCALL_DEFINE5(move_mount, int, from_dfd, const char *, from_pathname, + * int, to_dfd, const char *, to_pathname, unsigned int, flags) + */ +#include "sanitise.h" +#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, + 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/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 = { 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) { 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/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/perf_event_open.c b/syscalls/perf_event_open.c index 6cecee882..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< + +#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/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/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/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 = { 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/setsockopt.c b/syscalls/setsockopt.c index 3653ad639..2ac345646 100644 --- a/syscalls/setsockopt.c +++ b/syscalls/setsockopt.c @@ -25,7 +25,11 @@ 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, + 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) @@ -90,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) { diff --git a/syscalls/syscalls.h b/syscalls/syscalls.h index 38819b378..cfa59a6a8 100644 --- a/syscalls/syscalls.h +++ b/syscalls/syscalls.h @@ -386,5 +386,42 @@ 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_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_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_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_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_futex_waitv; +extern struct syscallentry syscall_set_mempolicy_home_node; + +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; + +extern struct syscallentry syscall_riscv_flush_icache; unsigned int random_fcntl_setfl_flags(void); diff --git a/syscalls/timer_create.c b/syscalls/timer_create.c index 1bd0ee7f6..095cbedfb 100644 --- a/syscalls/timer_create.c +++ b/syscalls/timer_create.c @@ -3,7 +3,31 @@ 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; + + if (RAND_BOOL()) { + int signo; + + 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 +37,5 @@ struct syscallentry syscall_timer_create = { .arg2type = ARG_ADDRESS, .arg3name = "create_timer_id", .arg3type = ARG_ADDRESS, + .sanitise = timer_create_sanitise, }; 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/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" diff --git a/sysv-shm.c b/sysv-shm.c index 9accd7c52..98e0d7f3e 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:%d 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) @@ -58,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; @@ -67,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); } } 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..60c03b8be 100644 --- a/trinity.c +++ b/trinity.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,6 @@ #include "tables.h" #include "taint.h" #include "trinity.h" -#include "udp.h" #include "uid.h" #include "version.h" @@ -37,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 @@ -108,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/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); -} 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; +}