From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9344 Path: news.gmane.org!not-for-mail From: Timo Teras Newsgroups: gmane.linux.lib.musl.general Subject: Re: dynlink.c: bug in reclaim_gaps leading to segfault in __libc_exit_fini Date: Wed, 17 Feb 2016 09:03:27 +0200 Message-ID: <20160217090327.4c6b5790@vostro.util.wtbts.net> References: <20160216215550.GC9915@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1455692630 790 80.91.229.3 (17 Feb 2016 07:03:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Feb 2016 07:03:50 +0000 (UTC) Cc: musl@lists.openwall.com To: Szabolcs Nagy Original-X-From: musl-return-9357-gllmg-musl=m.gmane.org@lists.openwall.com Wed Feb 17 08:03:50 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1aVw9N-0006Aa-Pk for gllmg-musl@m.gmane.org; Wed, 17 Feb 2016 08:03:49 +0100 Original-Received: (qmail 11717 invoked by uid 550); 17 Feb 2016 07:03:47 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 11690 invoked from network); 17 Feb 2016 07:03:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=QP1XBNYC+rH/aL3l7fS1Ws6oG+HEYlLrsY6F9Y8478Q=; b=sVycpeo59WydtayX2aXXt+Xp2wbxs9B68JV8rXuBD/yy/KJRQl7k9hOZbk/2vr52t6 Qsa1SK3ZUteVC0y5SJ6jyyEc47ig0r6Cl5TH9ubgW2qt6ocQ+pkGJyS+9GBDmekAHny+ otV+wb4fAM/Pgd9aFE4Fl0MWT0q7O1QMFP6CWOq/5wOv0/wy9mxc9J79/wI8Xr3pfWFR kWWJk32NcP+7kwrjg4LtDY6xQYg5eclZH0sRY9xw+nZSQ5YkCkmT3nXKA+bJftXSWHO0 HfkLn6XlfmzrJq6DJa+uWzNhjOLDXczxc/3xg19UXqJAt+tqFEpbiLStkmDVazLlMl/O risA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding; bh=QP1XBNYC+rH/aL3l7fS1Ws6oG+HEYlLrsY6F9Y8478Q=; b=IUcl/Px3ucFBvswaMOsEdr+F2EeTBdqE2mWSrzQ0ePGmtOvoCqmc8sby/bQnEB3XoX 93svx2VWWyJz4VF7lJXOp8MupBW7yQfvmGq/3jzZtrUhjZ8UswLmQEEzBqXaPD3+EqGE 8Noqc+o565owXfKmqFqnYDJ8CPrAS4C3KTnkYsJal0OxC7DufxffhZuzf/ozkiwVK645 OJ1FQoaK12x+bR8ZXA4hyjYFtyGTX6TTWltOYNPPKRrqu78tTbKTZAC4tFs9IEGcFTFZ X+7Q9Bhqfol5lKudGtxMuI9AuQlxcb4Cpll+WGHFgqNEOU7GZYsM7bwxpa6avLGYmPnv OMJg== X-Gm-Message-State: AG10YOSPkyJxANkrGUhiC7w8GmKnVsu7aXyp5Fc6chIucrP2GvtNFWQ5HBKJ/tBEqs+KMg== X-Received: by 10.25.91.71 with SMTP id p68mr9728482lfb.55.1455692615669; Tue, 16 Feb 2016 23:03:35 -0800 (PST) Original-Sender: =?UTF-8?Q?Timo_Ter=C3=A4s?= In-Reply-To: <20160216215550.GC9915@port70.net> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.28; x86_64-alpine-linux-musl) Xref: news.gmane.org gmane.linux.lib.musl.general:9344 Archived-At: On Tue, 16 Feb 2016 22:55:50 +0100 Szabolcs Nagy wrote: > * Hugues Bruant [2016-02-16 16:30:42 -0500]: > > Affects both 1.1.12 and 1.1.13 > > > > Tracked down with valgrind in Alpine Linux 3.3. > > > > The dmg tool build from https://github.com/aerofs/libdmg-hfsplus > > links to a handful shared libs. The following message is seen > > immediately at start: > > > > ==59== Invalid free() / delete / delete[] / realloc() > > ==59== at 0x4C92B0E: free (vg_replace_malloc.c:530) > > ==59== by 0x4056F68: reclaim_gaps (dynlink.c:488) > > ==59== by 0x405743D: map_library (dynlink.c:708) > > ==59== by 0x4057EF3: load_library (dynlink.c:1014) > > ==59== by 0x4058CA8: load_preload (dynlink.c:1112) > > ==59== by 0x4058CA8: __dls3 (dynlink.c:1581) > > ==59== by 0x405856A: __dls2 (dynlink.c:1383) > > ==59== by 0x405655E: ??? (in /lib/ld-musl-x86_64.so.1) > > ==59== by 0x3: ??? > > ==59== by 0xFFF000E3A: ??? > > ==59== by 0xFFF000E3E: ??? > > ==59== by 0xFFF000E44: ??? > > ==59== by 0xFFF000E86: ??? > > > > Afterwards, the program proceeds with no issue, until it exists, at > > which point a segfault is triggered when cleaning up shared > > libraries: > > this is not a bug. It is compliance issue. POSIX says about free: -- The free() function shall cause the space pointed to by ptr to be deallocated; that is, made available for further allocation. If ptr is a null pointer, no action shall occur. Otherwise, if the argument does not match a pointer earlier returned by a function in POSIX.1-2008 that allocates memory as if by malloc(), or if the space has been deallocated by a call to free() or realloc(), the behavior is undefined. -- While overloading allocators are not supported, they'd break at this too. And it'll be highly annoying if someone decides to test a new memory allocator inside musl and does not know about this one exception. > valgrind is not aware of dynamic linker internals, > you have to use a musl specific suppression file > to hide this message (but i dont know if anybody > wrote such thing for valgrind). Well - musl really should introduce __donatemem or similar for this purpose, and not overload the standard free() function. This would make the valgrind warning go away. I'd rather not write a suppression for the above, since the internals are misusing/overloading a standard api call against posix. Technically valgrind is detecting a valid case for misuse of free(). While in context of standard musl allocator it's ok. Thanks, Timo