virtualbox: Rebase hardened.patch on top of 5.1.22

The merge of the version bump in
6fb9f892382b4b091fc9edcae00e2eb4c0729bda didn't take care of our patch
for the hardening mode and thus enabling VirtualBox without also
force-disabling hardening mode will result in a build error.

While the patch is largely identical with the old version, I've removed
one particular change around the following code:

if (pFsObjState->Stat.st_mode & S_IWOTH)
return supR3HardenedSetError3(VERR_SUPLIB_WORLD_WRITABLE, pErrInfo,
"World writable: '", pszPath, "'");

In the old version of the patch we have checked whether the path is
within the Nix store and suppressed the error return if that's the case.

The reason why I did that in the first place was because we had a bunch
of symlinks which were writable.

In VirtualBox 5.1.22 the code specifically checks whether the file is a
symlink, so we can safely drop our change.

Tested via all of the "virtualbox" NixOS VM subtests and they now all
succeed.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>

aszlig 63fb845f fa6fd34f

+19 -31
+19 -31
pkgs/applications/virtualization/virtualbox/hardened.patch
··· 1 1 diff --git a/include/iprt/mangling.h b/include/iprt/mangling.h 2 - index 70c596a..78972ed 100644 2 + index c1daa8f..8618371 100644 3 3 --- a/include/iprt/mangling.h 4 4 +++ b/include/iprt/mangling.h 5 - @@ -1068,6 +1068,7 @@ 5 + @@ -1440,6 +1440,7 @@ 6 6 # define RTPathStripSuffix RT_MANGLER(RTPathStripSuffix) 7 7 # define RTPathStripFilename RT_MANGLER(RTPathStripFilename) 8 8 # define RTPathStripTrailingSlash RT_MANGLER(RTPathStripTrailingSlash) ··· 10 10 # define RTPathTemp RT_MANGLER(RTPathTemp) 11 11 # define RTPathTraverseList RT_MANGLER(RTPathTraverseList) 12 12 # define RTPathUnlink RT_MANGLER(RTPathUnlink) 13 - @@ -1105,6 +1106,7 @@ 13 + @@ -1478,6 +1479,7 @@ 14 14 # define RTProcGetAffinityMask RT_MANGLER(RTProcGetAffinityMask) 15 15 # define RTProcGetExecutablePath RT_MANGLER(RTProcGetExecutablePath) 16 16 # define RTProcGetPriority RT_MANGLER(RTProcGetPriority) ··· 19 19 # define RTProcQueryParent RT_MANGLER(RTProcQueryParent) 20 20 # define RTProcQueryUsername RT_MANGLER(RTProcQueryUsername) 21 21 diff --git a/include/iprt/path.h b/include/iprt/path.h 22 - index 7e42754..b4de4c8 100644 22 + index 8bd42bc..2c23d3e 100644 23 23 --- a/include/iprt/path.h 24 24 +++ b/include/iprt/path.h 25 - @@ -1049,6 +1049,15 @@ RTDECL(int) RTPathCalcRelative(char *pszPathDst, size_t cbPathDst, 25 + @@ -1064,6 +1064,15 @@ RTDECL(int) RTPathCalcRelative(char *pszPathDst, size_t cbPathDst, 26 26 RTDECL(int) RTPathExecDir(char *pszPath, size_t cchPath); 27 27 28 28 /** ··· 39 39 * 40 40 * @returns iprt status code. 41 41 diff --git a/include/iprt/process.h b/include/iprt/process.h 42 - index 2760306..0ce6c92 100644 42 + index 043653e..1070280 100644 43 43 --- a/include/iprt/process.h 44 44 +++ b/include/iprt/process.h 45 - @@ -313,6 +313,16 @@ RTR3DECL(const char *) RTProcShortName(void); 45 + @@ -327,6 +327,16 @@ RTR3DECL(const char *) RTProcShortName(void); 46 46 RTR3DECL(char *) RTProcGetExecutablePath(char *pszExecPath, size_t cbExecPath); 47 47 48 48 /** ··· 60 60 * 61 61 * The way this work is that it will spawn a detached / backgrounded / 62 62 diff --git a/src/VBox/HostDrivers/Support/SUPR3HardenedVerify.cpp b/src/VBox/HostDrivers/Support/SUPR3HardenedVerify.cpp 63 - index c39d2f7..896b352 100644 63 + index ce0f288..6193108 100644 64 64 --- a/src/VBox/HostDrivers/Support/SUPR3HardenedVerify.cpp 65 65 +++ b/src/VBox/HostDrivers/Support/SUPR3HardenedVerify.cpp 66 - @@ -1415,18 +1415,19 @@ static int supR3HardenedVerifyFsObject(PCSUPR3HARDENEDFSOBJSTATE pFsObjState, bo 67 - NOREF(fRelaxed); 66 + @@ -1489,9 +1489,9 @@ static int supR3HardenedVerifyFsObject(PCSUPR3HARDENEDFSOBJSTATE pFsObjState, bo 67 + bool fBad = !fRelaxed || pFsObjState->Stat.st_gid != 2 /*bin*/ || suplibHardenedStrCmp(pszPath, "/usr/lib/iconv"); 68 68 #else 69 69 NOREF(fRelaxed); 70 70 - bool fBad = true; ··· 75 75 return supR3HardenedSetError3(VERR_SUPLIB_WRITE_NON_SYS_GROUP, pErrInfo, 76 76 "An unknown (and thus untrusted) group has write access to '", pszPath, 77 77 "' and we therefore cannot trust the directory content or that of any subdirectory"); 78 - } 79 - 80 - /* 81 - - * World must not have write access. There is no relaxing this rule. 82 - + * World must not have write access. 83 - + * There is no relaxing this rule, except when it comes to the Nix store. 84 - */ 85 - - if (pFsObjState->Stat.st_mode & S_IWOTH) 86 - + if (pFsObjState->Stat.st_mode & S_IWOTH && suplibHardenedStrCmp(pszPath, "/nix/store")) 87 - return supR3HardenedSetError3(VERR_SUPLIB_WORLD_WRITABLE, pErrInfo, 88 - "World writable: '", pszPath, "'"); 89 - 90 78 diff --git a/src/VBox/Main/src-server/MachineImpl.cpp b/src/VBox/Main/src-server/MachineImpl.cpp 91 - index 95dc9a7..39170bc 100644 79 + index 320c569..9bfe41f 100644 92 80 --- a/src/VBox/Main/src-server/MachineImpl.cpp 93 81 +++ b/src/VBox/Main/src-server/MachineImpl.cpp 94 - @@ -7326,7 +7326,7 @@ HRESULT Machine::i_launchVMProcess(IInternalSessionControl *aControl, 82 + @@ -7543,7 +7543,7 @@ HRESULT Machine::i_launchVMProcess(IInternalSessionControl *aControl, 95 83 96 84 /* get the path to the executable */ 97 85 char szPath[RTPATH_MAX]; ··· 101 89 szPath[cchBufLeft++] = RTPATH_DELIMITER; 102 90 szPath[cchBufLeft] = 0; 103 91 diff --git a/src/VBox/Main/src-server/NetworkServiceRunner.cpp b/src/VBox/Main/src-server/NetworkServiceRunner.cpp 104 - index e9e1ba62..4d1c1e1 100644 92 + index 1e38d99..5e43dda 100644 105 93 --- a/src/VBox/Main/src-server/NetworkServiceRunner.cpp 106 94 +++ b/src/VBox/Main/src-server/NetworkServiceRunner.cpp 107 - @@ -79,7 +79,7 @@ int NetworkServiceRunner::start() 95 + @@ -85,7 +85,7 @@ int NetworkServiceRunner::start(bool aKillProcOnStop) 108 96 109 97 /* get the path to the executable */ 110 98 char exePathBuf[RTPATH_MAX]; ··· 114 102 char *substrBs = strrchr(exePathBuf, '\\'); 115 103 char *suffix = substrSl ? substrSl : substrBs; 116 104 diff --git a/src/VBox/Main/src-server/generic/NetIf-generic.cpp b/src/VBox/Main/src-server/generic/NetIf-generic.cpp 117 - index 8559d2a..2177f27 100644 105 + index 98dc91a..43a819f 100644 118 106 --- a/src/VBox/Main/src-server/generic/NetIf-generic.cpp 119 107 +++ b/src/VBox/Main/src-server/generic/NetIf-generic.cpp 120 108 @@ -47,7 +47,7 @@ static int NetIfAdpCtl(const char * pcszIfName, const char *pszAddr, const char ··· 126 114 if (RT_FAILURE(rc)) 127 115 { 128 116 LogRel(("NetIfAdpCtl: failed to get program path, rc=%Rrc.\n", rc)); 129 - @@ -90,7 +90,7 @@ static int NetIfAdpCtl(HostNetworkInterface * pIf, const char *pszAddr, const ch 117 + @@ -89,7 +89,7 @@ static int NetIfAdpCtl(HostNetworkInterface * pIf, const char *pszAddr, const ch 130 118 int NetIfAdpCtlOut(const char * pcszName, const char * pcszCmd, char *pszBuffer, size_t cBufSize) 131 119 { 132 120 char szAdpCtl[RTPATH_MAX]; ··· 135 123 if (RT_FAILURE(rc)) 136 124 { 137 125 LogRel(("NetIfAdpCtlOut: Failed to get program path, rc=%Rrc\n", rc)); 138 - @@ -202,7 +202,7 @@ int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVirtualBox, 126 + @@ -201,7 +201,7 @@ int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVirtualBox, 139 127 progress.queryInterfaceTo(aProgress); 140 128 141 129 char szAdpCtl[RTPATH_MAX]; ··· 145 133 { 146 134 progress->i_notifyComplete(E_FAIL, 147 135 diff --git a/src/VBox/Runtime/r3/path.cpp b/src/VBox/Runtime/r3/path.cpp 148 - index be2ad8f..7ddf105 100644 136 + index 944848e..744a261 100644 149 137 --- a/src/VBox/Runtime/r3/path.cpp 150 138 +++ b/src/VBox/Runtime/r3/path.cpp 151 139 @@ -81,6 +81,12 @@ RTDECL(int) RTPathExecDir(char *pszPath, size_t cchPath) ··· 162 150 { 163 151 #if !defined(RT_OS_WINDOWS) && defined(RTPATH_APP_PRIVATE) 164 152 diff --git a/src/VBox/Runtime/r3/process.cpp b/src/VBox/Runtime/r3/process.cpp 165 - index 7bde6af..2656cae 100644 153 + index 2aab645..9795f21 100644 166 154 --- a/src/VBox/Runtime/r3/process.cpp 167 155 +++ b/src/VBox/Runtime/r3/process.cpp 168 156 @@ -111,6 +111,26 @@ RTR3DECL(char *) RTProcGetExecutablePath(char *pszExecPath, size_t cbExecPath)