Blame SOURCES/glibc-rh1083646.patch

147e83
commit bc8f194c8c29e46e8ee4034f06e46988dfff38f7
147e83
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
147e83
Date:   Wed Apr 30 12:00:39 2014 +0530
147e83
147e83
    Initialize all of datahead structure in nscd (BZ #16791)
147e83
    
147e83
    The datahead structure has an unused padding field that remains
147e83
    uninitialized.  Valgrind prints out a warning for it on querying a
147e83
    netgroups entry.  This is harmless, but is a potential data leak since
147e83
    it would result in writing out an uninitialized byte to the cache
147e83
    file.  Besides, this happens only when there is a cache miss, so we're
147e83
    not adding computation to any fast path.
147e83
147e83
commit 1cdeb2372ddecac0dfe0c132a033e9590ffa07d2
147e83
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
147e83
Date:   Wed Apr 30 11:57:09 2014 +0530
147e83
147e83
    Consolidate code to initialize nscd dataset header
147e83
    
147e83
    This patch consolidates the code to initialize the header of a dataset
147e83
    into a single set of functions (one for positive and another for
147e83
    negative datasets) primarily to reduce repetition of code.  The
147e83
    secondary reason is to simplify Patch 2/2 which fixes the problem of
147e83
    an uninitialized byte in the header by initializing an unused field in
147e83
    the structure and hence preventing a possible data leak into the cache
147e83
    file.
147e83
147e83
diff --git glibc-2.17-c758a686/nscd/aicache.c glibc-2.17-c758a686/nscd/aicache.c
147e83
index 98d40a1..d7966bd 100644
147e83
--- glibc-2.17-c758a686/nscd/aicache.c
147e83
+++ glibc-2.17-c758a686/nscd/aicache.c
147e83
@@ -383,17 +383,12 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
147e83
 	  cp = family;
147e83
 	}
147e83
 
147e83
-      /* Fill in the rest of the dataset.  */
147e83
-      dataset->head.allocsize = total + req->key_len;
147e83
-      dataset->head.recsize = total - offsetof (struct dataset, resp);
147e83
-      dataset->head.notfound = false;
147e83
-      dataset->head.nreloads = he == NULL ? 0 : (dh->nreloads + 1);
147e83
-      dataset->head.usable = true;
147e83
-
147e83
-      /* Compute the timeout time.  */
147e83
-      dataset->head.ttl = ttl == INT32_MAX ? db->postimeout : ttl;
147e83
-      timeout = dataset->head.timeout = time (NULL) + dataset->head.ttl;
147e83
+      timeout = datahead_init_pos (&dataset->head, total + req->key_len,
147e83
+				   total - offsetof (struct dataset, resp),
147e83
+				   he == NULL ? 0 : dh->nreloads + 1,
147e83
+				   ttl == INT32_MAX ? db->postimeout : ttl);
147e83
 
147e83
+      /* Fill in the rest of the dataset.  */
147e83
       dataset->resp.version = NSCD_VERSION;
147e83
       dataset->resp.found = 1;
147e83
       dataset->resp.naddrs = naddrs;
147e83
@@ -528,15 +523,9 @@ next_nip:
147e83
       else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
147e83
 					      + req->key_len), 1)) != NULL)
147e83
 	{
147e83
-	  dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
147e83
-	  dataset->head.recsize = total;
147e83
-	  dataset->head.notfound = true;
147e83
-	  dataset->head.nreloads = 0;
147e83
-	  dataset->head.usable = true;
147e83
-
147e83
-	  /* Compute the timeout time.  */
147e83
-	  timeout = dataset->head.timeout = time (NULL) + db->negtimeout;
147e83
-	  dataset->head.ttl = db->negtimeout;
147e83
+	  timeout = datahead_init_neg (&dataset->head,
147e83
+				       sizeof (struct dataset) + req->key_len,
147e83
+				       total, db->negtimeout);
147e83
 
147e83
 	  /* This is the reply.  */
147e83
 	  memcpy (&dataset->resp, &notfound, total);
147e83
diff --git glibc-2.17-c758a686/nscd/grpcache.c glibc-2.17-c758a686/nscd/grpcache.c
147e83
index b5a33eb..df59fa7 100644
147e83
--- glibc-2.17-c758a686/nscd/grpcache.c
147e83
+++ glibc-2.17-c758a686/nscd/grpcache.c
147e83
@@ -128,14 +128,10 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
147e83
 	    }
147e83
 	  else if ((dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len, 1)) != NULL)
147e83
 	    {
147e83
-	      dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
147e83
-	      dataset->head.recsize = total;
147e83
-	      dataset->head.notfound = true;
147e83
-	      dataset->head.nreloads = 0;
147e83
-	      dataset->head.usable = true;
147e83
-
147e83
-	      /* Compute the timeout time.  */
147e83
-	      timeout = dataset->head.timeout = t + db->negtimeout;
147e83
+	      timeout = datahead_init_neg (&dataset->head,
147e83
+					   (sizeof (struct dataset)
147e83
+					    + req->key_len), total,
147e83
+					   db->negtimeout);
147e83
 
147e83
 	      /* This is the reply.  */
147e83
 	      memcpy (&dataset->resp, &notfound, total);
147e83
@@ -232,14 +228,10 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
147e83
 	  dataset_temporary = true;
147e83
 	}
147e83
 
147e83
-      dataset->head.allocsize = total + n;
147e83
-      dataset->head.recsize = total - offsetof (struct dataset, resp);
147e83
-      dataset->head.notfound = false;
147e83
-      dataset->head.nreloads = he == NULL ? 0 : (dh->nreloads + 1);
147e83
-      dataset->head.usable = true;
147e83
-
147e83
-      /* Compute the timeout time.  */
147e83
-      timeout = dataset->head.timeout = t + db->postimeout;
147e83
+      timeout = datahead_init_pos (&dataset->head, total + n,
147e83
+				   total - offsetof (struct dataset, resp),
147e83
+				   he == NULL ? 0 : dh->nreloads + 1,
147e83
+				   db->postimeout);
147e83
 
147e83
       dataset->resp.version = NSCD_VERSION;
147e83
       dataset->resp.found = 1;
147e83
diff --git glibc-2.17-c758a686/nscd/hstcache.c glibc-2.17-c758a686/nscd/hstcache.c
147e83
index a79b67a..d4f1ad2 100644
147e83
--- glibc-2.17-c758a686/nscd/hstcache.c
147e83
+++ glibc-2.17-c758a686/nscd/hstcache.c
147e83
@@ -152,15 +152,11 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req,
147e83
 	  else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
147e83
 						  + req->key_len), 1)) != NULL)
147e83
 	    {
147e83
-	      dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
147e83
-	      dataset->head.recsize = total;
147e83
-	      dataset->head.notfound = true;
147e83
-	      dataset->head.nreloads = 0;
147e83
-	      dataset->head.usable = true;
147e83
-
147e83
-	      /* Compute the timeout time.  */
147e83
-	      dataset->head.ttl = ttl == INT32_MAX ? db->negtimeout : ttl;
147e83
-	      timeout = dataset->head.timeout = t + dataset->head.ttl;
147e83
+	      timeout = datahead_init_neg (&dataset->head,
147e83
+					   (sizeof (struct dataset)
147e83
+					    + req->key_len), total,
147e83
+					   (ttl == INT32_MAX
147e83
+					    ? db->negtimeout : ttl));
147e83
 
147e83
 	      /* This is the reply.  */
147e83
 	      memcpy (&dataset->resp, resp, total);
147e83
@@ -257,15 +253,10 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req,
147e83
 	  alloca_used = true;
147e83
 	}
147e83
 
147e83
-      dataset->head.allocsize = total + req->key_len;
147e83
-      dataset->head.recsize = total - offsetof (struct dataset, resp);
147e83
-      dataset->head.notfound = false;
147e83
-      dataset->head.nreloads = he == NULL ? 0 : (dh->nreloads + 1);
147e83
-      dataset->head.usable = true;
147e83
-
147e83
-      /* Compute the timeout time.  */
147e83
-      dataset->head.ttl = ttl == INT32_MAX ? db->postimeout : ttl;
147e83
-      timeout = dataset->head.timeout = t + dataset->head.ttl;
147e83
+      timeout = datahead_init_pos (&dataset->head, total + req->key_len,
147e83
+				   total - offsetof (struct dataset, resp),
147e83
+				   he == NULL ? 0 : dh->nreloads + 1,
147e83
+				   ttl == INT32_MAX ? db->postimeout : ttl);
147e83
 
147e83
       dataset->resp.version = NSCD_VERSION;
147e83
       dataset->resp.found = 1;
147e83
diff --git glibc-2.17-c758a686/nscd/initgrcache.c glibc-2.17-c758a686/nscd/initgrcache.c
147e83
index 1bf9f0d..361319f 100644
147e83
--- glibc-2.17-c758a686/nscd/initgrcache.c
147e83
+++ glibc-2.17-c758a686/nscd/initgrcache.c
147e83
@@ -213,14 +213,10 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
147e83
 	  else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
147e83
 						  + req->key_len), 1)) != NULL)
147e83
 	    {
147e83
-	      dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
147e83
-	      dataset->head.recsize = total;
147e83
-	      dataset->head.notfound = true;
147e83
-	      dataset->head.nreloads = 0;
147e83
-	      dataset->head.usable = true;
147e83
-
147e83
-	      /* Compute the timeout time.  */
147e83
-	      timeout = dataset->head.timeout = time (NULL) + db->negtimeout;
147e83
+	      timeout = datahead_init_neg (&dataset->head,
147e83
+					   (sizeof (struct dataset)
147e83
+					    + req->key_len), total,
147e83
+					   db->negtimeout);
147e83
 
147e83
 	      /* This is the reply.  */
147e83
 	      memcpy (&dataset->resp, &notfound, total);
147e83
@@ -276,14 +272,10 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
147e83
 	  alloca_used = true;
147e83
 	}
147e83
 
147e83
-      dataset->head.allocsize = total + req->key_len;
147e83
-      dataset->head.recsize = total - offsetof (struct dataset, resp);
147e83
-      dataset->head.notfound = false;
147e83
-      dataset->head.nreloads = he == NULL ? 0 : (dh->nreloads + 1);
147e83
-      dataset->head.usable = true;
147e83
-
147e83
-      /* Compute the timeout time.  */
147e83
-      timeout = dataset->head.timeout = time (NULL) + db->postimeout;
147e83
+      timeout = datahead_init_pos (&dataset->head, total + req->key_len,
147e83
+				   total - offsetof (struct dataset, resp),
147e83
+				   he == NULL ? 0 : dh->nreloads + 1,
147e83
+				   db->postimeout);
147e83
 
147e83
       dataset->resp.version = NSCD_VERSION;
147e83
       dataset->resp.found = 1;
147e83
diff --git glibc-2.17-c758a686/nscd/netgroupcache.c glibc-2.17-c758a686/nscd/netgroupcache.c
147e83
index 820d823..b3d40e9 100644
147e83
--- glibc-2.17-c758a686/nscd/netgroupcache.c
147e83
+++ glibc-2.17-c758a686/nscd/netgroupcache.c
147e83
@@ -90,15 +90,9 @@ do_notfound (struct database_dyn *db, int fd, request_header *req,
147e83
   /* If we cannot permanently store the result, so be it.  */
147e83
   if (dataset != NULL)
147e83
     {
147e83
-      dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
147e83
-      dataset->head.recsize = total;
147e83
-      dataset->head.notfound = true;
147e83
-      dataset->head.nreloads = 0;
147e83
-      dataset->head.usable = true;
147e83
-
147e83
-      /* Compute the timeout time.  */
147e83
-      timeout = dataset->head.timeout = time (NULL) + db->negtimeout;
147e83
-      dataset->head.ttl = db->negtimeout;
147e83
+      timeout = datahead_init_neg (&dataset->head,
147e83
+				   sizeof (struct dataset) + req->key_len,
147e83
+				   total, db->negtimeout);
147e83
 
147e83
       /* This is the reply.  */
147e83
       memcpy (&dataset->resp, &notfound, total);
147e83
@@ -359,13 +353,10 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
147e83
 
147e83
   /* Fill in the dataset.  */
147e83
   dataset = (struct dataset *) buffer;
147e83
-  dataset->head.allocsize = total + req->key_len;
147e83
-  dataset->head.recsize = total - offsetof (struct dataset, resp);
147e83
-  dataset->head.notfound = false;
147e83
-  dataset->head.nreloads = he == NULL ? 0 : (dh->nreloads + 1);
147e83
-  dataset->head.usable = true;
147e83
-  dataset->head.ttl = db->postimeout;
147e83
-  timeout = dataset->head.timeout = time (NULL) + dataset->head.ttl;
147e83
+  timeout = datahead_init_pos (&dataset->head, total + req->key_len,
147e83
+			       total - offsetof (struct dataset, resp),
147e83
+			       he == NULL ? 0 : dh->nreloads + 1,
147e83
+			       db->postimeout);
147e83
 
147e83
   dataset->resp.version = NSCD_VERSION;
147e83
   dataset->resp.found = 1;
147e83
@@ -541,12 +532,12 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,
147e83
       dataset = &dataset_mem;
147e83
     }
147e83
 
147e83
-  dataset->head.allocsize = sizeof (*dataset) + req->key_len;
147e83
-  dataset->head.recsize = sizeof (innetgroup_response_header);
147e83
+  datahead_init_pos (&dataset->head, sizeof (*dataset) + req->key_len,
147e83
+		     sizeof (innetgroup_response_header),
147e83
+		     he == NULL ? 0 : dh->nreloads + 1, result->head.ttl);
147e83
+  /* Set the notfound status and timeout based on the result from
147e83
+     getnetgrent.  */
147e83
   dataset->head.notfound = result->head.notfound;
147e83
-  dataset->head.nreloads = he == NULL ? 0 : (dh->nreloads + 1);
147e83
-  dataset->head.usable = true;
147e83
-  dataset->head.ttl = result->head.ttl;
147e83
   dataset->head.timeout = timeout;
147e83
 
147e83
   dataset->resp.version = NSCD_VERSION;
147e83
diff --git glibc-2.17-c758a686/nscd/nscd-client.h glibc-2.17-c758a686/nscd/nscd-client.h
147e83
index 98f77e7..ee16df6 100644
147e83
--- glibc-2.17-c758a686/nscd/nscd-client.h
147e83
+++ glibc-2.17-c758a686/nscd/nscd-client.h
147e83
@@ -236,6 +236,48 @@ struct datahead
147e83
   } data[0];
147e83
 };
147e83
 
147e83
+static inline time_t
147e83
+datahead_init_common (struct datahead *head, nscd_ssize_t allocsize,
147e83
+		      nscd_ssize_t recsize, uint32_t ttl)
147e83
+{
147e83
+  /* Initialize so that we don't write out junk in uninitialized data to the
147e83
+     cache.  */
147e83
+  memset (head, 0, sizeof (*head));
147e83
+
147e83
+  head->allocsize = allocsize;
147e83
+  head->recsize = recsize;
147e83
+  head->usable = true;
147e83
+
147e83
+  head->ttl = ttl;
147e83
+
147e83
+  /* Compute and return the timeout time.  */
147e83
+  return head->timeout = time (NULL) + ttl;
147e83
+}
147e83
+
147e83
+static inline time_t
147e83
+datahead_init_pos (struct datahead *head, nscd_ssize_t allocsize,
147e83
+		   nscd_ssize_t recsize, uint8_t nreloads, uint32_t ttl)
147e83
+{
147e83
+  time_t ret = datahead_init_common (head, allocsize, recsize, ttl);
147e83
+
147e83
+  head->notfound = false;
147e83
+  head->nreloads = nreloads;
147e83
+
147e83
+  return ret;
147e83
+}
147e83
+
147e83
+static inline time_t
147e83
+datahead_init_neg (struct datahead *head, nscd_ssize_t allocsize,
147e83
+		   nscd_ssize_t recsize, uint32_t ttl)
147e83
+{
147e83
+  time_t ret = datahead_init_common (head, allocsize, recsize, ttl);
147e83
+
147e83
+  /* We don't need to touch nreloads here since it is set to our desired value
147e83
+     (0) when we clear the structure.  */
147e83
+  head->notfound = true;
147e83
+
147e83
+  return ret;
147e83
+}
147e83
 
147e83
 /* Structure for one hash table entry.  */
147e83
 struct hashentry
147e83
diff --git glibc-2.17-c758a686/nscd/pwdcache.c glibc-2.17-c758a686/nscd/pwdcache.c
147e83
index fa355c3..41c245b 100644
147e83
--- glibc-2.17-c758a686/nscd/pwdcache.c
147e83
+++ glibc-2.17-c758a686/nscd/pwdcache.c
147e83
@@ -135,14 +135,10 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
147e83
 	  else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
147e83
 						  + req->key_len), 1)) != NULL)
147e83
 	    {
147e83
-	      dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
147e83
-	      dataset->head.recsize = total;
147e83
-	      dataset->head.notfound = true;
147e83
-	      dataset->head.nreloads = 0;
147e83
-	      dataset->head.usable = true;
147e83
-
147e83
-	      /* Compute the timeout time.  */
147e83
-	      timeout = dataset->head.timeout = t + db->negtimeout;
147e83
+	      timeout = datahead_init_neg (&dataset->head,
147e83
+					   (sizeof (struct dataset)
147e83
+					    + req->key_len), total,
147e83
+					   db->negtimeout);
147e83
 
147e83
 	      /* This is the reply.  */
147e83
 	      memcpy (&dataset->resp, &notfound, total);
147e83
@@ -215,14 +211,10 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
147e83
 	  alloca_used = true;
147e83
 	}
147e83
 
147e83
-      dataset->head.allocsize = total + n;
147e83
-      dataset->head.recsize = total - offsetof (struct dataset, resp);
147e83
-      dataset->head.notfound = false;
147e83
-      dataset->head.nreloads = he == NULL ? 0 : (dh->nreloads + 1);
147e83
-      dataset->head.usable = true;
147e83
-
147e83
-      /* Compute the timeout time.  */
147e83
-      timeout = dataset->head.timeout = t + db->postimeout;
147e83
+      timeout = datahead_init_pos (&dataset->head, total + n,
147e83
+				   total - offsetof (struct dataset, resp),
147e83
+				   he == NULL ? 0 : dh->nreloads + 1,
147e83
+				   db->postimeout);
147e83
 
147e83
       dataset->resp.version = NSCD_VERSION;
147e83
       dataset->resp.found = 1;
147e83
diff --git glibc-2.17-c758a686/nscd/servicescache.c glibc-2.17-c758a686/nscd/servicescache.c
147e83
index 12ce9b2..95bdcfe 100644
147e83
--- glibc-2.17-c758a686/nscd/servicescache.c
147e83
+++ glibc-2.17-c758a686/nscd/servicescache.c
147e83
@@ -120,14 +120,10 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
147e83
 	  else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
147e83
 						  + req->key_len), 1)) != NULL)
147e83
 	    {
147e83
-	      dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
147e83
-	      dataset->head.recsize = total;
147e83
-	      dataset->head.notfound = true;
147e83
-	      dataset->head.nreloads = 0;
147e83
-	      dataset->head.usable = true;
147e83
-
147e83
-	      /* Compute the timeout time.  */
147e83
-	      timeout = dataset->head.timeout = t + db->negtimeout;
147e83
+	      timeout = datahead_init_neg (&dataset->head,
147e83
+					   (sizeof (struct dataset)
147e83
+					    + req->key_len), total,
147e83
+					   db->negtimeout);
147e83
 
147e83
 	      /* This is the reply.  */
147e83
 	      memcpy (&dataset->resp, &notfound, total);
147e83
@@ -207,14 +203,10 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
147e83
 	  alloca_used = true;
147e83
 	}
147e83
 
147e83
-      dataset->head.allocsize = total + req->key_len;
147e83
-      dataset->head.recsize = total - offsetof (struct dataset, resp);
147e83
-      dataset->head.notfound = false;
147e83
-      dataset->head.nreloads = he == NULL ? 0 : (dh->nreloads + 1);
147e83
-      dataset->head.usable = true;
147e83
-
147e83
-      /* Compute the timeout time.  */
147e83
-      timeout = dataset->head.timeout = t + db->postimeout;
147e83
+      timeout = datahead_init_pos (&dataset->head, total + req->key_len,
147e83
+				   total - offsetof (struct dataset, resp),
147e83
+				   he == NULL ? 0 : dh->nreloads + 1,
147e83
+				   db->postimeout);
147e83
 
147e83
       dataset->resp.version = NSCD_VERSION;
147e83
       dataset->resp.found = 1;