From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 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 dcvr.yhbt.net (Postfix) with ESMTPS id 5C79F1F463 for ; Wed, 27 Nov 2019 18:39:53 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:in-reply-to:references :reply-to:mime-version:content-transfer-encoding:content-type :message-id; q=dns; s=default; b=nHU9eh5oU4EFDu3/AiR4Hwe1/mZTVbd aC/EBnv9NNuZDnpwG6HyLecwPXzQ7rnbEiedJx95HMFyg3VDs8E6/KyGWowvDJku aClEPHljFbK++wLVwqtcAabrK1fQsngZxrnTt6/DOlQiJXJs04g9lZgsBUHjzMDV HVAHxYnEMTVA= 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:date:from:to:subject:in-reply-to:references :reply-to:mime-version:content-transfer-encoding:content-type :message-id; s=default; bh=Gsg073QyUv5Y1sqXWvLqW7Y1bSc=; b=Pn9Cp 4hCfTNHYIiEe6R0fCWRg/GA0o6mw0AaRbNy14IRFPZMJ9FejqdMjQAAcEC86zlU7 XE4PBHDBpJNfLPuYi5fDBj1mgH7rtOAYk8SQqSFJOvigu27fGIwSW+UNd5XLyzep 8TxsQuVotpS5X5VqKNw0rHXHum/hOCuq3gb2ns= Received: (qmail 50976 invoked by alias); 27 Nov 2019 18:39:51 -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 Received: (qmail 50965 invoked by uid 89); 27 Nov 2019 18:39:51 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: mx1.osci.io X-Gerrit-PatchSet: 4 Date: Wed, 27 Nov 2019 13:39:46 -0500 From: "Carlos O'Donell (Code Review)" To: Florian Weimer , libc-alpha@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: comment Subject: [review v4] Avoid late failure in dlopen in global scope update [BZ #25112] X-Gerrit-Change-Id: Ie08e2f318510d5a6a4bcb1c315f46791b5b77524 X-Gerrit-Change-Number: 465 X-Gerrit-ChangeURL: X-Gerrit-Commit: 842d32e288a5d07874c84d958e720efc65c9f4bd In-Reply-To: References: X-Gerrit-Comment-Date: Wed, 27 Nov 2019 13:39:46 -0500 Reply-To: gnutoolchain-gerrit@osci.io MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Content-Type: text/plain; charset=UTF-8 Message-Id: <20191127183946.A83B920AF6@gnutoolchain-gerrit.osci.io> Carlos O'Donell has posted comments on this change. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/465 ...................................................................... Patch Set 4: Code-Review+2 (4 comments) Still looks good. OK for master. Reviewed-by: Carlos O'Donell | --- elf/dl-open.c | +++ elf/dl-open.c | @@ -87,7 +115,20 @@ add_to_global_resize (struct link_map *new) | + add_to_global_resize_failure (new); | + | if (ns->_ns_global_scope_alloc == 0) | { | - /* This is the first dynamic object given global scope. */ | - ns->_ns_global_scope_alloc | - = ns->_ns_main_searchlist->r_nlist + to_add + 8; | - new_global = (struct link_map **) | - malloc (ns->_ns_global_scope_alloc * sizeof (struct link_map *)); | + if (__builtin_add_overflow (required_new_size, 8, &new_size)) | + add_to_global_resize_failure (new); PS3, Line 120: Done | + } | + else if (required_new_size > ns->_ns_global_scope_alloc) | + { | + if (__builtin_mul_overflow (required_new_size, 2, &new_size)) | + add_to_global_resize_failure (new); PS3, Line 125: Done | + | + /* The old array was allocated with our malloc, not the minimal | + malloc. */ | + old_global = ns->_ns_main_searchlist->r_list; | + } | + | + if (new_size > 0) | + { | + size_t allocation_size; | --- elf/dl-open.c | +++ elf/dl-open.c | @@ -171,34 +208,34 @@ _dl_find_dso_for_object (const ElfW(Addr) addr) | || _dl_addr_inside_object (l, (ElfW(Addr)) addr))) | { | assert (ns == l->l_ns); | return l; | } | return NULL; | } | rtld_hidden_def (_dl_find_dso_for_object); | | /* struct dl_init_args and call_dl_init are used to call _dl_init with | exception handling disabled. */ | struct dl_init_args | { | struct link_map *new; | int argc; | char **argv; | char **env; | }; | | static void | call_dl_init (void *closure) | { | struct dl_init_args *args = closure; | _dl_init (args->new, args->argc, args->argv, args->env); | } PS4, Line 232: OK. Call _dl_init with a closure. | | static void | dl_open_worker (void *a) | { | struct dl_open_args *args = a; | const char *file = args->file; | int mode = args->mode; | struct link_map *call_map = NULL; | ... | @@ -525,25 +569,27 @@ #endif | #ifndef SHARED | DL_STATIC_INIT (new); | #endif | | + /* Perform the necessary allocations for adding new global objects | + to the global scope below, via add_to_global_update. */ | + if (mode & RTLD_GLOBAL) | + add_to_global_resize (new); | + | /* Run the initializer functions of new objects. Temporarily | disable the exception handler, so that lazy binding failures are | fatal. */ | { | struct dl_init_args init_args = | { | .new = new, | .argc = args->argc, | .argv = args->argv, | .env = args->env | }; | _dl_catch_exception (NULL, call_dl_init, &init_args); | } PS4, Line 590: OK, run with _dl_catch_exception to it throws. | | /* Now we can make the new map available in the global scope. */ | if (mode & RTLD_GLOBAL) | - /* Move the object in the global namespace. */ | - if (add_to_global (new) != 0) | - /* It failed. */ | - return; | + add_to_global_update (new); | -- Gerrit-Project: glibc Gerrit-Branch: master Gerrit-Change-Id: Ie08e2f318510d5a6a4bcb1c315f46791b5b77524 Gerrit-Change-Number: 465 Gerrit-PatchSet: 4 Gerrit-Owner: Florian Weimer Gerrit-Reviewer: Carlos O'Donell Gerrit-Reviewer: Florian Weimer Gerrit-Comment-Date: Wed, 27 Nov 2019 18:39:46 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes Comment-In-Reply-To: Carlos O'Donell Gerrit-MessageType: comment