Blame SOURCES/mod_nss-certdb-permissions.patch

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