summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosé Hiram Soltren <jsoltren@nvidia.com>2015-08-17 16:01:44 -0500
committerAaron Plattner <aplattner@nvidia.com>2015-08-31 13:58:48 -0700
commitd1f9c16b1a8187110e501c9116d21ffee25c0ba4 (patch)
tree8cf9efd84a2346d7e32a9e373e2929bb1c86cfa3 /src
parent47fd4e8ec55e37f9d9e7583090f35929bfe63937 (diff)
Use secure_getenv(3) to improve security
This patch is in response to the following security vulnerabilities (CVEs) reported to NVIDIA against libvdpau: CVE-2015-5198 CVE-2015-5199 CVE-2015-5200 To address these CVEs, this patch: - replaces all uses of getenv(3) with secure_getenv(3); - uses secure_getenv(3) when available, with a fallback option; - protects VDPAU_DRIVER against directory traversal by checking for '/' On platforms where secure_getenv(3) is not available, the C preprocessor will print a warning at compile time. Then, a preprocessor macro will replace secure_getenv(3) with our getenv_wrapper(), which utilizes the check: getuid() == geteuid() && getgid() == getegid() See getuid(2) and getgid(2) for further details. Signed-off-by: Aaron Plattner <aplattner@nvidia.com> Reviewed-by: Florian Weimer <fweimer@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/mesa_dri2.c6
-rw-r--r--src/util.h48
-rw-r--r--src/vdpau_wrapper.c28
4 files changed, 69 insertions, 14 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 0ce8460..8d28bb4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,7 @@ lib_LTLIBRARIES = libvdpau.la
libvdpau_la_SOURCES = \
vdpau_wrapper.c \
+ util.h \
$(DRI2_SOURCES)
if DRI2
diff --git a/src/mesa_dri2.c b/src/mesa_dri2.c
index 5f7146a..51e8794 100644
--- a/src/mesa_dri2.c
+++ b/src/mesa_dri2.c
@@ -1,6 +1,6 @@
/*
* Copyright © 2008 Red Hat, Inc.
- * Copyright © 2010 NVIDIA Corporation
+ * Copyright © 2010-2015 NVIDIA Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Soft-
@@ -30,6 +30,7 @@
* Authors:
* Kristian Høgsberg (krh@redhat.com)
* Modified for VDPAU by Aaron Plattner (aplattner@nvidia.com)
+ * and José Hiram Soltren (jsoltren@nvidia.com)
*/
@@ -39,6 +40,7 @@
#include <X11/extensions/extutil.h>
#include <X11/extensions/dri2proto.h>
#include "mesa_dri2.h"
+#include "util.h"
static char dri2ExtensionName[] = DRI2_NAME;
static XExtensionInfo *dri2Info;
@@ -130,7 +132,7 @@ _vdp_DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName
req->driverType = DRI2DriverVDPAU;
#ifdef DRI2DriverPrimeShift
{
- char *prime = getenv("DRI_PRIME");
+ char *prime = secure_getenv("DRI_PRIME");
if (prime) {
unsigned int primeid;
errno = 0;
diff --git a/src/util.h b/src/util.h
new file mode 100644
index 0000000..1452c06
--- /dev/null
+++ b/src/util.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2015 NVIDIA Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+
+static char * getenv_wrapper(const char *name)
+{
+ if (getuid() == geteuid() && getgid() == getegid()) {
+ return getenv(name);
+ }
+ else {
+ return NULL;
+ }
+}
+
+#ifndef HAVE_SECURE_GETENV
+# ifdef HAVE___SECURE_GETENV
+# define secure_getenv __secure_getenv
+# else
+# warning Neither secure_getenv nor __secure_getenv is available.
+# define secure_getenv getenv_wrapper
+# endif
+#endif
diff --git a/src/vdpau_wrapper.c b/src/vdpau_wrapper.c
index 8efbd39..79dcb94 100644
--- a/src/vdpau_wrapper.c
+++ b/src/vdpau_wrapper.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008-2009 NVIDIA, Corporation
+ * Copyright (c) 2008-2015 NVIDIA Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -37,6 +37,7 @@
#include "mesa_dri2.h"
#include <X11/Xlib.h>
#endif
+#include "util.h"
typedef void SetDllHandle(
void * driver_dll_handle
@@ -117,7 +118,12 @@ static VdpStatus _vdp_open_driver(
char const * vdpau_trace;
char const * func_name;
- vdpau_driver = getenv("VDPAU_DRIVER");
+ vdpau_driver = secure_getenv("VDPAU_DRIVER");
+ if (vdpau_driver) {
+ if (strchr(vdpau_driver, '/')) {
+ vdpau_driver = NULL;
+ }
+ }
if (!vdpau_driver) {
vdpau_driver = vdpau_driver_dri2 =
_vdp_get_driver_name_from_dri2(display, screen);
@@ -126,15 +132,13 @@ static VdpStatus _vdp_open_driver(
vdpau_driver = "nvidia";
}
- if (geteuid() == getuid()) {
- /* don't allow setuid apps to use VDPAU_DRIVER_PATH */
- vdpau_driver_path = getenv("VDPAU_DRIVER_PATH");
- if (vdpau_driver_path &&
- snprintf(vdpau_driver_lib, sizeof(vdpau_driver_lib),
- DRIVER_LIB_FORMAT, vdpau_driver_path, vdpau_driver) <
- sizeof(vdpau_driver_lib)) {
- _vdp_driver_dll = dlopen(vdpau_driver_lib, RTLD_NOW | RTLD_GLOBAL);
- }
+ /* Don't allow setuid apps to use VDPAU_DRIVER_PATH */
+ vdpau_driver_path = secure_getenv("VDPAU_DRIVER_PATH");
+ if (vdpau_driver_path &&
+ snprintf(vdpau_driver_lib, sizeof(vdpau_driver_lib),
+ DRIVER_LIB_FORMAT, vdpau_driver_path, vdpau_driver) <
+ sizeof(vdpau_driver_lib)) {
+ _vdp_driver_dll = dlopen(vdpau_driver_lib, RTLD_NOW | RTLD_GLOBAL);
}
/* Fallback to VDPAU_MODULEDIR when VDPAU_DRIVER_PATH is not set,
@@ -177,7 +181,7 @@ static VdpStatus _vdp_open_driver(
_vdp_backend_dll = _vdp_driver_dll;
- vdpau_trace = getenv("VDPAU_TRACE");
+ vdpau_trace = secure_getenv("VDPAU_TRACE");
if (vdpau_trace && atoi(vdpau_trace)) {
SetDllHandle * set_dll_handle;