-
-
Save simran-kathpalia/9b71ccffecb6fce7d5109b92db4d8f8d to your computer and use it in GitHub Desktop.
Code prints out the missing FreeBSD syscalls in syzkaller.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
import re | |
import sys | |
import os | |
syzcalls = {0: "syscall",1: "exit",2: "fork",3: "read",4: "write",5: "open",6: "close",7: "wait4",8: "link",9: "unlink",10: "chdir",11: "fchdir",12: "freebsd11_mknod",13: "chmod",14: "chown",15: "break",16: "getpid",17: "mount",18: "unmount",19: "setuid",20: "getuid",21: "geteuid",22: "ptrace",23: "recvmsg",24: "sendmsg",25: "recvfrom",26: "accept",27: "getpeername",28: "getsockname",29: "access",30: "chflags",31: "fchflags",32: "sync",33: "kill",34: "getppid",35: "dup",36: "freebsd10_pipe",37: "getegid",38: "profil",39: "ktrace",40: "getgid",41: "getlogin",42: "setlogin",43: "acct",44: "sigaltstack",45: "ioctl",46: "reboot",47: "revoke",48: "symlink",49: "readlink",50: "execve",51: "umask",52: "chroot",53: "msync",54: "vfork",55: "sbrk",56: "sstk",57: "freebsd11_vadvi72",58: "munmap",59: "mprotect",60: "madvise",61: "mincore",62: "getgroups",63: "setgroups",64: "getpgrp",65: "setpgid",66: "setitimer",67: "swapon",68: "getitimer",69: "getdtablesize",70: "dup2",71: "fcntl",72: "select",73: "fsync",74: "setpriority",75: "socket",76: "connect",77: "getpriority",78: "bind",79: "setsockopt",80: "listen",81: "gettimeofday",82: "getrusage",83: "getsockopt",84: "readv",85: "writev",86: "settimeofday",87: "fchown",88: "fchmod",89: "setreuid",90: "setregid",91: "rename",92: "flock",93: "mkfifo",94: "sendto",95: "shutdown",96: "socketpair",97: "mkdir",98: "rmdir",99: "utimes",100: "adjtime",101: "setsid",102: "quotactl",103: "nlm_syscall",104: "nfssvc",105: "lgetfh",106: "getfh",107: "sysarch",108: "rtprio",109: "semsys",110: "msgsys",111: "shmsys",112: "setfib",113: "ntp_adjtime",114: "setgid",115: "setegid",116: "seteuid",117: "freebsd11_stat",118: "freebsd11_fstat",119: "freebsd11_lstat",120: "pathconf",121: "fpathconf",122: "getrlimit",123: "setrlimit",124: "freebsd11_getdirentries",125: "__syscall",126: "__sysctl",127: "mlock",128: "munlock",129: "undelete",130: "futimes",131: "getpgid",132: "poll",133: "freebsd7___semctl",134: "semget",135: "semop",136: "freebsd7_msgctl",137: "msgget",138: "msgsnd",139: "msgrcv",140: "shmat",141: "freebsd7_shmctl",142: "shmdt",143: "shmget",144: "clock_gettime",145: "clock_settime",146: "clock_getres",147: "ktimer_create",148: "ktimer_delete",149: "ktimer_settime",150: "ktimer_gettime",151: "ktimer_getoverrun",152: "nanosleep",153: "ffclock_getcounter",154: "ffclock_setestimate",155: "ffclock_getestimate",156: "clock_nanosleep",157: "clock_getcpuclockid2",158: "ntp_gettime",159: "minherit",160: "rfork",161: "issetugid",162: "lchown",163: "aio_read",164: "aio_write",165: "lio_listio",166: "freebsd11_getdents",167: "lchmod",168: "lutimes",169: "freebsd11_nstat",170: "freebsd11_nfstat",171: "freebsd11_nlstat",172: "preadv",173: "pwritev",174: "fhopen",175: "freebsd11_fhstat",176: "modnext",177: "modstat",178: "modfnext",179: "modfind",180: "kldload",181: "kldunload",182: "kldfind",183: "kldnext",184: "kldstat",185: "kldfirstmod",186: "getsid",187: "setresuid",188: "setresgid",189: "aio_return",190: "aio_suspend",191: "aio_cancel",192: "aio_error",193: "yield",194: "mlockall",195: "munlockall",196: "__getcwd",197: "sched_setparam",198: "sched_getparam",199: "sched_setscheduler",200: "sched_getscheduler",201: "sched_yield",202: "sched_get_priority_max",203: "sched_get_priority_min",204: "sched_rr_get_interval",205: "utrace",206: "kldsym",207: "jail",208: "nnpfs_syscall",209: "sigprocmask",210: "sigsuspend",211: "sigpending",212: "sigtimedwait",213: "sigwaitinfo",214: "__acl_get_file",215: "__acl_set_file",216: "__acl_get_fd",217: "__acl_set_fd",218: "__acl_delete_file",219: "__acl_delete_fd",220: "__acl_aclcheck_file",221: "__acl_aclcheck_fd",222: "extattrctl",223: "extattr_set_file",224: "extattr_get_file",225: "extattr_delete_file",226: "aio_waitcomplete",227: "getresuid",228: "getresgid",229: "kqueue",230: "freebsd11_kevent",231: "extattr_set_fd",232: "extattr_get_fd",233: "extattr_delete_fd",234: "__setugid",235: "eaccess",236: "afs3_syscall",237: "nmount",238: "__mac_get_proc",239: "__mac_set_proc",240: "__mac_get_fd",241: "__mac_get_file",242: "__mac_set_fd",243: "__mac_set_file",244: "kenv",245: "lchflags",246: "uuidgen",247: "sendfile",248: "mac_syscall",249: "freebsd11_getfsstat",250: "freebsd11_statfs",251: "freebsd11_fstatfs",252: "freebsd11_fhstatfs",253: "ksem_close",254: "ksem_post",255: "ksem_wait",256: "ksem_trywait",257: "ksem_init",258: "ksem_open",259: "ksem_unlink",260: "ksem_getvalue",261: "ksem_destroy",262: "__mac_get_pid",263: "__mac_get_link",264: "__mac_set_link",265: "extattr_set_link",266: "extattr_get_link",267: "extattr_delete_link",268: "__mac_execve",269: "sigaction",270: "sigreturn",271: "getcontext",272: "setcontext",273: "swapcontext",274: "swapoff",275: "__acl_get_link",276: "__acl_set_link",277: "__acl_delete_link",278: "__acl_aclcheck_link",279: "sigwait",280: "thr_create",281: "thr_exit",282: "thr_self",283: "thr_kill",284: "jail_attach",285: "extattr_list_fd",286: "extattr_list_file",287: "extattr_list_link",288: "ksem_timedwait",289: "thr_suspend",290: "thr_wake",291: "kldunloadf",292: "audit",293: "auditon",294: "getauid",295: "setauid",296: "getaudit",297: "setaudit",298: "getaudit_addr",299: "setaudit_addr",300: "auditctl",301: "_umtx_op",302: "thr_new",303: "sigqueue",304: "kmq_open",305: "kmq_setattr",306: "kmq_timedreceive",307: "kmq_timedsend",308: "kmq_notify",309: "kmq_unlink",310: "abort2",311: "thr_set_name",312: "aio_fsync",313: "rtprio_thread",314: "sctp_peeloff",315: "sctp_generic_sendmsg",316: "sctp_generic_sendmsg_io",317: "sctp_generic_recvmsg",318: "pread",319: "pwrite",320: "mmap",321: "lseek",322: "truncate",323: "ftruncate",324: "thr_kill2",325: "freebsd12_shm_open",326: "shm_unlink",327: "cpuset",328: "cpuset_setid",329: "cpuset_getid",330: "cpuset_getaffinity",331: "cpuset_setaffinity",332: "faccessat",333: "fchmodat",334: "fchownat",335: "fexecve",336: "freebsd11_fstatat",337: "futimesat",338: "linkat",339: "mkdirat",340: "mkfifoat",341: "freebsd11_mknodat",342: "openat",343: "readlinkat",344: "renameat",345: "symlinkat",346: "unlinkat",347: "posix_openpt",348: "gssd_syscall",349: "jail_get",350: "jail_set",351: "jail_remove",352: "freebsd12_closefrom",353: "__semctl",354: "msgctl",355: "shmctl",356: "lpathconf",357: "__cap_rights_get",358: "cap_enter",359: "cap_getmode",360: "pdfork",361: "pdkill",362: "pdgetpid",363: "pselect",364: "getloginclass",365: "setloginclass",366: "rctl_get_racct",367: "rctl_get_rules",368: "rctl_get_limits",369: "rctl_add_rule",370: "rctl_remove_rule",371: "posix_fallocate",372: "posix_fadvise",373: "wait6",374: "cap_rights_limit",375: "cap_ioctls_limit",376: "cap_ioctls_get",377: "cap_fcntls_limit",378: "cap_fcntls_get",379: "bindat",380: "connectat",381: "chflagsat",382: "accept4",383: "pipe2",384: "aio_mlock",385: "procctl",386: "ppoll",387: "futimens",388: "utimensat",389: "fdatasync",390: "fstat",391: "fstatat",392: "fhstat",393: "getdirentries",394: "statfs",395: "fstatfs",396: "getfsstat",397: "fhstatfs",398: "mknodat",399: "kevent",400: "cpuset_getdomain",401: "cpuset_setdomain",402: "getrandom",403: "getfhat",404: "fhlink",405: "fhlinkat",406: "fhreadlink",407: "funlinkat",408: "copy_file_range",409: "__sysctlbyname",410: "shm_open2",411: "shm_rename",412: "sigfastblock",413: "__realpathat",414: "close_range",415: "rpctls_syscall",416: "MAXSYSCALL"} | |
listed_syscalls = [] | |
listed_syscalls_names = {} | |
unmatched_functions = [] | |
missing_syscalls = {} | |
def usage(): | |
print "USAGE: python missing.py <option>" | |
print "\t -syz <path to sys/freebsd>: Syzkaller checker" | |
def syzkaller_check(path): | |
for filename in os.listdir(path): | |
if filename.endswith(".txt"): | |
content = open(os.path.join(path, filename)).readlines() | |
syzkaller_file_parser(content) | |
find_missing_syscalls() | |
print_syscalls() | |
def syzkaller_file_parser(content): | |
syz = re.compile("(.*?)\(.*\).*") | |
for line in content: | |
if syz.match(line): | |
flag = 0 | |
for syscallno, syscall in syzcalls.items(): | |
if cmp(line.split('(')[0].split('$')[0], syscall) == 0: | |
listed_syscalls.append(syscallno) | |
listed_syscalls_names[syscallno] = syscall | |
flag = 1 | |
if flag == 0: | |
unmatched_functions.append(line) | |
def find_missing_syscalls(): | |
ctr = 0 | |
for i in sorted(set(listed_syscalls)): | |
if ctr != i: | |
while ctr != i: | |
if syzcalls.has_key(ctr): | |
missing_syscalls[ctr] = syzcalls[ctr] | |
ctr = ctr + 1 | |
ctr = ctr + 1 | |
def print_syscalls(): | |
print "="*50 | |
print "Existing syscalls" | |
print "="*50 | |
for syscallno, syscall in listed_syscalls_names.items(): | |
print "Syscall No " + str(syscallno) + " : " + syscall | |
print "="*50 | |
print "Missing syscalls" | |
print "="*50 | |
for syscallno, syscall in missing_syscalls.items(): | |
print "Syscall No " + str(syscallno) + " : " + syscall | |
print "="*50 | |
print "Unmatched syscalls/functions" | |
print "="*50 | |
for unmatched in set(unmatched_functions): | |
print unmatched.strip() | |
print "="*50 | |
print "Stats" | |
print "="*50 | |
print "[*] No. of syscalls fuzzed : " + str(len(listed_syscalls_names)) | |
print "[*] No. of syscalls not fuzzed : " + str(len(missing_syscalls)) | |
print "[*] Total no. of syscalls : " + str(len(syzcalls)) | |
print "[*] Coverage percentage : " + str((len(listed_syscalls_names)*100)/len(syzcalls)) | |
def main(): | |
if len(sys.argv) < 2: | |
usage() | |
exit() | |
if sys.argv[1] == "-syz": | |
if len(sys.argv) != 3: | |
usage() | |
exit() | |
path = sys.argv[2] | |
syzkaller_check(path) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment