]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
wcsmbs: Fix data race in __wcsmbs_clone_conv [BZ #24584]
authorFlorian Weimer <fweimer@redhat.com>
Tue, 21 May 2019 08:19:46 +0000 (10:19 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 21 May 2019 10:04:55 +0000 (12:04 +0200)
This also adds an overflow check and documents the synchronization
requirement in <gconv.h>.

ChangeLog
iconv/gconv.h
wcsmbs/wcsmbsload.c

index 1dcb620e9a8ef7e060def9f10fe43983a6696eaa..35e6f7c322354b5e223ad2cc1377aace87574ad9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2019-05-21  Florian Weimer  <fweimer@redhat.com>
+
+       [BZ #24584]
+       * wcsmbs/wcsmbsload.c (__wcsmbs_clone_conv): Acquire __gconv_lock
+       before updating __counter field and release it afterwards.  Add
+       overflow check.
+       * iconv/gconv.h (struct __gconv_step): Mention synchronization
+       requirement for __counter member.
+
 2019-05-21  Florian Weimer  <fweimer@redhat.com>
 
        [BZ #24583]
index 5ad26c06ace9ac192264590f82cdd00f9ed001e4..7ce79bcbf68bb98103becc212038aca1eb2a6739 100644 (file)
@@ -86,6 +86,8 @@ struct __gconv_step
   struct __gconv_loaded_object *__shlib_handle;
   const char *__modname;
 
+  /* For internal use by glibc.  (Accesses to this member must occur
+     when the internal __gconv_lock mutex is acquired).  */
   int __counter;
 
   char *__from_name;
index 10e1a4f4f53ca7304b73b1c3e6ae5e3dc899648f..840d4abc440e10765998b6b4d4eebecf3a8c6fa0 100644 (file)
@@ -20,6 +20,7 @@
 #include <langinfo.h>
 #include <limits.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 
 #include <locale/localeinfo.h>
@@ -223,12 +224,25 @@ __wcsmbs_clone_conv (struct gconv_fcts *copy)
   /* Copy the data.  */
   *copy = *orig;
 
-  /* Now increment the usage counters.
-     Note: This assumes copy->*_nsteps == 1.  */
+  /* Now increment the usage counters.  Note: This assumes
+     copy->*_nsteps == 1.  The current locale holds a reference, so it
+     is still there after acquiring the lock.  */
+
+  __libc_lock_lock (__gconv_lock);
+
+  bool overflow = false;
   if (copy->towc->__shlib_handle != NULL)
-    ++copy->towc->__counter;
+    overflow |= __builtin_add_overflow (copy->towc->__counter, 1,
+                                       &copy->towc->__counter);
   if (copy->tomb->__shlib_handle != NULL)
-    ++copy->tomb->__counter;
+    overflow |= __builtin_add_overflow (copy->tomb->__counter, 1,
+                                       &copy->tomb->__counter);
+
+  __libc_lock_unlock (__gconv_lock);
+
+  if (overflow)
+    __libc_fatal ("\
+Fatal glibc error: gconv module reference counter overflow\n");
 }