Blame SOURCES/mod_nss-certdb-permissions.patch

88aca9
From 7c08aa9b0aa10f4d13e7317c9a7353399188dba4 Mon Sep 17 00:00:00 2001
88aca9
From: Rob Crittenden <rcritten@redhat.com>
88aca9
Date: Wed, 21 Sep 2016 13:45:25 -0400
88aca9
Subject: [PATCH] Enhance checking on NSS database permissions to include
88aca9
 directory
88aca9
88aca9
Previously I was checking the NSS database files for readability
88aca9
but not the database directory itself. Since it starts as root if
88aca9
the directory permissions didn't allow read by the Apache user but
88aca9
the files themselves did then startup would continue but blow
88aca9
up due to the inability to chdir into the directory.
88aca9
88aca9
BZ #1312583
88aca9
---
88aca9
 nss_engine_init.c | 25 ++++++++++++++++---------
88aca9
 1 file changed, 16 insertions(+), 9 deletions(-)
88aca9
88aca9
diff --git a/nss_engine_init.c b/nss_engine_init.c
88aca9
index cd71989..03ac644 100644
88aca9
--- a/nss_engine_init.c
88aca9
+++ b/nss_engine_init.c
88aca9
@@ -51,8 +51,7 @@ static char *version_components[] = {
88aca9
     NULL
88aca9
 };
88aca9
 
88aca9
-/* See if a uid or gid can read a file at a given path. Ignore world
88aca9
- * read permissions.
88aca9
+/* See if a uid or gid can read a file at a given path.
88aca9
  *
88aca9
  * Return 0 on failure or file doesn't exist
88aca9
  * Return 1 on success
88aca9
@@ -65,14 +64,14 @@ static int check_path(uid_t uid, gid_t gid, char *filepath, apr_pool_t *p)
88aca9
     if ((rv = apr_stat(&finfo, filepath, APR_FINFO_PROT | APR_FINFO_OWNER,
88aca9
          p)) == APR_SUCCESS) {
88aca9
         if (((uid == finfo.user) &&
88aca9
-            ((finfo.protection & APR_FPROT_UREAD))) ||
88aca9
+            (finfo.protection & APR_FPROT_UREAD)) ||
88aca9
             ((gid == finfo.group) &&
88aca9
-                ((finfo.protection & APR_FPROT_GREAD)))
88aca9
+                (finfo.protection & APR_FPROT_GREAD)) ||
88aca9
+            (finfo.protection & APR_FPROT_WREAD)
88aca9
            )
88aca9
         {
88aca9
             return 1;
88aca9
         }
88aca9
-        return 0;
88aca9
     }
88aca9
     return 0;
88aca9
 }
88aca9
@@ -158,6 +157,11 @@ static void nss_init_SSLLibrary(server_rec *base_server, apr_pool_t *p)
88aca9
         }
88aca9
     }
88aca9
 
88aca9
+    if (strncasecmp(mc->pCertificateDatabase, "sql:", 4) == 0)
88aca9
+        dbdir = (char *)mc->pCertificateDatabase + 4;
88aca9
+    else
88aca9
+        dbdir = (char *)mc->pCertificateDatabase;
88aca9
+
88aca9
     /* Assuming everything is ok so far, check the cert database permissions
88aca9
      * for the server user before Apache starts forking. We die now or
88aca9
      * get stuck in an endless loop not able to read the NSS database.
88aca9
@@ -172,6 +176,13 @@ static void nss_init_SSLLibrary(server_rec *base_server, apr_pool_t *p)
88aca9
                 "Checking permissions for user %s: uid %d gid %d",
88aca9
                 mc->user, pw->pw_uid, pw->pw_gid);
88aca9
 
88aca9
+            if (!(check_path(pw->pw_uid, pw->pw_gid, dbdir, p))) {
88aca9
+                ap_log_error(APLOG_MARK, APLOG_ERR, 0, base_server,
88aca9
+                    "Server user %s lacks read access to NSS "
88aca9
+                    "database directory %s.", mc->user, dbdir);
88aca9
+                nss_die();
88aca9
+            }
88aca9
+
88aca9
             if (strncasecmp(mc->pCertificateDatabase, "sql:", 4) == 0) {
88aca9
                 apr_snprintf(filepath, 1024, "%s/key4.db",
88aca9
                              mc->pCertificateDatabase+4);
88aca9
@@ -231,10 +242,6 @@ static void nss_init_SSLLibrary(server_rec *base_server, apr_pool_t *p)
88aca9
             else
88aca9
                 return;
88aca9
     }
88aca9
-    if (strncasecmp(mc->pCertificateDatabase, "sql:", 4) == 0)
88aca9
-        dbdir = (char *)mc->pCertificateDatabase + 4;
88aca9
-    else
88aca9
-        dbdir = (char *)mc->pCertificateDatabase;
88aca9
     if (chdir(dbdir) != 0) {
88aca9
         ap_log_error(APLOG_MARK, APLOG_ERR, 0, base_server,
88aca9
             "Unable to change directory to %s", mc->pCertificateDatabase);
88aca9
-- 
88aca9
2.5.5
88aca9