Blame SOURCES/mod_nss-certdb-permissions.patch

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