From 0ad873b44b73ab2fde8c378470cd1b75b7a3c4d2 Mon Sep 17 00:00:00 2001 From: Yarny0 <41838844+Yarny0@users.noreply.github.com> Date: Mon, 4 Jul 2022 22:15:03 +0200 Subject: [PATCH] virtualbox: update patch linux-5.18 -> linux-5.19 Some history: The linux kernel v5.18-rc contains the commit > commit 6e8ec2552c7d13991148e551e3325a624d73fac6 > Author: Jason A. Donenfeld > Date: 2022-01-16 14:23:10 +0100 > > random: use computational hash for entropy extraction > [...] which modifies the kernels random number generator. This change broke VirtualBox 6.1.34 in several ways: It causes random crashes and filesystem corruption in the guest (at least on some host CPU models). More details can be found in the corresponding ticket in the VirtualBox bug tracker: https://www.virtualbox.org/ticket/20914 That ticket also contains a patch "vbox-linux-5.18.patch" for VirtualBox that fixes the problem, at least for kernels 5.18 and (hopefully) above. This patch got added to nixpkgs' VirtualBox build recipe with https://github.com/NixOS/nixpkgs/pull/175507/commits/9c8132494fbfb6c5cf09767b18d703103d067a17 . Meanwhile, the kernel patch got backported to LTS kernels. As the VirtualBox patch contains several `#if RTLNX_VER_MIN(5,18,0)` clauses to apply the fix, it can't heal VirtualBox on LTS kernel versions. The result is that VirtualBox is still broken if used with linux kernels 5.10 and 5.15 (currenly the default kernel in nixpkgs). Luckily, VirtualBox developers updated the patch (now named "vbox-linux-5.19.patch") to not only fix the problem for the upcoming 5.19 kernel, but also address backport releases. The commit at hand replaces "vbox-linux-5.18.patch" with the new "vbox-linux-5.19.patch", fixing VirtualBox for LTS kernel releases. --- .../virtualization/virtualbox/default.nix | 9 +- .../virtualization/virtualbox/linux518.patch | 285 ------------------ 2 files changed, 7 insertions(+), 287 deletions(-) delete mode 100644 pkgs/applications/virtualization/virtualbox/linux518.patch diff --git a/pkgs/applications/virtualization/virtualbox/default.nix b/pkgs/applications/virtualization/virtualbox/default.nix index 4e07d92d661d..af2c4a0070ad 100644 --- a/pkgs/applications/virtualization/virtualbox/default.nix +++ b/pkgs/applications/virtualization/virtualbox/default.nix @@ -3,6 +3,7 @@ , libpng, glib, lvm2, libXrandr, libXinerama, libopus, qtbase, qtx11extras , qttools, qtsvg, qtwayland, pkg-config, which, docbook_xsl, docbook_xml_dtd_43 , alsa-lib, curl, libvpx, nettools, dbus, substituteAll, gsoap, zlib +, fetchpatch # If open-watcom-bin is not passed, VirtualBox will fall back to use # the shipped alternative sources (assembly). , open-watcom-bin @@ -98,8 +99,12 @@ in stdenv.mkDerivation { # https://github.com/NixOS/nixpkgs/issues/123851 ./fix-audio-driver-loading.patch # NOTE: both patches below should be removed when updating to 6.1.35 - # https://www.virtualbox.org/ticket/20914#comment:6 - ./linux518.patch + # https://www.virtualbox.org/ticket/20914#comment:15 + (fetchpatch { + url = "https://www.virtualbox.org/raw-attachment/ticket/20914/vbox-linux-5.19.patch"; + hash = "sha512-NNiMf8kUuM/PimrQCOacYLkrf7UFPh6ZdPsXKyLlsqWfWQXkG92Fv3qZXvg8weE1Z/SBsFTuHICEI4b4l1wZFw=="; + extraPrefix = "/"; + }) # https://www.virtualbox.org/ticket/20904#comment:22 ./ffreestanding.patch ]; diff --git a/pkgs/applications/virtualization/virtualbox/linux518.patch b/pkgs/applications/virtualization/virtualbox/linux518.patch deleted file mode 100644 index 6130cfc78a0a..000000000000 --- a/pkgs/applications/virtualization/virtualbox/linux518.patch +++ /dev/null @@ -1,285 +0,0 @@ -Index: include/VBox/sup.h -=================================================================== ---- trunk/include/VBox/sup.h (revision 151556) -+++ trunk/include/VBox/sup.h (working copy) -@@ -2142,6 +2142,26 @@ - */ - SUPR0DECL(uint32_t) SUPR0GetKernelFeatures(void); - -+/** -+ * Notification from R0 VMM prior to loading the guest-FPU register state. -+ * -+ * @returns Whether the host-FPU register state has been saved by the host kernel. -+ * @param fCtxHook Whether thread-context hooks are enabled. -+ * -+ * @remarks Called with preemption disabled. -+ */ -+SUPR0DECL(bool) SUPR0FpuBegin(bool fCtxHook); -+ -+/** -+ * Notification from R0 VMM prior to saving the guest-FPU register state (and -+ * potentially restoring the host-FPU register state) in ring-0. -+ * -+ * @param fCtxHook Whether thread-context hooks are enabled. -+ * -+ * @remarks Called with preemption disabled. -+ */ -+SUPR0DECL(void) SUPR0FpuEnd(bool fCtxHook); -+ - /** @copydoc RTLogGetDefaultInstanceEx - * @remarks To allow overriding RTLogGetDefaultInstanceEx locally. */ - SUPR0DECL(struct RTLOGGER *) SUPR0GetDefaultLogInstanceEx(uint32_t fFlagsAndGroup); -Index: src/VBox/Additions/linux/sharedfolders/regops.c -=================================================================== ---- trunk/src/VBox/Additions/linux/sharedfolders/regops.c (revision 151556) -+++ trunk/src/VBox/Additions/linux/sharedfolders/regops.c (working copy) -@@ -3823,7 +3823,9 @@ - .readpage = vbsf_readpage, - .writepage = vbsf_writepage, - /** @todo Need .writepages if we want msync performance... */ --#if RTLNX_VER_MIN(2,5,12) -+#if RTLNX_VER_MIN(5,18,0) -+ .dirty_folio = filemap_dirty_folio, -+#elif RTLNX_VER_MIN(2,5,12) - .set_page_dirty = __set_page_dirty_buffers, - #endif - #if RTLNX_VER_MIN(5,14,0) -Index: src/VBox/Additions -=================================================================== ---- trunk/src/VBox/Additions (revision 151556) -+++ trunk/src/VBox/Additions (working copy) - -Property changes on: src/VBox/Additions -___________________________________________________________________ -Modified: svn:mergeinfo -## -0,0 +0,1 ## - Merged /trunk/src/VBox/Additions:r150844 -Index: src/VBox/HostDrivers/Support/SUPDrv.cpp -=================================================================== ---- trunk/src/VBox/HostDrivers/Support/SUPDrv.cpp (revision 151556) -+++ trunk/src/VBox/HostDrivers/Support/SUPDrv.cpp (working copy) -@@ -98,6 +98,18 @@ - # endif - #endif - -+#if defined(RT_OS_LINUX) && !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE) -+/* In Linux 5.18-rc1, memcpy became a wrapper which does fortify checks -+ * before triggering __underlying_memcpy() call. We do not pass these checks here, -+ * so bypass them for now. */ -+# if RTLNX_VER_MIN(5,18,0) -+# define SUPDRV_MEMCPY __underlying_memcpy -+# else -+# define SUPDRV_MEMCPY memcpy -+# endif -+#else -+# define SUPDRV_MEMCPY memcpy -+#endif - - /* - * Logging assignments: -@@ -266,6 +278,8 @@ - SUPEXP_STK_BACK( 2, SUPR0ContFree), - SUPEXP_STK_BACK( 2, SUPR0ChangeCR4), - SUPEXP_STK_BACK( 1, SUPR0EnableVTx), -+ SUPEXP_STK_OKAY( 1, SUPR0FpuBegin), -+ SUPEXP_STK_OKAY( 1, SUPR0FpuEnd), - SUPEXP_STK_BACK( 0, SUPR0SuspendVTxOnCpu), - SUPEXP_STK_BACK( 1, SUPR0ResumeVTxOnCpu), - SUPEXP_STK_OKAY( 1, SUPR0GetCurrentGdtRw), -@@ -1742,7 +1756,7 @@ - - /* execute */ - pReq->u.Out.cFunctions = RT_ELEMENTS(g_aFunctions); -- memcpy(&pReq->u.Out.aFunctions[0], g_aFunctions, sizeof(g_aFunctions)); -+ SUPDRV_MEMCPY(&pReq->u.Out.aFunctions[0], g_aFunctions, sizeof(g_aFunctions)); - pReq->Hdr.rc = VINF_SUCCESS; - return 0; - } -Index: src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp -=================================================================== ---- trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp (revision 151556) -+++ trunk/src/VBox/HostDrivers/Support/darwin/SUPDrv-darwin.cpp (working copy) -@@ -2002,6 +2002,18 @@ - } - - -+SUPR0DECL(bool) SUPR0FpuBegin(bool fCtxHook) -+{ -+ RT_NOREF(fCtxHook); -+ return false; -+} -+ -+ -+SUPR0DECL(void) SUPR0FpuEnd(bool fCtxHook) -+{ -+ RT_NOREF(fCtxHook); -+} -+ - /* - * - * org_virtualbox_SupDrv -Index: src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c -=================================================================== ---- trunk/src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c (revision 151556) -+++ trunk/src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c (working copy) -@@ -640,3 +640,16 @@ - return 0; - } - -+ -+SUPR0DECL(bool) SUPR0FpuBegin(bool fCtxHook) -+{ -+ RT_NOREF(fCtxHook); -+ return false; -+} -+ -+ -+SUPR0DECL(void) SUPR0FpuEnd(bool fCtxHook) -+{ -+ RT_NOREF(fCtxHook); -+} -+ -Index: src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c -=================================================================== ---- trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c (revision 151556) -+++ trunk/src/VBox/HostDrivers/Support/linux/SUPDrv-linux.c (working copy) -@@ -1454,6 +1454,31 @@ - } - - -+SUPR0DECL(bool) SUPR0FpuBegin(bool fCtxHook) -+{ -+ RT_NOREF(fCtxHook); -+#if RTLNX_VER_MIN(5,18,0) -+ kernel_fpu_begin(); -+ /* if (fCtxHook) */ -+ preempt_enable(); /* HACK ALERT! undo the implicit preempt_disable() in kernel_fpu_begin(). */ -+ return true; -+#else -+ return false; -+#endif -+} -+ -+ -+SUPR0DECL(void) SUPR0FpuEnd(bool fCtxHook) -+{ -+ RT_NOREF(fCtxHook); -+#if RTLNX_VER_MIN(5,18,0) -+ /* if (fCtxHook) */ -+ preempt_disable(); /* HACK ALERT! undo the implicit preempt_enable() in SUPR0FpuBegin(). */ -+ kernel_fpu_end(); -+#endif -+} -+ -+ - int VBOXCALL supdrvOSGetCurrentGdtRw(RTHCUINTPTR *pGdtRw) - { - #if RTLNX_VER_MIN(4,12,0) -Index: src/VBox/HostDrivers/Support/os2/SUPDrv-os2.cpp -=================================================================== ---- trunk/src/VBox/HostDrivers/Support/os2/SUPDrv-os2.cpp (revision 151556) -+++ trunk/src/VBox/HostDrivers/Support/os2/SUPDrv-os2.cpp (working copy) -@@ -541,3 +541,16 @@ - return 0; - } - -+ -+SUPR0DECL(bool) SUPR0FpuBegin(bool fCtxHook) -+{ -+ RT_NOREF(fCtxHook); -+ return false; -+} -+ -+ -+SUPR0DECL(void) SUPR0FpuEnd(bool fCtxHook) -+{ -+ RT_NOREF(fCtxHook); -+} -+ -Index: src/VBox/HostDrivers/Support/solaris/SUPDrv-solaris.c -=================================================================== ---- trunk/src/VBox/HostDrivers/Support/solaris/SUPDrv-solaris.c (revision 151556) -+++ trunk/src/VBox/HostDrivers/Support/solaris/SUPDrv-solaris.c (working copy) -@@ -1309,3 +1309,16 @@ - return 0; - } - -+ -+SUPR0DECL(bool) SUPR0FpuBegin(bool fCtxHook) -+{ -+ RT_NOREF(fCtxHook); -+ return false; -+} -+ -+ -+SUPR0DECL(void) SUPR0FpuEnd(bool fCtxHook) -+{ -+ RT_NOREF(fCtxHook); -+} -+ -Index: src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp -=================================================================== ---- trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp (revision 151556) -+++ trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp (working copy) -@@ -2704,6 +2704,19 @@ - } - - -+SUPR0DECL(bool) SUPR0FpuBegin(bool fCtxHook) -+{ -+ RT_NOREF(fCtxHook); -+ return false; -+} -+ -+ -+SUPR0DECL(void) SUPR0FpuEnd(bool fCtxHook) -+{ -+ RT_NOREF(fCtxHook); -+} -+ -+ - SUPR0DECL(int) SUPR0IoCtlSetupForHandle(PSUPDRVSESSION pSession, intptr_t hHandle, uint32_t fFlags, PSUPR0IOCTLCTX *ppCtx) - { - /* -Index: src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c -=================================================================== ---- trunk/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c (revision 151556) -+++ trunk/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c (working copy) -@@ -2311,7 +2311,13 @@ - vboxNetFltDumpPacket(pSG, true, "host", (fDst & INTNETTRUNKDIR_WIRE) ? 0 : 1); - Log6(("vboxNetFltPortOsXmit: pBuf->cb dump:\n%.*Rhxd\n", sizeof(pBuf->cb), pBuf->cb)); - Log6(("vboxNetFltPortOsXmit: netif_rx_ni(%p)\n", pBuf)); -+#if RTLNX_VER_MIN(5,18,0) -+ local_bh_disable(); -+ err = netif_rx(pBuf); -+ local_bh_enable(); -+#else - err = netif_rx_ni(pBuf); -+#endif - if (err) - rc = RTErrConvertFromErrno(err); - } -Index: src/VBox/VMM/VMMR0/CPUMR0.cpp -=================================================================== ---- trunk/src/VBox/VMM/VMMR0/CPUMR0.cpp (revision 151556) -+++ trunk/src/VBox/VMM/VMMR0/CPUMR0.cpp (working copy) -@@ -440,6 +440,9 @@ - Assert(!(pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)); - Assert(!(pVCpu->cpum.s.fUseFlags & CPUM_SYNC_FPU_STATE)); - -+ /* Notify the support driver prior to loading the guest-FPU register state. */ -+ SUPR0FpuBegin(false /* unused */); -+ - if (!pVM->cpum.s.HostFeatures.fLeakyFxSR) - { - Assert(!(pVCpu->cpum.s.fUseFlags & CPUM_USED_MANUAL_XMM_RESTORE)); -@@ -484,6 +487,9 @@ - Assert(ASMGetCR4() & X86_CR4_OSFXSR); - if (pVCpu->cpum.s.fUseFlags & (CPUM_USED_FPU_GUEST | CPUM_USED_FPU_HOST)) - { -+ /* Notify the support driver prior to loading the host-FPU register state. */ -+ SUPR0FpuEnd(false /* unused */); -+ - fSavedGuest = RT_BOOL(pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST); - if (!(pVCpu->cpum.s.fUseFlags & CPUM_USED_MANUAL_XMM_RESTORE)) - cpumR0SaveGuestRestoreHostFPUState(&pVCpu->cpum.s);