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: 34497 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;