From owner-freebsd-threads@FreeBSD.ORG Thu Oct 5 13:20:29 2006 Return-Path: X-Original-To: freebsd-threads@hub.freebsd.org Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E4A2E16A407 for ; Thu, 5 Oct 2006 13:20:28 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7BD5143D46 for ; Thu, 5 Oct 2006 13:20:28 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k95DKSKi050904 for ; Thu, 5 Oct 2006 13:20:28 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k95DKSDL050902; Thu, 5 Oct 2006 13:20:28 GMT (envelope-from gnats) Date: Thu, 5 Oct 2006 13:20:28 GMT Message-Id: <200610051320.k95DKSDL050902@freefall.freebsd.org> To: freebsd-threads@FreeBSD.org From: John Baldwin Cc: Subject: Re: threads/103975: Implicit loading/unloading of libpthread.so may crash user processes X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: John Baldwin List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Oct 2006 13:20:29 -0000 The following reply was made to PR threads/103975; it has been noted by GNATS. From: John Baldwin To: freebsd-threads@freebsd.org Cc: KUROSAWA@freebsd.org, Takahiro , freebsd-gnats-submit@freebsd.org Subject: Re: threads/103975: Implicit loading/unloading of libpthread.so may crash user processes Date: Thu, 5 Oct 2006 09:06:20 -0400 On Wednesday 04 October 2006 09:56, KUROSAWA@freebsd.org, Takahiro wrote: > > >Number: 103975 > >Category: threads > >Synopsis: Implicit loading/unloading of libpthread.so may crash user processes > >Confidential: no > >Severity: serious > >Priority: medium > >Responsible: freebsd-threads > >State: open > >Quarter: > >Keywords: > >Date-Required: > >Class: sw-bug > >Submitter-Id: current-users > >Arrival-Date: Wed Oct 04 14:00:50 GMT 2006 > >Closed-Date: > >Last-Modified: > >Originator: KUROSAWA, Takahiro > >Release: 6.2-PRERELEASE > >Organization: > >Environment: > FreeBSD cube.nodomain.noroot 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #13: Fri Sep 29 14:34:05 JST 2006 kurosawa@cube.nodomain.noroot:/usr/obj/usr/src/sys/CUBE i386 > > >Description: > A program (described as ProgA below) gets SIGSEGV if following conditions > are met: > - ProgA dlopen()s and dlclose()s a shared object (ShobjB) > - ProgA doesn't link libpthread.so > - ShbjB dynamically links libpthread.so > (libpthread.so will be loaded when ProgA dlopen()s ShobjB) > - ProgA calls functions like gethostbyname() that uses __thr_jtable > (in src/lib/libc/gen/_pthread_stubs.c) after unloading ShobjB. > > The problem is that function pointers in __thr_jtable still point to functions > in libpthread.so after libpthread.so is unloaded from ProgA's memory space. Actually, I wonder if it should be allowed to unload at all. On 4.x at work we ran into an issue with the linuxthreads library loading, setting _is_threaded, then unloading with a malloc() occurring during the destructors resolving a _spinlock() weak symbol, then after the libraries were completely unloaded, the next malloc() blew up when _spinlock() pointed off into space. Hmm, this specific condition is handled I think since __isthreaded in 6.x libpthread isn't set until you do pthread_create() which at that point means a symbol is resolved, and the library won't be unloaded (I think). Hmm, maybe not since that doesn't guarantee that libc depends on libpthread (that is what keeps it from being unloaded IIRC). So, maybe when the library sets __isthreaded it should call one of the libc functions (like malloc) to force one of the weak symbols to be resolved so it isn't unloaded. > To fix the problem, a function that has __attribute__((destructor)) > in libpthread should probably be implemented in order to recover > the initial state before unloading. I'm not sure you can recover the state actually, hence why I think maybe we should make it so that libpthread doesn't unload once it has been loaded. -- John Baldwin