From 23e7dfcef9c26fc67011eab7f3b80f715f01dde8 Mon Sep 17 00:00:00 2001 From: Franz-Josef Haider Date: Wed, 11 Jan 2023 23:39:00 +0200 Subject: [PATCH] [qemu-usermode] Simplify safe syscall patches. JB#59837 After https://github.com/sailfishos/scratchbox2/pull/21 is merged, we can now let syscalls go through the C syscall function. --- ...r-Use-safe_syscall-for-open-and-open.patch | 64 -------- ...-if-getrandom-is-available-properly.patch} | 9 +- ...r-Use-safe_syscall-for-execve-syscal.patch | 45 ------ ...t-f_flags-in-statfs64-when-availabl.patch} | 11 +- ...r-Use-safe_syscall-wrapper-for-send-.patch | 81 ---------- ...avx1-and-avx2-off-since-they-cause-.patch} | 9 +- ...r-Use-safe_syscall-wrapper-for-accep.patch | 65 --------- ...=> 0004-linux-user-disable-commpage.patch} | 9 +- ...r-Use-safe_syscall-wrapper-for-conne.patch | 27 ---- ...user-fix-guest-address-space-assert.patch} | 9 +- ...ser-Use-direct-syscall-for-utimensat.patch | 35 ----- ...le-safe_syscall-functionality-for-sb.patch | 22 +++ ...s-passed-to-openat-if-O_TMPFILE-is-s.patch | 26 ---- ...-util-drop-old-utimensat-compat-code.patch | 138 ------------------ ...r-Use-safe_syscall-wrapper-for-fcntl.patch | 136 ----------------- rpm/qemu-usermode.spec | 25 +--- 16 files changed, 45 insertions(+), 666 deletions(-) delete mode 100644 rpm/0001-Revert-linux-user-Use-safe_syscall-for-open-and-open.patch rename rpm/{0008-crypto-check-if-getrandom-is-available-properly.patch => 0001-crypto-check-if-getrandom-is-available-properly.patch} (89%) delete mode 100644 rpm/0002-Revert-linux-user-Use-safe_syscall-for-execve-syscal.patch rename rpm/{0012-linux-user-Support-f_flags-in-statfs64-when-availabl.patch => 0002-linux-user-Support-f_flags-in-statfs64-when-availabl.patch} (72%) delete mode 100644 rpm/0003-Revert-linux-user-Use-safe_syscall-wrapper-for-send-.patch rename rpm/{0013-linux-user-Force-avx1-and-avx2-off-since-they-cause-.patch => 0003-linux-user-Force-avx1-and-avx2-off-since-they-cause-.patch} (77%) delete mode 100644 rpm/0004-Revert-linux-user-Use-safe_syscall-wrapper-for-accep.patch rename rpm/{0014-linux-user-disable-commpage.patch => 0004-linux-user-disable-commpage.patch} (77%) delete mode 100644 rpm/0005-Revert-linux-user-Use-safe_syscall-wrapper-for-conne.patch rename rpm/{0015-linux-user-fix-guest-address-space-assert.patch => 0005-linux-user-fix-guest-address-space-assert.patch} (77%) delete mode 100644 rpm/0006-Revert-linux-user-Use-direct-syscall-for-utimensat.patch create mode 100644 rpm/0006-linux-user-Disable-safe_syscall-functionality-for-sb.patch delete mode 100644 rpm/0009-make-sure-mode-is-passed-to-openat-if-O_TMPFILE-is-s.patch delete mode 100644 rpm/0010-Revert-util-drop-old-utimensat-compat-code.patch delete mode 100644 rpm/0011-Revert-linux-user-Use-safe_syscall-wrapper-for-fcntl.patch diff --git a/rpm/0001-Revert-linux-user-Use-safe_syscall-for-open-and-open.patch b/rpm/0001-Revert-linux-user-Use-safe_syscall-for-open-and-open.patch deleted file mode 100644 index 2ad84af..0000000 --- a/rpm/0001-Revert-linux-user-Use-safe_syscall-for-open-and-open.patch +++ /dev/null @@ -1,64 +0,0 @@ -From a5702421f6f9f205fe6ba4e6ce90cef778356d9a Mon Sep 17 00:00:00 2001 -From: Frajo Haider -Date: Wed, 22 Jan 2020 10:47:20 +0200 -Subject: [PATCH 01/15] Revert "linux-user: Use safe_syscall for open and - openat system calls" - -This reverts commit c10a07387b77b94d8f7233f3b5bb559211d4e49a. ---- - linux-user/syscall.c | 18 ++++++++++++++---- - 1 file changed, 14 insertions(+), 4 deletions(-) - -diff --git a/linux-user/syscall.c b/linux-user/syscall.c -index 945fc25279..b8e9b839a2 100644 ---- a/linux-user/syscall.c -+++ b/linux-user/syscall.c -@@ -390,6 +390,18 @@ static bitmask_transtbl fcntl_flags_tbl[] = { - - _syscall2(int, sys_getcwd1, char *, buf, size_t, size) - -+static int sys_openat(int dirfd, const char *pathname, int flags, mode_t mode) -+{ -+ /* -+ * open(2) has extra parameter 'mode' when called with -+ * flag O_CREAT. -+ */ -+ if ((flags & O_CREAT) != 0) { -+ return (openat(dirfd, pathname, flags, mode)); -+ } -+ return (openat(dirfd, pathname, flags)); -+} -+ - #ifdef TARGET_NR_utimensat - #if defined(__NR_utimensat) - #define __NR_sys_utimensat __NR_utimensat -@@ -746,8 +758,6 @@ static type safe_##name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \ - - safe_syscall3(ssize_t, read, int, fd, void *, buff, size_t, count) - safe_syscall3(ssize_t, write, int, fd, const void *, buff, size_t, count) --safe_syscall4(int, openat, int, dirfd, const char *, pathname, \ -- int, flags, mode_t, mode) - #if defined(TARGET_NR_wait4) || defined(TARGET_NR_waitpid) - safe_syscall4(pid_t, wait4, pid_t, pid, int *, status, int, options, \ - struct rusage *, rusage) -@@ -7614,7 +7624,7 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags, - - if (is_proc_myself(pathname, "exe")) { - int execfd = qemu_getauxval(AT_EXECFD); -- return execfd ? execfd : safe_openat(dirfd, exec_path, flags, mode); -+ return execfd ? execfd : sys_openat(dirfd, exec_path, flags, mode); - } - - for (fake_open = fakes; fake_open->filename; fake_open++) { -@@ -7650,7 +7660,7 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags, - return fd; - } - -- return safe_openat(dirfd, path(pathname), flags, mode); -+ return sys_openat(dirfd, path(pathname), flags, mode); - } - - #define TIMER_MAGIC 0x0caf0000 --- -2.26.2 - diff --git a/rpm/0008-crypto-check-if-getrandom-is-available-properly.patch b/rpm/0001-crypto-check-if-getrandom-is-available-properly.patch similarity index 89% rename from rpm/0008-crypto-check-if-getrandom-is-available-properly.patch rename to rpm/0001-crypto-check-if-getrandom-is-available-properly.patch index d5752f9..4c81ccf 100644 --- a/rpm/0008-crypto-check-if-getrandom-is-available-properly.patch +++ b/rpm/0001-crypto-check-if-getrandom-is-available-properly.patch @@ -1,14 +1,14 @@ -From e85a856e19919c936c4cd851bcc68c3b974f28d1 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Frajo Haider Date: Mon, 27 Jan 2020 20:34:21 +0200 -Subject: [PATCH 08/15] crypto: check if getrandom is available properly +Subject: [PATCH 1/6] crypto: check if getrandom is available properly --- crypto/random-platform.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crypto/random-platform.c b/crypto/random-platform.c -index f92f96987d..b45f25db24 100644 +index f92f96987d7d262047c7604b169a7fdf11236107..b45f25db241a52e53dea8725bc62cb2d60bc8463 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -31,7 +31,8 @@ static HCRYPTPROV hCryptProv; @@ -59,6 +59,3 @@ index f92f96987d..b45f25db24 100644 } else if (errno != EINTR) { error_setg_errno(errp, errno, "getrandom"); return -1; --- -2.26.2 - diff --git a/rpm/0002-Revert-linux-user-Use-safe_syscall-for-execve-syscal.patch b/rpm/0002-Revert-linux-user-Use-safe_syscall-for-execve-syscal.patch deleted file mode 100644 index 016ebad..0000000 --- a/rpm/0002-Revert-linux-user-Use-safe_syscall-for-execve-syscal.patch +++ /dev/null @@ -1,45 +0,0 @@ -From a79fd5a9d642953db93f33af098ad7c3920915cf Mon Sep 17 00:00:00 2001 -From: Frajo Haider -Date: Wed, 22 Jan 2020 10:48:18 +0200 -Subject: [PATCH 02/15] Revert "linux-user: Use safe_syscall for execve - syscall" - -This reverts commit ffdcbe223d23461669869e85786145cce65e1e8c. ---- - linux-user/syscall.c | 13 +------------ - 1 file changed, 1 insertion(+), 12 deletions(-) - -diff --git a/linux-user/syscall.c b/linux-user/syscall.c -index b8e9b839a2..c0f675800d 100644 ---- a/linux-user/syscall.c -+++ b/linux-user/syscall.c -@@ -764,7 +764,6 @@ safe_syscall4(pid_t, wait4, pid_t, pid, int *, status, int, options, \ - #endif - safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop, \ - int, options, struct rusage *, rusage) --safe_syscall3(int, execve, const char *, filename, char **, argv, char **, envp) - #if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \ - defined(TARGET_NR_pselect6) - safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, \ -@@ -8033,17 +8032,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, - - if (!(p = lock_user_string(arg1))) - goto execve_efault; -- /* Although execve() is not an interruptible syscall it is -- * a special case where we must use the safe_syscall wrapper: -- * if we allow a signal to happen before we make the host -- * syscall then we will 'lose' it, because at the point of -- * execve the process leaves QEMU's control. So we use the -- * safe syscall wrapper to ensure that we either take the -- * signal as a guest signal, or else it does not happen -- * before the execve completes and makes it the other -- * program's problem. -- */ -- ret = get_errno(safe_execve(p, argp, envp)); -+ ret = get_errno(execve(p, argp, envp)); - unlock_user(p, arg1, 0); - - goto execve_end; --- -2.26.2 - diff --git a/rpm/0012-linux-user-Support-f_flags-in-statfs64-when-availabl.patch b/rpm/0002-linux-user-Support-f_flags-in-statfs64-when-availabl.patch similarity index 72% rename from rpm/0012-linux-user-Support-f_flags-in-statfs64-when-availabl.patch rename to rpm/0002-linux-user-Support-f_flags-in-statfs64-when-availabl.patch index 24bb4bf..e032313 100644 --- a/rpm/0012-linux-user-Support-f_flags-in-statfs64-when-availabl.patch +++ b/rpm/0002-linux-user-Support-f_flags-in-statfs64-when-availabl.patch @@ -1,17 +1,17 @@ -From 33dd663c75aeceade62a2e5803a9648815acd019 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Frajo Haider Date: Thu, 30 Jan 2020 12:17:16 +0000 -Subject: [PATCH 12/15] linux-user: Support f_flags in statfs64 when available. +Subject: [PATCH 2/6] linux-user: Support f_flags in statfs64 when available. --- linux-user/syscall.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c -index 04ea1724f5..4379d8c11c 100644 +index 945fc252791ce79d968dba5f9545be24bd28697d..7ddde87ffd96a31d6812fefa65a915dd82084dad 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c -@@ -9427,6 +9427,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, +@@ -9428,6 +9428,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, __put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]); __put_user(stfs.f_namelen, &target_stfs->f_namelen); __put_user(stfs.f_frsize, &target_stfs->f_frsize); @@ -23,6 +23,3 @@ index 04ea1724f5..4379d8c11c 100644 memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare)); unlock_user_struct(target_stfs, arg3, 1); } --- -2.26.2 - diff --git a/rpm/0003-Revert-linux-user-Use-safe_syscall-wrapper-for-send-.patch b/rpm/0003-Revert-linux-user-Use-safe_syscall-wrapper-for-send-.patch deleted file mode 100644 index f030506..0000000 --- a/rpm/0003-Revert-linux-user-Use-safe_syscall-wrapper-for-send-.patch +++ /dev/null @@ -1,81 +0,0 @@ -From 34c2acb97023dbe6fdf2e81cbb1e55b2e25bc169 Mon Sep 17 00:00:00 2001 -From: Frajo Haider -Date: Wed, 22 Jan 2020 10:57:53 +0200 -Subject: [PATCH 03/15] Revert "linux-user: Use safe_syscall wrapper for send* - and recv* syscalls" - -This reverts commit 666875306e03e1f94e1d4c808502585c10abc69a. ---- - linux-user/syscall.c | 22 +++++++--------------- - 1 file changed, 7 insertions(+), 15 deletions(-) - -diff --git a/linux-user/syscall.c b/linux-user/syscall.c -index c0f675800d..4b87fafe44 100644 ---- a/linux-user/syscall.c -+++ b/linux-user/syscall.c -@@ -795,14 +795,6 @@ safe_syscall5(ssize_t, preadv, int, fd, const struct iovec *, iov, int, iovcnt, - unsigned long, pos_l, unsigned long, pos_h) - safe_syscall5(ssize_t, pwritev, int, fd, const struct iovec *, iov, int, iovcnt, - unsigned long, pos_l, unsigned long, pos_h) --safe_syscall3(int, connect, int, fd, const struct sockaddr *, addr, -- socklen_t, addrlen) --safe_syscall6(ssize_t, sendto, int, fd, const void *, buf, size_t, len, -- int, flags, const struct sockaddr *, addr, socklen_t, addrlen) --safe_syscall6(ssize_t, recvfrom, int, fd, void *, buf, size_t, len, -- int, flags, struct sockaddr *, addr, socklen_t *, addrlen) --safe_syscall3(ssize_t, sendmsg, int, fd, const struct msghdr *, msg, int, flags) --safe_syscall3(ssize_t, recvmsg, int, fd, struct msghdr *, msg, int, flags) - safe_syscall2(int, flock, int, fd, int, operation) - #ifdef TARGET_NR_rt_sigtimedwait - safe_syscall4(int, rt_sigtimedwait, const sigset_t *, these, siginfo_t *, uinfo, -@@ -3141,17 +3133,17 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, - msg.msg_iov->iov_len); - if (ret >= 0) { - msg.msg_iov->iov_base = host_msg; -- ret = get_errno(safe_sendmsg(fd, &msg, flags)); -+ ret = get_errno(sendmsg(fd, &msg, flags)); - } - g_free(host_msg); - } else { - ret = target_to_host_cmsg(&msg, msgp); - if (ret == 0) { -- ret = get_errno(safe_sendmsg(fd, &msg, flags)); -+ ret = get_errno(sendmsg(fd, &msg, flags)); - } - } - } else { -- ret = get_errno(safe_recvmsg(fd, &msg, flags)); -+ ret = get_errno(recvmsg(fd, &msg, flags)); - if (!is_error(ret)) { - len = ret; - if (fd_trans_host_to_target_data(fd)) { -@@ -3396,9 +3388,9 @@ static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags, - if (ret) { - goto fail; - } -- ret = get_errno(safe_sendto(fd, host_msg, len, flags, addr, addrlen)); -+ ret = get_errno(sendto(fd, host_msg, len, flags, addr, addrlen)); - } else { -- ret = get_errno(safe_sendto(fd, host_msg, len, flags, NULL, 0)); -+ ret = get_errno(send(fd, host_msg, len, flags)); - } - fail: - if (copy_msg) { -@@ -3433,12 +3425,12 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, - } - addr = alloca(addrlen); - ret_addrlen = addrlen; -- ret = get_errno(safe_recvfrom(fd, host_msg, len, flags, -+ ret = get_errno(recvfrom(fd, host_msg, len, flags, - addr, &ret_addrlen)); - } else { - addr = NULL; /* To keep compiler quiet. */ - addrlen = 0; /* To keep compiler quiet. */ -- ret = get_errno(safe_recvfrom(fd, host_msg, len, flags, NULL, 0)); -+ ret = get_errno(recvfrom(fd, host_msg, len, flags, NULL, 0)); - } - if (!is_error(ret)) { - if (fd_trans_host_to_target_data(fd)) { --- -2.26.2 - diff --git a/rpm/0013-linux-user-Force-avx1-and-avx2-off-since-they-cause-.patch b/rpm/0003-linux-user-Force-avx1-and-avx2-off-since-they-cause-.patch similarity index 77% rename from rpm/0013-linux-user-Force-avx1-and-avx2-off-since-they-cause-.patch rename to rpm/0003-linux-user-Force-avx1-and-avx2-off-since-they-cause-.patch index 9293b59..c4da406 100644 --- a/rpm/0013-linux-user-Force-avx1-and-avx2-off-since-they-cause-.patch +++ b/rpm/0003-linux-user-Force-avx1-and-avx2-off-since-they-cause-.patch @@ -1,7 +1,7 @@ -From 116a97a22bce7b8a034d2b071b5200cd3f5fedff Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Frajo Haider Date: Tue, 8 Dec 2020 10:18:18 +0000 -Subject: [PATCH 13/15] linux-user: Force avx1 and avx2 off since they cause +Subject: [PATCH 3/6] linux-user: Force avx1 and avx2 off since they cause issues in sb2 environment. --- @@ -9,7 +9,7 @@ Subject: [PATCH 13/15] linux-user: Force avx1 and avx2 off since they cause 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tcg/i386/tcg-target.inc.c b/tcg/i386/tcg-target.inc.c -index ae0228238b..1e47a8f1d0 100644 +index ae0228238b456e0e7c41fc7adc5047b9da2ac202..1e47a8f1d0e52a3266d1bf550e19edf49851b470 100644 --- a/tcg/i386/tcg-target.inc.c +++ b/tcg/i386/tcg-target.inc.c @@ -3894,8 +3894,8 @@ static void tcg_target_init(TCGContext *s) @@ -23,6 +23,3 @@ index ae0228238b..1e47a8f1d0 100644 } } } --- -2.26.2 - diff --git a/rpm/0004-Revert-linux-user-Use-safe_syscall-wrapper-for-accep.patch b/rpm/0004-Revert-linux-user-Use-safe_syscall-wrapper-for-accep.patch deleted file mode 100644 index 8d84802..0000000 --- a/rpm/0004-Revert-linux-user-Use-safe_syscall-wrapper-for-accep.patch +++ /dev/null @@ -1,65 +0,0 @@ -From d7a6f3ca96a4af2f47031ea04cf05e92e36cd8bb Mon Sep 17 00:00:00 2001 -From: Frajo Haider -Date: Wed, 22 Jan 2020 10:59:47 +0200 -Subject: [PATCH 04/15] Revert "linux-user: Use safe_syscall wrapper for accept - and accept4 syscalls" - -This reverts commit ff6dc130794bcd5b2033bc50262a7720285a74c7. ---- - linux-user/syscall.c | 19 +++++++++++++++---- - 1 file changed, 15 insertions(+), 4 deletions(-) - -diff --git a/linux-user/syscall.c b/linux-user/syscall.c -index 4b87fafe44..50a91b9af7 100644 ---- a/linux-user/syscall.c -+++ b/linux-user/syscall.c -@@ -800,8 +800,6 @@ safe_syscall2(int, flock, int, fd, int, operation) - safe_syscall4(int, rt_sigtimedwait, const sigset_t *, these, siginfo_t *, uinfo, - const struct timespec *, uts, size_t, sigsetsize) - #endif --safe_syscall4(int, accept4, int, fd, struct sockaddr *, addr, socklen_t *, len, -- int, flags) - #if defined(TARGET_NR_nanosleep) - safe_syscall2(int, nanosleep, const struct timespec *, req, - struct timespec *, rem) -@@ -3238,6 +3236,19 @@ static abi_long do_sendrecvmmsg(int fd, abi_ulong target_msgvec, - return ret; - } - -+/* If we don't have a system accept4() then just call accept. -+ * The callsites to do_accept4() will ensure that they don't -+ * pass a non-zero flags argument in this config. -+ */ -+#ifndef CONFIG_ACCEPT4 -+static inline int accept4(int sockfd, struct sockaddr *addr, -+ socklen_t *addrlen, int flags) -+{ -+ assert(flags == 0); -+ return accept(sockfd, addr, addrlen); -+} -+#endif -+ - /* do_accept4() Must return target values and target errnos. */ - static abi_long do_accept4(int fd, abi_ulong target_addr, - abi_ulong target_addrlen_addr, int flags) -@@ -3250,7 +3261,7 @@ static abi_long do_accept4(int fd, abi_ulong target_addr, - host_flags = target_to_host_bitmask(flags, fcntl_flags_tbl); - - if (target_addr == 0) { -- return get_errno(safe_accept4(fd, NULL, NULL, host_flags)); -+ return get_errno(accept4(fd, NULL, NULL, host_flags)); - } - - /* linux returns EINVAL if addrlen pointer is invalid */ -@@ -3267,7 +3278,7 @@ static abi_long do_accept4(int fd, abi_ulong target_addr, - addr = alloca(addrlen); - - ret_addrlen = addrlen; -- ret = get_errno(safe_accept4(fd, addr, &ret_addrlen, host_flags)); -+ ret = get_errno(accept4(fd, addr, &ret_addrlen, host_flags)); - if (!is_error(ret)) { - host_to_target_sockaddr(target_addr, addr, MIN(addrlen, ret_addrlen)); - if (put_user_u32(ret_addrlen, target_addrlen_addr)) { --- -2.26.2 - diff --git a/rpm/0014-linux-user-disable-commpage.patch b/rpm/0004-linux-user-disable-commpage.patch similarity index 77% rename from rpm/0014-linux-user-disable-commpage.patch rename to rpm/0004-linux-user-disable-commpage.patch index 21dc906..cbf25d3 100644 --- a/rpm/0014-linux-user-disable-commpage.patch +++ b/rpm/0004-linux-user-disable-commpage.patch @@ -1,14 +1,14 @@ -From 0ae25695228fefca462304c91735fc1736156649 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Frajo Haider Date: Tue, 8 Dec 2020 00:19:06 +0200 -Subject: [PATCH 14/15] linux-user: disable commpage +Subject: [PATCH 4/6] linux-user: disable commpage --- linux-user/elfload.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c -index fe9dfe795d..7119cf531a 100644 +index fe9dfe795ddd63ab862ac8c6f31ff7a25700c5bb..7119cf531a3002ff509549d5647f49699b06f4de 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -383,8 +383,10 @@ enum { @@ -31,6 +31,3 @@ index fe9dfe795d..7119cf531a 100644 #define ELF_HWCAP get_elf_hwcap() #define ELF_HWCAP2 get_elf_hwcap2() --- -2.26.2 - diff --git a/rpm/0005-Revert-linux-user-Use-safe_syscall-wrapper-for-conne.patch b/rpm/0005-Revert-linux-user-Use-safe_syscall-wrapper-for-conne.patch deleted file mode 100644 index 5e68ab2..0000000 --- a/rpm/0005-Revert-linux-user-Use-safe_syscall-wrapper-for-conne.patch +++ /dev/null @@ -1,27 +0,0 @@ -From 2d7e33829ff7b9f5f2841d0cc577be45b9f3d3fb Mon Sep 17 00:00:00 2001 -From: Frajo Haider -Date: Wed, 22 Jan 2020 11:13:13 +0200 -Subject: [PATCH 05/15] Revert "linux-user: Use safe_syscall wrapper for - connect syscall" - -This reverts commit 2a3c7619288af9cfcc09a233dce911bf80849dfb. ---- - linux-user/syscall.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/linux-user/syscall.c b/linux-user/syscall.c -index 50a91b9af7..88a64dc495 100644 ---- a/linux-user/syscall.c -+++ b/linux-user/syscall.c -@@ -3062,7 +3062,7 @@ static abi_long do_connect(int sockfd, abi_ulong target_addr, - if (ret) - return ret; - -- return get_errno(safe_connect(sockfd, addr, addrlen)); -+ return get_errno(connect(sockfd, addr, addrlen)); - } - - /* do_sendrecvmsg_locked() Must return target values and target errnos. */ --- -2.26.2 - diff --git a/rpm/0015-linux-user-fix-guest-address-space-assert.patch b/rpm/0005-linux-user-fix-guest-address-space-assert.patch similarity index 77% rename from rpm/0015-linux-user-fix-guest-address-space-assert.patch rename to rpm/0005-linux-user-fix-guest-address-space-assert.patch index 18aabe8..5cf122f 100644 --- a/rpm/0015-linux-user-fix-guest-address-space-assert.patch +++ b/rpm/0005-linux-user-fix-guest-address-space-assert.patch @@ -1,15 +1,15 @@ -From a26286f2ddc513fa80ec77fbe4ff36fea28d32e0 Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juho=20H=C3=A4m=C3=A4l=C3=A4inen?= Date: Tue, 8 Dec 2020 15:47:10 +0000 -Subject: [PATCH 15/15] linux-user: fix guest address space assert +Subject: [PATCH 5/6] linux-user: fix guest address space assert --- accel/tcg/translate-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c -index 2d83013633..4cea23784a 100644 +index 2d83013633b59026ab5daa4a7bb5b3a094270a5f..4cea23784a3de52abc6f70fe6f7371f50cbcc172 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -2551,7 +2551,7 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) @@ -21,6 +21,3 @@ index 2d83013633..4cea23784a 100644 assert(start < end); assert_memory_lock(); --- -2.26.2 - diff --git a/rpm/0006-Revert-linux-user-Use-direct-syscall-for-utimensat.patch b/rpm/0006-Revert-linux-user-Use-direct-syscall-for-utimensat.patch deleted file mode 100644 index 33aaa5d..0000000 --- a/rpm/0006-Revert-linux-user-Use-direct-syscall-for-utimensat.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 7d64443c41d6249f098da26ff5fa9bc463ebbd45 Mon Sep 17 00:00:00 2001 -From: Frajo Haider -Date: Wed, 29 Jan 2020 12:49:43 +0200 -Subject: [PATCH 06/15] Revert "linux-user: Use direct syscall for utimensat" - -This reverts commit 700fa58e4b9100d6bd77df06d2e5d1f457720c4d. ---- - linux-user/syscall.c | 11 ++++++++++- - 1 file changed, 10 insertions(+), 1 deletion(-) - -diff --git a/linux-user/syscall.c b/linux-user/syscall.c -index 88a64dc495..91594472ed 100644 ---- a/linux-user/syscall.c -+++ b/linux-user/syscall.c -@@ -403,7 +403,16 @@ static int sys_openat(int dirfd, const char *pathname, int flags, mode_t mode) - } - - #ifdef TARGET_NR_utimensat --#if defined(__NR_utimensat) -+#ifdef CONFIG_UTIMENSAT -+static int sys_utimensat(int dirfd, const char *pathname, -+ const struct timespec times[2], int flags) -+{ -+ if (pathname == NULL) -+ return futimens(dirfd, times); -+ else -+ return utimensat(dirfd, pathname, times, flags); -+} -+#elif defined(__NR_utimensat) - #define __NR_sys_utimensat __NR_utimensat - _syscall4(int,sys_utimensat,int,dirfd,const char *,pathname, - const struct timespec *,tsp,int,flags) --- -2.26.2 - diff --git a/rpm/0006-linux-user-Disable-safe_syscall-functionality-for-sb.patch b/rpm/0006-linux-user-Disable-safe_syscall-functionality-for-sb.patch new file mode 100644 index 0000000..ef6713d --- /dev/null +++ b/rpm/0006-linux-user-Disable-safe_syscall-functionality-for-sb.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Frajo Haider +Date: Thu, 12 Jan 2023 01:22:33 +0200 +Subject: [PATCH 6/6] linux-user: Disable safe_syscall functionality for sb2 + +--- + linux-user/qemu.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/linux-user/qemu.h b/linux-user/qemu.h +index 5c964389c101ce00fcffe206bc69fb8b571634bc..15ff74749f4372269fff62cd98c1bf756cd84b2b 100644 +--- a/linux-user/qemu.h ++++ b/linux-user/qemu.h +@@ -1,7 +1,7 @@ + #ifndef QEMU_H + #define QEMU_H + +-#include "hostdep.h" ++// #include "hostdep.h" + #include "cpu.h" + #include "exec/exec-all.h" + #include "exec/cpu_ldst.h" diff --git a/rpm/0009-make-sure-mode-is-passed-to-openat-if-O_TMPFILE-is-s.patch b/rpm/0009-make-sure-mode-is-passed-to-openat-if-O_TMPFILE-is-s.patch deleted file mode 100644 index dc08135..0000000 --- a/rpm/0009-make-sure-mode-is-passed-to-openat-if-O_TMPFILE-is-s.patch +++ /dev/null @@ -1,26 +0,0 @@ -From d5e5925b5b7fc08d0c476842493183f3bc66389e Mon Sep 17 00:00:00 2001 -From: Frajo Haider -Date: Wed, 29 Jan 2020 11:12:24 +0000 -Subject: [PATCH 09/15] make sure mode is passed to openat if O_TMPFILE is - specified. JB#45765 - ---- - linux-user/syscall.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/linux-user/syscall.c b/linux-user/syscall.c -index 91594472ed..5ec9a19ca2 100644 ---- a/linux-user/syscall.c -+++ b/linux-user/syscall.c -@@ -396,7 +396,7 @@ static int sys_openat(int dirfd, const char *pathname, int flags, mode_t mode) - * open(2) has extra parameter 'mode' when called with - * flag O_CREAT. - */ -- if ((flags & O_CREAT) != 0) { -+ if ((flags & O_CREAT) != 0 || ((flags) & O_TMPFILE) == O_TMPFILE) { - return (openat(dirfd, pathname, flags, mode)); - } - return (openat(dirfd, pathname, flags)); --- -2.26.2 - diff --git a/rpm/0010-Revert-util-drop-old-utimensat-compat-code.patch b/rpm/0010-Revert-util-drop-old-utimensat-compat-code.patch deleted file mode 100644 index 696e2ec..0000000 --- a/rpm/0010-Revert-util-drop-old-utimensat-compat-code.patch +++ /dev/null @@ -1,138 +0,0 @@ -From b633f9758ed8101ea56a7d3c2303ac1f6b994258 Mon Sep 17 00:00:00 2001 -From: Frajo Haider -Date: Wed, 29 Jan 2020 11:21:54 +0000 -Subject: [PATCH 10/15] Revert "util: drop old utimensat() compat code" - -This reverts commit fcdcf1eed2fd26bfe836080755ba4322d3c1f2cc. - -Conflicts: - slirp ---- - configure | 22 ++++++++++++++++++ - include/sysemu/os-posix.h | 11 +++++++++ - util/oslib-posix.c | 47 +++++++++++++++++++++++++++++++++++++++ - 3 files changed, 80 insertions(+) - -diff --git a/configure b/configure -index 2acc4d1465..5d47dbc1e8 100755 ---- a/configure -+++ b/configure -@@ -4599,6 +4599,25 @@ if compile_prog "" "" ; then - inotify1=yes - fi - -+# check if utimensat and futimens are supported -+utimens=no -+cat > $TMPC << EOF -+#define _ATFILE_SOURCE -+#include -+#include -+#include -+ -+int main(void) -+{ -+ utimensat(AT_FDCWD, "foo", NULL, 0); -+ futimens(0, NULL); -+ return 0; -+} -+EOF -+if compile_prog "" "" ; then -+ utimens=yes -+fi -+ - # check if pipe2 is there - pipe2=no - cat > $TMPC << EOF -@@ -7261,6 +7280,9 @@ if test "$curses" = "yes" ; then - echo "CURSES_CFLAGS=$curses_inc" >> $config_host_mak - echo "CURSES_LIBS=$curses_lib" >> $config_host_mak - fi -+if test "$utimens" = "yes" ; then -+ echo "CONFIG_UTIMENSAT=y" >> $config_host_mak -+fi - if test "$pipe2" = "yes" ; then - echo "CONFIG_PIPE2=y" >> $config_host_mak - fi -diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h -index 629c8c648b..900bdcb45a 100644 ---- a/include/sysemu/os-posix.h -+++ b/include/sysemu/os-posix.h -@@ -51,6 +51,17 @@ int os_mlock(void); - typedef struct timeval qemu_timeval; - #define qemu_gettimeofday(tp) gettimeofday(tp, NULL) - -+#ifndef CONFIG_UTIMENSAT -+#ifndef UTIME_NOW -+# define UTIME_NOW ((1l << 30) - 1l) -+#endif -+#ifndef UTIME_OMIT -+# define UTIME_OMIT ((1l << 30) - 2l) -+#endif -+#endif -+typedef struct timespec qemu_timespec; -+int qemu_utimens(const char *path, const qemu_timespec *times); -+ - bool is_daemonized(void); - - /** -diff --git a/util/oslib-posix.c b/util/oslib-posix.c -index ad8001a4ad..6df285a07b 100644 ---- a/util/oslib-posix.c -+++ b/util/oslib-posix.c -@@ -336,6 +336,53 @@ int qemu_pipe(int pipefd[2]) - return ret; - } - -+int qemu_utimens(const char *path, const struct timespec *times) -+{ -+ struct timeval tv[2], tv_now; -+ struct stat st; -+ int i; -+#ifdef CONFIG_UTIMENSAT -+ int ret; -+ -+ ret = utimensat(AT_FDCWD, path, times, AT_SYMLINK_NOFOLLOW); -+ if (ret != -1 || errno != ENOSYS) { -+ return ret; -+ } -+#endif -+ /* Fallback: use utimes() instead of utimensat() */ -+ -+ /* happy if special cases */ -+ if (times[0].tv_nsec == UTIME_OMIT && times[1].tv_nsec == UTIME_OMIT) { -+ return 0; -+ } -+ if (times[0].tv_nsec == UTIME_NOW && times[1].tv_nsec == UTIME_NOW) { -+ return utimes(path, NULL); -+ } -+ -+ /* prepare for hard cases */ -+ if (times[0].tv_nsec == UTIME_NOW || times[1].tv_nsec == UTIME_NOW) { -+ gettimeofday(&tv_now, NULL); -+ } -+ if (times[0].tv_nsec == UTIME_OMIT || times[1].tv_nsec == UTIME_OMIT) { -+ stat(path, &st); -+ } -+ -+ for (i = 0; i < 2; i++) { -+ if (times[i].tv_nsec == UTIME_NOW) { -+ tv[i].tv_sec = tv_now.tv_sec; -+ tv[i].tv_usec = tv_now.tv_usec; -+ } else if (times[i].tv_nsec == UTIME_OMIT) { -+ tv[i].tv_sec = (i == 0) ? st.st_atime : st.st_mtime; -+ tv[i].tv_usec = 0; -+ } else { -+ tv[i].tv_sec = times[i].tv_sec; -+ tv[i].tv_usec = times[i].tv_nsec / 1000; -+ } -+ } -+ -+ return utimes(path, &tv[0]); -+} -+ - char * - qemu_get_local_state_pathname(const char *relative_pathname) - { --- -2.26.2 - diff --git a/rpm/0011-Revert-linux-user-Use-safe_syscall-wrapper-for-fcntl.patch b/rpm/0011-Revert-linux-user-Use-safe_syscall-wrapper-for-fcntl.patch deleted file mode 100644 index 0120da2..0000000 --- a/rpm/0011-Revert-linux-user-Use-safe_syscall-wrapper-for-fcntl.patch +++ /dev/null @@ -1,136 +0,0 @@ -From 3025c3ad424d229f4d52209d7eec058d9fec8816 Mon Sep 17 00:00:00 2001 -From: Frajo Haider -Date: Wed, 29 Jan 2020 12:42:08 +0000 -Subject: [PATCH 11/15] Revert "linux-user: Use safe_syscall wrapper for fcntl" - -This reverts commit 435da5e7092aa54e12044b9401b42c4a9333c74d. - -Conflicts: - linux-user/syscall.c - slirp ---- - linux-user/syscall.c | 36 ++++++++++++------------------------ - 1 file changed, 12 insertions(+), 24 deletions(-) - -diff --git a/linux-user/syscall.c b/linux-user/syscall.c -index 5ec9a19ca2..04ea1724f5 100644 ---- a/linux-user/syscall.c -+++ b/linux-user/syscall.c -@@ -851,16 +851,6 @@ safe_syscall5(int, mq_timedreceive, int, mqdes, char *, msg_ptr, - * the libc function. - */ - #define safe_ioctl(...) safe_syscall(__NR_ioctl, __VA_ARGS__) --/* Similarly for fcntl. Note that callers must always: -- * pass the F_GETLK64 etc constants rather than the unsuffixed F_GETLK -- * use the flock64 struct rather than unsuffixed flock -- * This will then work and use a 64-bit offset for both 32-bit and 64-bit hosts. -- */ --#ifdef __NR_fcntl64 --#define safe_fcntl(...) safe_syscall(__NR_fcntl64, __VA_ARGS__) --#else --#define safe_fcntl(...) safe_syscall(__NR_fcntl, __VA_ARGS__) --#endif - - static inline int host_to_target_sock_type(int host_type) - { -@@ -6530,7 +6520,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) - if (ret) { - return ret; - } -- ret = get_errno(safe_fcntl(fd, host_cmd, &fl64)); -+ ret = get_errno(fcntl(fd, host_cmd, &fl64)); - if (ret == 0) { - ret = copy_to_user_flock(arg, &fl64); - } -@@ -6542,7 +6532,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) - if (ret) { - return ret; - } -- ret = get_errno(safe_fcntl(fd, host_cmd, &fl64)); -+ ret = get_errno(fcntl(fd, host_cmd, &fl64)); - break; - - case TARGET_F_GETLK64: -@@ -6551,7 +6541,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) - if (ret) { - return ret; - } -- ret = get_errno(safe_fcntl(fd, host_cmd, &fl64)); -+ ret = get_errno(fcntl(fd, host_cmd, &fl64)); - if (ret == 0) { - ret = copy_to_user_flock64(arg, &fl64); - } -@@ -6564,25 +6554,23 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) - if (ret) { - return ret; - } -- ret = get_errno(safe_fcntl(fd, host_cmd, &fl64)); -+ ret = get_errno(fcntl(fd, host_cmd, &fl64)); - break; - - case TARGET_F_GETFL: -- ret = get_errno(safe_fcntl(fd, host_cmd, arg)); -+ ret = get_errno(fcntl(fd, host_cmd, arg)); - if (ret >= 0) { - ret = host_to_target_bitmask(ret, fcntl_flags_tbl); - } - break; - - case TARGET_F_SETFL: -- ret = get_errno(safe_fcntl(fd, host_cmd, -- target_to_host_bitmask(arg, -- fcntl_flags_tbl))); -+ ret = get_errno(fcntl(fd, host_cmd, target_to_host_bitmask(arg, fcntl_flags_tbl))); - break; - - #ifdef F_GETOWN_EX - case TARGET_F_GETOWN_EX: -- ret = get_errno(safe_fcntl(fd, host_cmd, &fox)); -+ ret = get_errno(fcntl(fd, host_cmd, &fox)); - if (ret >= 0) { - if (!lock_user_struct(VERIFY_WRITE, target_fox, arg, 0)) - return -TARGET_EFAULT; -@@ -6600,7 +6588,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) - fox.type = tswap32(target_fox->type); - fox.pid = tswap32(target_fox->pid); - unlock_user_struct(target_fox, arg, 0); -- ret = get_errno(safe_fcntl(fd, host_cmd, &fox)); -+ ret = get_errno(fcntl(fd, host_cmd, &fox)); - break; - #endif - -@@ -6612,11 +6600,11 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) - case TARGET_F_GETLEASE: - case TARGET_F_SETPIPE_SZ: - case TARGET_F_GETPIPE_SZ: -- ret = get_errno(safe_fcntl(fd, host_cmd, arg)); -+ ret = get_errno(fcntl(fd, host_cmd, arg)); - break; - - default: -- ret = get_errno(safe_fcntl(fd, cmd, arg)); -+ ret = get_errno(fcntl(fd, cmd, arg)); - break; - } - return ret; -@@ -11522,7 +11510,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, - if (ret) { - break; - } -- ret = get_errno(safe_fcntl(arg1, cmd, &fl)); -+ ret = get_errno(fcntl(arg1, cmd, &fl)); - if (ret == 0) { - ret = copyto(arg3, &fl); - } -@@ -11534,7 +11522,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, - if (ret) { - break; - } -- ret = get_errno(safe_fcntl(arg1, cmd, &fl)); -+ ret = get_errno(fcntl(arg1, cmd, &fl)); - break; - default: - ret = do_fcntl(arg1, arg2, arg3); --- -2.26.2 - diff --git a/rpm/qemu-usermode.spec b/rpm/qemu-usermode.spec index 280704b..cd973ac 100644 --- a/rpm/qemu-usermode.spec +++ b/rpm/qemu-usermode.spec @@ -11,29 +11,18 @@ URL: https://www.qemu.org/ Source0: %{name}-%{version}.tar.xz Source1: qemu-binfmt-conf.sh -# fix for sb2 (sb2 needs to hook open, openat): -Patch0: 0001-Revert-linux-user-Use-safe_syscall-for-open-and-open.patch -Patch1: 0002-Revert-linux-user-Use-safe_syscall-for-execve-syscal.patch -Patch2: 0003-Revert-linux-user-Use-safe_syscall-wrapper-for-send-.patch -Patch3: 0004-Revert-linux-user-Use-safe_syscall-wrapper-for-accep.patch -Patch4: 0005-Revert-linux-user-Use-safe_syscall-wrapper-for-conne.patch -Patch5: 0006-Revert-linux-user-Use-direct-syscall-for-utimensat.patch # For obs getting stuck in getrandom -Patch7: 0008-crypto-check-if-getrandom-is-available-properly.patch -# fix openat syscall (breaks e.g. bc build) -Patch8: 0009-make-sure-mode-is-passed-to-openat-if-O_TMPFILE-is-s.patch -# make sure utimensat from glibc is being used (see sb2 fixes above) -Patch9: 0010-Revert-util-drop-old-utimensat-compat-code.patch -# one more revert for sb2 -Patch10: 0011-Revert-linux-user-Use-safe_syscall-wrapper-for-fcntl.patch +Patch0: 0001-crypto-check-if-getrandom-is-available-properly.patch # fix f_flags in statfs64 -Patch11: 0012-linux-user-Support-f_flags-in-statfs64-when-availabl.patch +Patch1: 0002-linux-user-Support-f_flags-in-statfs64-when-availabl.patch # fix build failures -Patch12: 0013-linux-user-Force-avx1-and-avx2-off-since-they-cause-.patch +Patch2: 0003-linux-user-Force-avx1-and-avx2-off-since-they-cause-.patch # fix qemu-user start issues due to running on 64 bit kernel -Patch13: 0014-linux-user-disable-commpage.patch +Patch3: 0004-linux-user-disable-commpage.patch # fix assert which breaks ustr tests -Patch14: 0015-linux-user-fix-guest-address-space-assert.patch +Patch4: 0005-linux-user-fix-guest-address-space-assert.patch +# sb2 can handle syscalls now, but not if they are not going through the c interface +Patch5: 0006-Disable-safe_syscall-functionality-for-sb2.patch BuildRequires: pkgconfig(ext2fs) BuildRequires: pkgconfig(glib-2.0)