Blame SOURCES/gssproxy-0.3.1-secure_getenv.patch

4c520e
From 1d78d1af3da7eeb15aa1f054b740f31a12f48f31 Mon Sep 17 00:00:00 2001
4c520e
From: Simo Sorce <simo@redhat.com>
4c520e
Date: Sat, 16 Nov 2013 17:08:06 -0500
4c520e
Subject: [PATCH 1/3] config: Do not modify const strings
4c520e
MIME-Version: 1.0
4c520e
Content-Type: text/plain; charset=UTF-8
4c520e
Content-Transfer-Encoding: 8bit
4c520e
4c520e
Take a copy here, the option string is const and strtok_r() is not a safe
4c520e
function as it may change the string it manipulates.
4c520e
4c520e
Reviewed-by: Günther Deschner <gdeschner@redhat.com>
4c520e
---
4c520e
 proxy/src/gp_config.c | 10 +++++++++-
4c520e
 1 file changed, 9 insertions(+), 1 deletion(-)
4c520e
4c520e
diff --git a/proxy/src/gp_config.c b/proxy/src/gp_config.c
4c520e
index e21e70d..63f264e 100644
4c520e
--- a/proxy/src/gp_config.c
4c520e
+++ b/proxy/src/gp_config.c
4c520e
@@ -209,6 +209,7 @@ static int load_services(struct gp_config *cfg, struct gp_ini_context *ctx)
4c520e
     int num_sec;
4c520e
     char *secname = NULL;
4c520e
     const char *value;
4c520e
+    char *vcopy;
4c520e
     char *token;
4c520e
     char *handle;
4c520e
     int valnum;
4c520e
@@ -318,7 +319,12 @@ static int load_services(struct gp_config *cfg, struct gp_ini_context *ctx)
4c520e
                 goto done;
4c520e
             }
4c520e
 
4c520e
-            token = strtok_r(no_const(value), ", ", &handle);
4c520e
+            vcopy = strdup(value);
4c520e
+            if (!vcopy) {
4c520e
+                ret = ENOMEM;
4c520e
+                goto done;
4c520e
+            }
4c520e
+            token = strtok_r(vcopy, ", ", &handle);
4c520e
             do {
4c520e
 
4c520e
                 ret = strcmp(value, "krb5");
4c520e
@@ -329,6 +335,7 @@ static int load_services(struct gp_config *cfg, struct gp_ini_context *ctx)
4c520e
                     } else {
4c520e
                         GPERROR("Failed to read krb5 config for %s.\n",
4c520e
                                 secname);
4c520e
+                        safefree(vcopy);
4c520e
                         return ret;
4c520e
                     }
4c520e
                 } else {
4c520e
@@ -338,6 +345,7 @@ static int load_services(struct gp_config *cfg, struct gp_ini_context *ctx)
4c520e
 
4c520e
                 token = strtok_r(NULL, ", ", &handle);
4c520e
             } while (token != NULL);
4c520e
+            safefree(vcopy);
4c520e
 
4c520e
             if (cfg->svcs[n]->mechs == 0) {
4c520e
                 GPDEBUG("No mechs found for [%s], ignoring.\n", secname);
4c520e
-- 
4c520e
1.8.3.1
4c520e
4c520e
4c520e
From a272091dfd568cb96738cc96ea01bbf7f24ee62c Mon Sep 17 00:00:00 2001
4c520e
From: Simo Sorce <simo@redhat.com>
4c520e
Date: Sat, 16 Nov 2013 18:54:28 -0500
4c520e
Subject: [PATCH 2/3] creds: Allow admins to define only client creds
4c520e
MIME-Version: 1.0
4c520e
Content-Type: text/plain; charset=UTF-8
4c520e
Content-Transfer-Encoding: 8bit
4c520e
4c520e
When a service is configured with cred_usage = initiate it is
4c520e
ok to allow only client credentials to be defined.
4c520e
4c520e
Reviewed-by: Günther Deschner <gdeschner@redhat.com>
4c520e
---
4c520e
 proxy/src/gp_creds.c | 7 ++++++-
4c520e
 1 file changed, 6 insertions(+), 1 deletion(-)
4c520e
4c520e
diff --git a/proxy/src/gp_creds.c b/proxy/src/gp_creds.c
4c520e
index 60c4e12..1ac1fac 100644
4c520e
--- a/proxy/src/gp_creds.c
4c520e
+++ b/proxy/src/gp_creds.c
4c520e
@@ -376,7 +376,12 @@ static int gp_get_cred_environment(struct gp_call_ctx *gpcall,
4c520e
      * if any. */
4c520e
     if (use_service_keytab) {
4c520e
         if (k_num == -1) {
4c520e
-            ret = EINVAL;
4c520e
+            if (ck_num == -1) {
4c520e
+                ret = EINVAL;
4c520e
+            } else {
4c520e
+                /* allow a service to define only the client keytab */
4c520e
+                ret = 0;
4c520e
+            }
4c520e
             goto done;
4c520e
         }
4c520e
         if (ck_num == -1) {
4c520e
-- 
4c520e
1.8.3.1
4c520e
4c520e
4c520e
From 23f4ee4359d10f66e1938ce6b1d92d3cc77865ff Mon Sep 17 00:00:00 2001
4c520e
From: Simo Sorce <simo@redhat.com>
4c520e
Date: Wed, 20 Nov 2013 11:58:22 -0500
4c520e
Subject: [PATCH 3/3] Use secure_getenv in client and mechglue module
4c520e
MIME-Version: 1.0
4c520e
Content-Type: text/plain; charset=UTF-8
4c520e
Content-Transfer-Encoding: 8bit
4c520e
4c520e
proxymehc.so may be used in setuid binaries so follow best security
4c520e
practices and use secure_getenv() if available.
4c520e
Fallback to poorman emulation when secure_getenv() is not available.
4c520e
4c520e
Resolves: https://fedorahosted.org/gss-proxy/ticket/110
4c520e
4c520e
Reviewed-by: Günther Deschner <gdeschner@redhat.com>
4c520e
---
4c520e
 proxy/Makefile.am               |  7 ++++---
4c520e
 proxy/configure.ac              |  2 ++
4c520e
 proxy/src/client/gpm_common.c   |  2 +-
4c520e
 proxy/src/gp_common.h           |  1 +
4c520e
 proxy/src/gp_util.c             | 20 ++++++++++++++++++++
4c520e
 proxy/src/mechglue/gss_plugin.c |  4 ++--
4c520e
 6 files changed, 30 insertions(+), 6 deletions(-)
4c520e
4c520e
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
4c520e
index 065be6e..c946421 100644
4c520e
--- a/proxy/Makefile.am
4c520e
+++ b/proxy/Makefile.am
4c520e
@@ -102,7 +102,9 @@ GP_RPCCLI_OBJ = \
4c520e
     src/client/gpm_wrap.c \
4c520e
     src/client/gpm_unwrap.c \
4c520e
     src/client/gpm_wrap_size_limit.c \
4c520e
-    src/client/gpm_common.c
4c520e
+    src/client/gpm_common.c \
4c520e
+    src/gp_util.c
4c520e
+
4c520e
 GP_MECHGLUE_OBJ = \
4c520e
     src/mechglue/gpp_accept_sec_context.c \
4c520e
     src/mechglue/gpp_acquire_cred.c \
4c520e
@@ -114,8 +116,7 @@ GP_MECHGLUE_OBJ = \
4c520e
     src/mechglue/gpp_indicate_mechs.c \
4c520e
     src/mechglue/gpp_priv_integ.c \
4c520e
     src/mechglue/gpp_misc.c \
4c520e
-    src/mechglue/gss_plugin.c \
4c520e
-    src/gp_util.c
4c520e
+    src/mechglue/gss_plugin.c
4c520e
 
4c520e
 dist_noinst_HEADERS = \
4c520e
     rpcgen/gp_rpc.h \
4c520e
diff --git a/proxy/configure.ac b/proxy/configure.ac
4c520e
index b75a1ef..a0cc4ef 100644
4c520e
--- a/proxy/configure.ac
4c520e
+++ b/proxy/configure.ac
4c520e
@@ -149,6 +149,8 @@ AC_CHECK_LIB(gssrpc, gssrpc_xdrmem_create,,
4c520e
              [$GSSAPI_LIBS $GSSRPC_LIBS])
4c520e
 AC_SUBST([GSSRPC_LIBS])
4c520e
 
4c520e
+AC_CHECK_FUNCS([__secure_getenv secure_getenv])
4c520e
+
4c520e
 WITH_INITSCRIPT
4c520e
 if test x$initscript = xsystemd; then
4c520e
     WITH_SYSTEMD_UNIT_DIR
4c520e
diff --git a/proxy/src/client/gpm_common.c b/proxy/src/client/gpm_common.c
4c520e
index df1f5a1..74296da 100644
4c520e
--- a/proxy/src/client/gpm_common.c
4c520e
+++ b/proxy/src/client/gpm_common.c
4c520e
@@ -68,7 +68,7 @@ static int get_pipe_name(struct gpm_ctx *gpmctx, char *name)
4c520e
     const char *socket;
4c520e
     int ret;
4c520e
 
4c520e
-    socket = getenv("GSSPROXY_SOCKET");
4c520e
+    socket = gp_getenv("GSSPROXY_SOCKET");
4c520e
     if (!socket) {
4c520e
         socket = GP_SOCKET_NAME;
4c520e
     }
4c520e
diff --git a/proxy/src/gp_common.h b/proxy/src/gp_common.h
4c520e
index 9e4ae81..b5c525f 100644
4c520e
--- a/proxy/src/gp_common.h
4c520e
+++ b/proxy/src/gp_common.h
4c520e
@@ -67,6 +67,7 @@
4c520e
 
4c520e
 bool gp_same(const char *a, const char *b);
4c520e
 bool gp_boolean_is_true(const char *s);
4c520e
+char *gp_getenv(const char *name);
4c520e
 
4c520e
 #include "rpcgen/gss_proxy.h"
4c520e
 
4c520e
diff --git a/proxy/src/gp_util.c b/proxy/src/gp_util.c
4c520e
index 8400da1..a6c870f 100644
4c520e
--- a/proxy/src/gp_util.c
4c520e
+++ b/proxy/src/gp_util.c
4c520e
@@ -23,8 +23,10 @@
4c520e
    DEALINGS IN THE SOFTWARE.
4c520e
 */
4c520e
 
4c520e
+#include "config.h"
4c520e
 #include <stdbool.h>
4c520e
 #include <string.h>
4c520e
+#include <stdlib.h>
4c520e
 
4c520e
 bool gp_same(const char *a, const char *b)
4c520e
 {
4c520e
@@ -46,3 +48,21 @@ bool gp_boolean_is_true(const char *s)
4c520e
 
4c520e
     return false;
4c520e
 }
4c520e
+
4c520e
+char *gp_getenv(const char *name)
4c520e
+{
4c520e
+#if HAVE_SECURE_GETENV
4c520e
+    return secure_getenv(name);
4c520e
+#elif HAVE___SECURE_GETENV
4c520e
+    return __secure_getenv(name);
4c520e
+#else
4c520e
+#include <unistd.h>
4c520e
+#include <sys/types.h>
4c520e
+#warning secure_getenv not available, falling back to poorman emulation
4c520e
+    if ((getuid() == geteuid()) &&
4c520e
+        (getgid() == getegid())) {
4c520e
+        return getenv(name);
4c520e
+    }
4c520e
+    return NULL;
4c520e
+#endif
4c520e
+}
4c520e
diff --git a/proxy/src/mechglue/gss_plugin.c b/proxy/src/mechglue/gss_plugin.c
4c520e
index 5b40df9..372ab2e 100644
4c520e
--- a/proxy/src/mechglue/gss_plugin.c
4c520e
+++ b/proxy/src/mechglue/gss_plugin.c
4c520e
@@ -64,7 +64,7 @@ enum gpp_behavior gpp_get_behavior(void)
4c520e
     char *envval;
4c520e
 
4c520e
     if (behavior == GPP_UNINITIALIZED) {
4c520e
-        envval = getenv("GSSPROXY_BEHAVIOR");
4c520e
+        envval = gp_getenv("GSSPROXY_BEHAVIOR");
4c520e
         if (envval) {
4c520e
             if (strcmp(envval, "LOCAL_ONLY") == 0) {
4c520e
                 behavior = GPP_LOCAL_ONLY;
4c520e
@@ -102,7 +102,7 @@ gss_OID_set gss_mech_interposer(gss_OID mech_type)
4c520e
 
4c520e
     /* avoid looping in the gssproxy daemon by avoiding to interpose
4c520e
      * any mechanism */
4c520e
-    envval = getenv("GSS_USE_PROXY");
4c520e
+    envval = gp_getenv("GSS_USE_PROXY");
4c520e
     if (!envval) {
4c520e
         return NULL;
4c520e
     }
4c520e
-- 
4c520e
1.8.3.1
4c520e