[zorp-hu] zorp gpl 2.1.7 memory leak

Balazs Scheidler zorp-hu@lists.balabit.hu
Wed, 09 Jun 2004 20:13:32 +0200


--=-r63W3jLt8ZEPuepqFtyl
Content-Type: text/plain; charset=iso-8859-2
Content-Transfer-Encoding: 8bit

hali,

backportoltam egy libc 2.3-as javitast, ami ezzel kapcsolatos. ez
"elvileg" javitja a problemat. Binaris csomagot meg csak privat gepen
generaltam, ugy nez ki mukodik. Holnap megprobalom beleszuszakolni a
ZorpOS-be is.

A patch attachban (debianos glibc 2.2.5-11.5-osre megy fel)


2004-06-09, sze keltezéssel 14:43-kor Balazs Scheidler ezt írta:
> 2004-06-09, sze keltezéssel 13:52-kor narancs ezt írta:
> > Szia,
> > 
> > toletek van a binaris. woody + apt balabit sources.list
> > 
> > deb ftp://ftp.debian.org/debian woody main contrib non-free
> > deb ftp://ftp.debian.org/debian-non-US woody/non-US main contrib non-free
> > deb ftp://ftp.debian.org/debian-security woody/updates main contrib non-free
> > deb http://apt.balabit.hu/zorp-gpl-os 2.1 main zorp-os zorp-common 
> > zorp-gpl zorp-os-extra
> > 
> > ii  libzorpll            2.1.12.3-1           Low level library 
> > functions for Zorp
> > ii  zorp                 2.1.7                An advanced protocol 
> > analyzing firewall
> > ii  zorp-doc             2.1.7                Zorp documentation.
> > ii  zorp-modules         2.1.7                Default proxy modules for Zorp
> > ii  libc6          2.2.5-11.5     GNU C Library: Shared libraries and 
> > Timezone
> > 
> > azota megint 96M eppen 1 process. amig nem volt non-trans http addig ez 
> > a memleak sem volt.
> > ha toletek van a binaris, akkor gondolom jo.
> > downgradeljek 2.0.9-re vagy az is lukas?
> 
> ha libc leak, akkor hiaba. megprobalom reprodukalni nalunk.
-- 
Bazsi
PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1


--=-r63W3jLt8ZEPuepqFtyl
Content-Disposition: attachment; filename=glibc-2.2.5-resolv-leak-backport.diff
Content-Type: text/x-patch; name=glibc-2.2.5-resolv-leak-backport.diff; charset=iso-8859-2
Content-Transfer-Encoding: 7bit

diff -urN --exclude manual glibc-2.2.5/Versions.def glibc-2.2.5-leakfix/Versions.def
--- glibc-2.2.5/Versions.def	Wed Jun  9 18:04:30 2004
+++ glibc-2.2.5-leakfix/Versions.def	Wed Jun  9 17:40:11 2004
@@ -21,6 +21,7 @@
 %ifdef EXPORT_UNWIND_FIND_FDE
   GCC_3.0
 %endif
+  GLIBC_PRIVATE
 }
 libcrypt {
   GLIBC_2.0
diff -urN --exclude manual glibc-2.2.5/include/libc-internal.h glibc-2.2.5-leakfix/include/libc-internal.h
--- glibc-2.2.5/include/libc-internal.h	Tue Apr 24 01:23:58 2001
+++ glibc-2.2.5-leakfix/include/libc-internal.h	Wed Jun  9 17:12:50 2004
@@ -26,4 +26,7 @@
 /* Free all allocated resources.  */
 extern void __libc_freeres (void);
 
+/* Free resources stored in thread-local variables on thread exit.  */
+extern void __libc_thread_freeres (void);
+
 #endif /* _LIBC_INTERNAL  */
diff -urN --exclude manual glibc-2.2.5/linuxthreads/cancel.c glibc-2.2.5-leakfix/linuxthreads/cancel.c
--- glibc-2.2.5/linuxthreads/cancel.c	Fri Sep  7 17:46:13 2001
+++ glibc-2.2.5-leakfix/linuxthreads/cancel.c	Wed Jun  9 17:36:03 2004
@@ -15,7 +15,7 @@
 /* Thread cancellation */
 
 #include <errno.h>
-#include <rpc/rpc.h>
+#include <libc-internal.h>
 #include "pthread.h"
 #include "internals.h"
 #include "spinlock.h"
@@ -202,8 +202,8 @@
     }
 
   /* And the TSD which needs special help.  */
-  if (THREAD_GETMEM(self, p_libc_specific[_LIBC_TSD_KEY_RPC_VARS]) != NULL)
-    __rpc_thread_destroy ();
+  __libc_thread_freeres ();
+
 }
 
 #ifndef SHARED
diff -urN --exclude manual glibc-2.2.5/malloc/Makefile glibc-2.2.5-leakfix/malloc/Makefile
--- glibc-2.2.5/malloc/Makefile	Fri Sep  7 17:58:31 2001
+++ glibc-2.2.5-leakfix/malloc/Makefile	Wed Jun  9 17:12:50 2004
@@ -51,7 +51,7 @@
 extra-objs = mcheck-init.o libmcheck.a
 
 # Include the cleanup handler.
-aux := set-freeres
+aux := set-freeres thread-freeres
 
 include ../Makeconfig
 
diff -urN --exclude manual glibc-2.2.5/malloc/Versions glibc-2.2.5-leakfix/malloc/Versions
--- glibc-2.2.5/malloc/Versions	Thu Apr 27 13:36:41 2000
+++ glibc-2.2.5-leakfix/malloc/Versions	Wed Jun  9 17:40:42 2004
@@ -55,4 +55,7 @@
     # p*
     posix_memalign;
   }
+  GLIBC_PRIVATE {
+    __libc_thread_freeres;
+  }
 }
diff -urN --exclude manual glibc-2.2.5/malloc/thread-freeres.c glibc-2.2.5-leakfix/malloc/thread-freeres.c
--- glibc-2.2.5/malloc/thread-freeres.c	Thu Jan  1 00:00:00 1970
+++ glibc-2.2.5-leakfix/malloc/thread-freeres.c	Wed Jun  9 17:12:50 2004
@@ -0,0 +1,32 @@
+/* Free resources stored in thread-local variables on thread exit.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <stdlib.h>
+#include <libc-internal.h>
+#include <set-hooks.h>
+
+#ifdef _LIBC_REENTRANT
+DEFINE_HOOK (__libc_thread_subfreeres, (void));
+
+void __attribute__ ((section ("__libc_thread_freeres_fn")))
+__libc_thread_freeres (void)
+{
+  RUN_HOOK (__libc_thread_subfreeres, ());
+}
+#endif
diff -urN --exclude manual glibc-2.2.5/resolv/res_init.c glibc-2.2.5-leakfix/resolv/res_init.c
--- glibc-2.2.5/resolv/res_init.c	Sun Jul 22 20:24:53 2001
+++ glibc-2.2.5-leakfix/resolv/res_init.c	Wed Jun  9 17:16:42 2004
@@ -550,3 +550,29 @@
 	}
 	statp->_u._ext.nsinit = 0;
 }
+
+#ifdef _LIBC
+# ifdef _LIBC_REENTRANT
+/* This is called when a thread is exiting to free resources held in _res.  */
+static void __attribute__ ((section ("__libc_thread_freeres_fn")))
+res_thread_freeres (void)
+{
+  int ns;
+
+  if (_res.nscount == 0)
+    /* Never called res_ninit.  */
+    return;
+                                                                                                                                       
+  __res_nclose (&_res);         /* Close any VC sockets.  */
+                                                                                                                                       
+  for (ns = 0; ns < MAXNS; ns++)
+    if (_res._u._ext.nsaddrs[ns] != NULL)
+      {
+        free (_res._u._ext.nsaddrs[ns]);
+        _res._u._ext.nsaddrs[ns] = NULL;
+      }
+}
+text_set_element (__libc_thread_subfreeres, res_thread_freeres);
+text_set_element (__libc_subfreeres, res_thread_freeres);
+# endif
+#endif
diff -urN --exclude manual glibc-2.2.5/sunrpc/Versions glibc-2.2.5-leakfix/sunrpc/Versions
--- glibc-2.2.5/sunrpc/Versions	Mon Mar 26 15:44:38 2001
+++ glibc-2.2.5-leakfix/sunrpc/Versions	Wed Jun  9 17:38:13 2004
@@ -110,7 +110,7 @@
     svc_getreq_common; svc_getreq_poll; svc_max_pollfd; svc_pollfd;
   }
   GLIBC_2.2.3 {
-    __rpc_thread_destroy; __rpc_thread_svc_fdset; __rpc_thread_createerr;
+    __rpc_thread_svc_fdset; __rpc_thread_createerr;
     __rpc_thread_svc_pollfd; __rpc_thread_svc_max_pollfd;
   }
 }
diff -urN --exclude manual glibc-2.2.5/sunrpc/rpc_thread.c glibc-2.2.5-leakfix/sunrpc/rpc_thread.c
--- glibc-2.2.5/sunrpc/rpc_thread.c	Mon May 21 03:20:31 2001
+++ glibc-2.2.5-leakfix/sunrpc/rpc_thread.c	Wed Jun  9 17:12:50 2004
@@ -17,7 +17,7 @@
 /*
  * Task-variable destructor
  */
-void
+void __attribute__ ((section ("__libc_thread_freeres_fn")))
 __rpc_thread_destroy (void)
 {
 	struct rpc_thread_variables *tvp = __rpc_thread_variables();
@@ -35,6 +35,10 @@
 		free (tvp);
 	}
 }
+#ifdef _LIBC_REENTRANT
+text_set_element (__libc_thread_subfreeres, __rpc_thread_destroy);
+#endif
+text_set_element (__libc_subfreeres, __rpc_thread_destroy);
 
 
 /*

--=-r63W3jLt8ZEPuepqFtyl--