[vbox-dev] NetBSD patch 0015: Implement getting program name for NetBSD in SUPR3HardenedMain

Kamil Rytarowski n54 at gmx.com
Sat Aug 13 15:32:50 GMT 2016


Implement getting program name for NetBSD in SUPR3HardenedMain

The sysctl(7) version is compatible with NetBSD pre-8.0. Older releases
will need to fallback to procfs way similar to Linux. Older versions are
not planned right now to be supported.

PVM is an internal symbol on NetBSD and it conflicts with PVM from VBox.
The NetBSD one needs to be undefined in order make VBox build properly.

This patch is MIT-licensed.

Author: Kamil Rytarowski
-------------- next part --------------
Implement getting program name for NetBSD in SUPR3HardenedMain

The sysctl(7) version is compatible with NetBSD pre-8.0. Older releases will
need to fallback to procfs way similar to Linux. Older versions are not planned
right now to be supported.

PVM is an internal symbol on NetBSD and it conflicts with PVM from VBox.
The NetBSD one needs to be undefined in order make VBox build properly.

This patch is MIT-licensed.

Author: Kamil Rytarowski

Index: src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
===================================================================
--- src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp	(wersja 63343)
+++ src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp	(kopia robocza)
@@ -425,9 +425,12 @@
 #  ifndef CAP_TO_MASK
 #   define CAP_TO_MASK(cap) RT_BIT(cap)
 #  endif
-# elif defined(RT_OS_FREEBSD)
+# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
 #  include <sys/param.h>
 #  include <sys/sysctl.h>
+#  ifdef PVM
+#   undef PVM
+#  endif
 # elif defined(RT_OS_SOLARIS)
 #  include <priv.h>
 # endif
@@ -1221,7 +1224,7 @@
      *
      * Darwin, OS/2 and Windows all have proper APIs for getting the program file name.
      */
-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD) || defined(RT_OS_SOLARIS)
 # ifdef RT_OS_LINUX
     int cchLink = readlink("/proc/self/exe", &g_szSupLibHardenedExePath[0], sizeof(g_szSupLibHardenedExePath) - 1);
 
@@ -1230,12 +1233,19 @@
     sprintf(szFileBuf, "/proc/%ld/path/a.out", (long)getpid());
     int cchLink = readlink(szFileBuf, &g_szSupLibHardenedExePath[0], sizeof(g_szSupLibHardenedExePath) - 1);
 
-# else /* RT_OS_FREEBSD */
+# else /* RT_OS_FREEBSD || RT_OS_NETBSD */
     int aiName[4];
+#  if defined(RT_OS_FREEBSD)
     aiName[0] = CTL_KERN;
     aiName[1] = KERN_PROC;
     aiName[2] = KERN_PROC_PATHNAME;
     aiName[3] = getpid();
+#  else /* RT_OS_NETBSD */
+    aiName[0] = CTL_KERN;
+    aiName[1] = KERN_PROC_ARGS;
+    aiName[2] = getpid();
+    aiName[3] = KERN_PROC_PATHNAME;
+#  endif
 
     size_t cbPath = sizeof(g_szSupLibHardenedExePath);
     if (sysctl(aiName, RT_ELEMENTS(aiName), g_szSupLibHardenedExePath, &cbPath, NULL, 0) < 0)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20160813/7bd7798e/attachment.sig>


More information about the vbox-dev mailing list