1# Copyright 2017 syzkaller project authors. All rights reserved. 2# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4# TODO: due to autobind a socket can bind to port 0, that will result in a random port which is not reproducible 5 6include <sys/types.h> 7include <sys/socket.h> 8include <sys/sockio.h> 9include <netinet/in.h> 10include <linux/linux.h> 11include <compat/linux/linux_socket.h> 12 13resource sock[fd] 14type sock_port proc[20000, 4, int16be] 15 16# TODO: describe socketcall syscall 17 18socket(domain flags[socket_domain], type flags[socket_type], proto int8) sock 19socketpair(domain flags[socket_domain], type flags[socket_type], proto int8, fds ptr[out, pipefd]) 20bind(fd sock, addr ptr[in, sockaddr_storage], addrlen len[addr]) 21connect(fd sock, addr ptr[in, sockaddr_storage], addrlen len[addr]) 22accept(fd sock, peer ptr[out, sockaddr_storage, opt], peerlen ptr[inout, len[peer, int32]]) sock 23accept4(fd sock, peer ptr[out, sockaddr_storage, opt], peerlen ptr[inout, len[peer, int32]], flags flags[accept_flags]) sock 24sendto(fd sock, buf buffer[in], len len[buf], f flags[send_flags], addr ptr[in, sockaddr_storage, opt], addrlen len[addr]) 25recvfrom(fd sock, buf buffer[out], len len[buf], f flags[recv_flags], addr ptr[in, sockaddr_storage, opt], addrlen len[addr]) 26getsockname(fd sock, addr ptr[out, sockaddr_storage], addrlen ptr[inout, len[addr, int32]]) 27getpeername(fd sock, peer ptr[out, sockaddr_storage], peerlen ptr[inout, len[peer, int32]]) 28 29sendmsg(fd sock, msg ptr[in, send_msghdr], f flags[send_flags]) 30recvmsg(fd sock, msg ptr[in, recv_msghdr], f flags[recv_flags]) 31 32listen(fd sock, backlog int32) 33shutdown(fd sock, how flags[shutdown_flags]) 34 35getsockopt(fd sock, level int32, optname int32, optval buffer[out], optlen ptr[inout, len[optval, int32]]) 36setsockopt(fd sock, level int32, optname int32, optval buffer[in], optlen len[optval]) 37 38socket_domain = AF_UNIX, AF_INET, AF_INET6, AF_IPX, AF_AX25, AF_APPLETALK 39socket_type = SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_NONBLOCK, SOCK_CLOEXEC 40accept_flags = SOCK_NONBLOCK, SOCK_CLOEXEC 41shutdown_flags = SHUT_RD, SHUT_WR 42send_flags = MSG_CONFIRM, MSG_DONTROUTE, MSG_DONTWAIT, MSG_EOR, MSG_NOSIGNAL, MSG_OOB 43recv_flags = MSG_CMSG_CLOEXEC, MSG_DONTWAIT, MSG_ERRQUEUE, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, MSG_WAITFORONE 44cmsg_levels = SOL_SOCKET, IPPROTO_ICMP, SOL_IP, SOL_TCP, LINUX_SOL_UDP, SOL_IPV6, SOL_IPX, SOL_AX25 45 46# This sockaddr type corresponds to the sockaddr_storage type and is 128 bytes size. 47sockaddr_storage [ 48 un sockaddr_un 49 in sockaddr_in 50 in6 sockaddr_in6 51] [varlen] 52 53send_msghdr { 54 msg_name ptr[in, sockaddr_storage, opt] 55 msg_namelen len[msg_name, int32] 56 msg_iov ptr[in, array[iovec_in]] 57 msg_iovlen len[msg_iov, intptr] 58 msg_control ptr[in, array[cmsghdr]] 59 msg_controllen bytesize[msg_control, intptr] 60 msg_flags flags[send_flags, int32] 61} 62 63recv_msghdr { 64 msg_name ptr[out, sockaddr_storage, opt] 65 msg_namelen len[msg_name, int32] 66 msg_iov ptr[in, array[iovec_out]] 67 msg_iovlen len[msg_iov, intptr] 68 msg_control buffer[out] 69 msg_controllen len[msg_control, intptr] 70 msg_flags int32 71} 72 73cmsghdr { 74 cmsg_len len[parent, intptr] 75 cmsg_level flags[cmsg_levels, int32] 76 cmsg_type int32 77 data array[int8] 78} [align_ptr] 79 80# Socket options 81 82getsockopt$sock_int(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_int], optval ptr[out, int32], optlen ptr[inout, len[optval, int32]]) 83setsockopt$sock_int(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_int], optval ptr[in, int32], optlen len[optval]) 84getsockopt$sock_linger(fd sock, level const[SOL_SOCKET], optname const[SO_LINGER], optval ptr[out, linger], optlen ptr[inout, len[optval, int32]]) 85setsockopt$sock_linger(fd sock, level const[SOL_SOCKET], optname const[SO_LINGER], optval ptr[in, linger], optlen len[optval]) 86getsockopt$sock_cred(fd sock, level const[SOL_SOCKET], optname const[SO_PEERCRED], optval ptr[out, ucred], optlen ptr[inout, len[optval, int32]]) 87setsockopt$sock_cred(fd sock, level const[SOL_SOCKET], optname const[SO_PEERCRED], optval ptr[in, ucred], optlen len[optval]) 88getsockopt$sock_timeval(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_timeval], optval ptr[out, timeval], optlen ptr[inout, len[optval, int32]]) 89setsockopt$sock_timeval(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_timeval], optval ptr[in, timeval], optlen len[optval]) 90getsockopt$SO_PEERCRED(fd sock, level const[SOL_SOCKET], optname const[SO_PEERCRED], optval ptr[out, ucred], optlen len[optval]) 91 92sockopt_opt_sock_int = SO_ACCEPTCONN, SO_BROADCAST, SO_DEBUG, SO_ERROR, SO_DONTROUTE, SO_KEEPALIVE, SO_PRIORITY, SO_PROTOCOL, SO_RCVBUF, SO_RCVLOWAT, SO_SNDLOWAT, SO_REUSEADDR, SO_SNDBUF, LINUX_SO_TIMESTAMP, SO_TYPE, SO_REUSEPORT, SO_OOBINLINE, SO_NO_CHECK, SO_PASSCRED 93sockopt_opt_sock_timeval = SO_RCVTIMEO, SO_SNDTIMEO 94