From patchwork Wed Sep 11 09:57:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1160891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105132-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="rIy0FL8m"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46Sy4b0zZzz9s00 for ; Wed, 11 Sep 2019 19:57:34 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=X6lhufu1G5gpxS2PAEaJhKAodWnDi Fh1SpWuFTOjAp6uiiFcG/YxZKcSV0lju5IFB4OS6+cOnz/EpA2rxtCYHevoCmgYo 1XCQGuM2TK0hCm+YjOM8quHLBMCQ8fgTr++rKCI9aPj5li6x4ZAVG2m0ETg5Z7y0 A9AySxJC1MwmIs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=JTrXK/YUyALfSCYIt7wabLtfzzY=; b=rIy 0FL8m+sHo5YpraWznNloS6AXT3m50vZymDasvq5N/3KtLqg+7HZzXEvuBOARgEzO vW4fZCd9GqbX4lihZj0Ok1aPJ/aNvMrpdw0/+mAq+RYZamkcuk1sCrmkOid16C/V PQXnxKUr5roaSVTYJjQ7CyIWbP+wIDWt96a3uVlQ= Received: (qmail 37543 invoked by alias); 11 Sep 2019 09:57:29 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 37535 invoked by uid 89); 11 Sep 2019 09:57:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=H*r:sk:dhcp-19, H*RU:sk:dhcp-19, HX-Spam-Relays-External:sk:dhcp-19 X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] elf: Assert that objects are relocated before their constructors run Date: Wed, 11 Sep 2019 11:57:24 +0200 Message-ID: <87pnk7w3y3.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 If we try to run constructors before relocation, this is always a dynamic linker bug. An assert is easier to notice than a call via an invalid function pointer (which may not even produce a valid call stack). 2019-09-11 Florian Weimer * elf/dl-init.c (call_init): Assert that the object has been relocated. Reviewed-by: Carlos O'Donell diff --git a/elf/dl-init.c b/elf/dl-init.c index 3721bca81e..a998992544 100644 --- a/elf/dl-init.c +++ b/elf/dl-init.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#include #include #include @@ -27,6 +28,11 @@ typedef void (*init_t) (int, char **, char **); static void call_init (struct link_map *l, int argc, char **argv, char **env) { + /* If the object has not been relocated, this is a bug. The + function pointers are invalid in this case. (Executables do not + need relocation, and neither do proxy objects.) */ + assert (l->l_real->l_relocated || l->l_real->l_type == lt_executable); + if (l->l_init_called) /* This object is all done. */ return;