qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

linux-user: Protect more syscalls

New y2038 safe 32-bit architectures (like RISC-V) don't support old
syscalls with a 32-bit time_t. The kernel defines new *_time64 versions
of these syscalls. Add some more #ifdefs to syscall.c in linux-user to
allow us to compile without these old syscalls.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <9ffc3cc6226756895157f16622be5f6edfa2aee6.1584051142.git.alistair.francis@wdc.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>

authored by

Alistair Francis and committed by
Laurent Vivier
859e8a89 aab613fb

+68 -2
+2
linux-user/strace.c
··· 781 781 #define TARGET_TIME_OOP 3 /* leap second in progress */ 782 782 #define TARGET_TIME_WAIT 4 /* leap second has occurred */ 783 783 #define TARGET_TIME_ERROR 5 /* clock not synchronized */ 784 + #ifdef TARGET_NR_adjtimex 784 785 static void 785 786 print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret) 786 787 { ··· 819 820 820 821 qemu_log("\n"); 821 822 } 823 + #endif 822 824 823 825 UNUSED static struct flags access_flags[] = { 824 826 FLAG_GENERIC(F_OK),
+66 -2
linux-user/syscall.c
··· 742 742 safe_syscall3(ssize_t, write, int, fd, const void *, buff, size_t, count) 743 743 safe_syscall4(int, openat, int, dirfd, const char *, pathname, \ 744 744 int, flags, mode_t, mode) 745 + #if defined(TARGET_NR_wait4) || defined(TARGET_NR_waitpid) 745 746 safe_syscall4(pid_t, wait4, pid_t, pid, int *, status, int, options, \ 746 747 struct rusage *, rusage) 748 + #endif 747 749 safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop, \ 748 750 int, options, struct rusage *, rusage) 749 751 safe_syscall3(int, execve, const char *, filename, char **, argv, char **, envp) 752 + #if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \ 753 + defined(TARGET_NR_pselect6) 750 754 safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, \ 751 755 fd_set *, exceptfds, struct timespec *, timeout, void *, sig) 756 + #endif 757 + #if defined(TARGET_NR_ppoll) || defined(TARGET_NR_poll) 752 758 safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds, 753 759 struct timespec *, tsp, const sigset_t *, sigmask, 754 760 size_t, sigsetsize) 761 + #endif 755 762 safe_syscall6(int, epoll_pwait, int, epfd, struct epoll_event *, events, 756 763 int, maxevents, int, timeout, const sigset_t *, sigmask, 757 764 size_t, sigsetsize) 765 + #ifdef TARGET_NR_futex 758 766 safe_syscall6(int,futex,int *,uaddr,int,op,int,val, \ 759 767 const struct timespec *,timeout,int *,uaddr2,int,val3) 768 + #endif 760 769 safe_syscall2(int, rt_sigsuspend, sigset_t *, newset, size_t, sigsetsize) 761 770 safe_syscall2(int, kill, pid_t, pid, int, sig) 762 771 safe_syscall2(int, tkill, int, tid, int, sig) ··· 776 785 safe_syscall3(ssize_t, sendmsg, int, fd, const struct msghdr *, msg, int, flags) 777 786 safe_syscall3(ssize_t, recvmsg, int, fd, struct msghdr *, msg, int, flags) 778 787 safe_syscall2(int, flock, int, fd, int, operation) 788 + #ifdef TARGET_NR_rt_sigtimedwait 779 789 safe_syscall4(int, rt_sigtimedwait, const sigset_t *, these, siginfo_t *, uinfo, 780 790 const struct timespec *, uts, size_t, sigsetsize) 791 + #endif 781 792 safe_syscall4(int, accept4, int, fd, struct sockaddr *, addr, socklen_t *, len, 782 793 int, flags) 794 + #if defined(TARGET_NR_nanosleep) 783 795 safe_syscall2(int, nanosleep, const struct timespec *, req, 784 796 struct timespec *, rem) 797 + #endif 785 798 #ifdef TARGET_NR_clock_nanosleep 786 799 safe_syscall4(int, clock_nanosleep, const clockid_t, clock, int, flags, 787 800 const struct timespec *, req, struct timespec *, rem) ··· 802 815 safe_syscall4(int, semtimedop, int, semid, struct sembuf *, tsops, 803 816 unsigned, nsops, const struct timespec *, timeout) 804 817 #endif 805 - #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open) 818 + #ifdef TARGET_NR_mq_timedsend 806 819 safe_syscall5(int, mq_timedsend, int, mqdes, const char *, msg_ptr, 807 820 size_t, len, unsigned, prio, const struct timespec *, timeout) 821 + #endif 822 + #ifdef TARGET_NR_mq_timedreceive 808 823 safe_syscall5(int, mq_timedreceive, int, mqdes, char *, msg_ptr, 809 824 size_t, len, unsigned *, prio, const struct timespec *, timeout) 810 825 #endif ··· 946 961 return target_brk; 947 962 } 948 963 964 + #if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \ 965 + defined(TARGET_NR_pselect6) 949 966 static inline abi_long copy_from_user_fdset(fd_set *fds, 950 967 abi_ulong target_fds_addr, 951 968 int n) ··· 1021 1038 1022 1039 return 0; 1023 1040 } 1041 + #endif 1024 1042 1025 1043 #if defined(__alpha__) 1026 1044 #define HOST_HZ 1024 ··· 1067 1085 return 0; 1068 1086 } 1069 1087 1088 + #ifdef TARGET_NR_setrlimit 1070 1089 static inline rlim_t target_to_host_rlim(abi_ulong target_rlim) 1071 1090 { 1072 1091 abi_ulong target_rlim_swap; ··· 1082 1101 1083 1102 return result; 1084 1103 } 1104 + #endif 1085 1105 1106 + #if defined(TARGET_NR_getrlimit) || defined(TARGET_NR_ugetrlimit) 1086 1107 static inline abi_ulong host_to_target_rlim(rlim_t rlim) 1087 1108 { 1088 1109 abi_ulong target_rlim_swap; ··· 1096 1117 1097 1118 return result; 1098 1119 } 1120 + #endif 1099 1121 1100 1122 static inline int target_to_host_resource(int code) 1101 1123 { ··· 1186 1208 return 0; 1187 1209 } 1188 1210 1211 + #if defined(TARGET_NR_futex) || \ 1212 + defined(TARGET_NR_rt_sigtimedwait) || \ 1213 + defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6) || \ 1214 + defined(TARGET_NR_nanosleep) || defined(TARGET_NR_clock_settime) || \ 1215 + defined(TARGET_NR_utimensat) || defined(TARGET_NR_mq_timedsend) || \ 1216 + defined(TARGET_NR_mq_timedreceive) 1189 1217 static inline abi_long target_to_host_timespec(struct timespec *host_ts, 1190 1218 abi_ulong target_addr) 1191 1219 { ··· 1199 1227 unlock_user_struct(target_ts, target_addr, 0); 1200 1228 return 0; 1201 1229 } 1230 + #endif 1202 1231 1203 1232 static inline abi_long host_to_target_timespec(abi_ulong target_addr, 1204 1233 struct timespec *host_ts) ··· 1228 1257 return 0; 1229 1258 } 1230 1259 1260 + #if defined(TARGET_NR_settimeofday) 1231 1261 static inline abi_long copy_from_user_timezone(struct timezone *tz, 1232 1262 abi_ulong target_tz_addr) 1233 1263 { ··· 1244 1274 1245 1275 return 0; 1246 1276 } 1277 + #endif 1247 1278 1248 1279 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open) 1249 1280 #include <mqueue.h> ··· 6565 6596 } 6566 6597 #endif 6567 6598 6599 + #if defined(TARGET_NR_timer_settime) || \ 6600 + (defined(TARGET_NR_timerfd_settime) && defined(CONFIG_TIMERFD)) 6568 6601 static inline abi_long target_to_host_itimerspec(struct itimerspec *host_itspec, 6569 6602 abi_ulong target_addr) 6570 6603 { ··· 6584 6617 unlock_user_struct(target_itspec, target_addr, 1); 6585 6618 return 0; 6586 6619 } 6620 + #endif 6587 6621 6622 + #if ((defined(TARGET_NR_timerfd_gettime) || \ 6623 + defined(TARGET_NR_timerfd_settime)) && defined(CONFIG_TIMERFD)) || \ 6624 + defined(TARGET_NR_timer_gettime) || defined(TARGET_NR_timer_settime) 6588 6625 static inline abi_long host_to_target_itimerspec(abi_ulong target_addr, 6589 6626 struct itimerspec *host_its) 6590 6627 { ··· 6603 6640 unlock_user_struct(target_itspec, target_addr, 0); 6604 6641 return 0; 6605 6642 } 6643 + #endif 6606 6644 6645 + #if defined(TARGET_NR_adjtimex) || \ 6646 + (defined(TARGET_NR_clock_adjtime) && defined(CONFIG_CLOCK_ADJTIME)) 6607 6647 static inline abi_long target_to_host_timex(struct timex *host_tx, 6608 6648 abi_long target_addr) 6609 6649 { ··· 6673 6713 unlock_user_struct(target_tx, target_addr, 1); 6674 6714 return 0; 6675 6715 } 6676 - 6716 + #endif 6677 6717 6678 6718 static inline abi_long target_to_host_sigevent(struct sigevent *host_sevp, 6679 6719 abi_ulong target_addr) ··· 6840 6880 futexes locally would make futexes shared between multiple processes 6841 6881 tricky. However they're probably useless because guest atomic 6842 6882 operations won't work either. */ 6883 + #if defined(TARGET_NR_futex) 6843 6884 static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout, 6844 6885 target_ulong uaddr2, int val3) 6845 6886 { ··· 6886 6927 return -TARGET_ENOSYS; 6887 6928 } 6888 6929 } 6930 + #endif 6889 6931 #if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) 6890 6932 static abi_long do_name_to_handle_at(abi_long dirfd, abi_long pathname, 6891 6933 abi_long handle, abi_long mount_id, ··· 8494 8536 } 8495 8537 } 8496 8538 return ret; 8539 + #ifdef TARGET_NR_rt_sigtimedwait 8497 8540 case TARGET_NR_rt_sigtimedwait: 8498 8541 { 8499 8542 sigset_t set; ··· 8530 8573 } 8531 8574 } 8532 8575 return ret; 8576 + #endif 8533 8577 case TARGET_NR_rt_sigqueueinfo: 8534 8578 { 8535 8579 siginfo_t uinfo; ··· 8629 8673 } 8630 8674 } 8631 8675 return ret; 8676 + #if defined(TARGET_NR_gettimeofday) 8632 8677 case TARGET_NR_gettimeofday: 8633 8678 { 8634 8679 struct timeval tv; ··· 8639 8684 } 8640 8685 } 8641 8686 return ret; 8687 + #endif 8688 + #if defined(TARGET_NR_settimeofday) 8642 8689 case TARGET_NR_settimeofday: 8643 8690 { 8644 8691 struct timeval tv, *ptv = NULL; ··· 8660 8707 8661 8708 return get_errno(settimeofday(ptv, ptz)); 8662 8709 } 8710 + #endif 8663 8711 #if defined(TARGET_NR_select) 8664 8712 case TARGET_NR_select: 8665 8713 #if defined(TARGET_WANT_NI_OLD_SELECT) ··· 9131 9179 #ifdef TARGET_NR_sendmmsg 9132 9180 case TARGET_NR_sendmmsg: 9133 9181 return do_sendrecvmmsg(arg1, arg2, arg3, arg4, 1); 9182 + #endif 9183 + #ifdef TARGET_NR_recvmmsg 9134 9184 case TARGET_NR_recvmmsg: 9135 9185 return do_sendrecvmmsg(arg1, arg2, arg3, arg4, 0); 9136 9186 #endif ··· 9305 9355 return do_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, 9306 9356 arg6, arg7, arg8, 0); 9307 9357 #endif 9358 + #if defined(TARGET_NR_wait4) 9308 9359 case TARGET_NR_wait4: 9309 9360 { 9310 9361 int status; ··· 9332 9383 } 9333 9384 } 9334 9385 return ret; 9386 + #endif 9335 9387 #ifdef TARGET_NR_swapoff 9336 9388 case TARGET_NR_swapoff: 9337 9389 if (!(p = lock_user_string(arg1))) ··· 9476 9528 return do_vm86(cpu_env, arg1, arg2); 9477 9529 #endif 9478 9530 #endif 9531 + #if defined(TARGET_NR_adjtimex) 9479 9532 case TARGET_NR_adjtimex: 9480 9533 { 9481 9534 struct timex host_buf; ··· 9491 9544 } 9492 9545 } 9493 9546 return ret; 9547 + #endif 9494 9548 #if defined(TARGET_NR_clock_adjtime) && defined(CONFIG_CLOCK_ADJTIME) 9495 9549 case TARGET_NR_clock_adjtime: 9496 9550 { ··· 10007 10061 return get_errno(sched_get_priority_max(arg1)); 10008 10062 case TARGET_NR_sched_get_priority_min: 10009 10063 return get_errno(sched_get_priority_min(arg1)); 10064 + #ifdef TARGET_NR_sched_rr_get_interval 10010 10065 case TARGET_NR_sched_rr_get_interval: 10011 10066 { 10012 10067 struct timespec ts; ··· 10016 10071 } 10017 10072 } 10018 10073 return ret; 10074 + #endif 10075 + #if defined(TARGET_NR_nanosleep) 10019 10076 case TARGET_NR_nanosleep: 10020 10077 { 10021 10078 struct timespec req, rem; ··· 10026 10083 } 10027 10084 } 10028 10085 return ret; 10086 + #endif 10029 10087 case TARGET_NR_prctl: 10030 10088 switch (arg1) { 10031 10089 case PR_GET_PDEATHSIG: ··· 11496 11554 } 11497 11555 return ret; 11498 11556 #endif 11557 + #ifdef TARGET_NR_futex 11499 11558 case TARGET_NR_futex: 11500 11559 return do_futex(arg1, arg2, arg3, arg4, arg5, arg6); 11560 + #endif 11501 11561 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init) 11502 11562 case TARGET_NR_inotify_init: 11503 11563 ret = get_errno(sys_inotify_init()); ··· 11562 11622 unlock_user (p, arg1, 0); 11563 11623 return ret; 11564 11624 11625 + #ifdef TARGET_NR_mq_timedsend 11565 11626 case TARGET_NR_mq_timedsend: 11566 11627 { 11567 11628 struct timespec ts; ··· 11577 11638 unlock_user (p, arg2, arg3); 11578 11639 } 11579 11640 return ret; 11641 + #endif 11580 11642 11643 + #ifdef TARGET_NR_mq_timedreceive 11581 11644 case TARGET_NR_mq_timedreceive: 11582 11645 { 11583 11646 struct timespec ts; ··· 11598 11661 put_user_u32(prio, arg4); 11599 11662 } 11600 11663 return ret; 11664 + #endif 11601 11665 11602 11666 /* Not implemented for now... */ 11603 11667 /* case TARGET_NR_mq_notify: */