From patchwork Wed Dec 13 04:40:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos O'Donell X-Patchwork-Id: 24906 Received: (qmail 114585 invoked by alias); 13 Dec 2017 04:40:18 -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 114574 invoked by uid 89); 13 Dec 2017 04:40:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=onetime, one-time X-HELO: mail-qk0-f180.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:organization:message-id:date :user-agent:mime-version:content-language; bh=r0BrHr/h2j/qj5HIqrFfRNLIvbIHP9jUvuBscJX0dt4=; b=ojELIlYxSdP/JNwaP8QZ9N7G+I+miow2zhA8ANIN6ldasrdfmhrQwXHHATfQyMbdEb cLNDi6FKoXk5PEMjIWZ1UbAxO+hVXfCPk6ZltljS7rW1XEcxaSNP4EbsSt6w6FIK4dX8 nSXbWcSVf70MoPcER3yF8UzSFbzmTVibB+Qr+n0JkvW4H9pt3ao4ZUwTPcte9330EZaY 9zT2u8VwusR766PFJg8Ta4v6s5u9hxOeeLT5lPi2JfQdV1RJIoBsdF00GnTvFsScBG4S k03gB0m3p+Nnu/Yr8PGeJKOpedORagX6RZO8NBRv05nCO6gTHEq4OTt71agi5/MQ0lFA xlEQ== X-Gm-Message-State: AKGB3mIYEc9mWkaoRgbndvCfC1OjW9mRu5dtXHNIXDXJPOTS/vtgDPSL FZTparRh7BaHzxxeVrsFQNQGoSuqc5Y= X-Google-Smtp-Source: ACJfBouN++Eh+hKkzeCCJmBZ4N+zc5/OoQ522o0WNdoaybQD+cof145fcDZKOUGSX1JHqAuJcnfpCQ== X-Received: by 10.55.43.156 with SMTP id r28mr9054634qkr.316.1513140014820; Tue, 12 Dec 2017 20:40:14 -0800 (PST) To: GNU C Library , "H.J. Lu" From: Carlos O'Donell Subject: [PATCH] Fix tst-leaks1 (bug 14681) Message-ID: Date: Tue, 12 Dec 2017 20:40:10 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 The test tst-leaks1 exercises calling dlopen with a $ORIGIN DST. This results in a theoretical leak e.g. Memory not freed: ----------------- Address Size Caller 0x0000000001d766c0 0x21 at 0x7fb1bd8bf4ab Or as seen via valgrind: ==27582== 33 bytes in 1 blocks are still reachable in loss record 1 of 1 ==27582== at 0x4C2CB6B: malloc (vg_replace_malloc.c:299) ==27582== by 0x40124AA: _dl_get_origin (dl-origin.c:50) ==27582== by 0x4007DB9: expand_dynamic_string_token (dl-load.c:382) ==27582== by 0x400899C: _dl_map_object (dl-load.c:2160) ==27582== by 0x4013020: dl_open_worker (dl-open.c:224) ==27582== by 0x5166F9B: _dl_catch_exception (dl-error-skeleton.c:198) ==27582== by 0x4012BD9: _dl_open (dl-open.c:594) ==27582== by 0x4E39EF5: dlopen_doit (dlopen.c:66) ==27582== by 0x5166F9B: _dl_catch_exception (dl-error-skeleton.c:198) ==27582== by 0x516700E: _dl_catch_error (dl-error-skeleton.c:217) ==27582== by 0x4E3A514: _dlerror_run (dlerror.c:162) ==27582== by 0x4E39F70: dlopen@@GLIBC_2.2.5 (dlopen.c:87) There is no real leak. The calling link map (the executable's link map) has it's l_origin expanded for future use as part of _dl_get_origin, and that results in the main executable link map having a N-byte allocation for l->l_origin that is never freed since the executable's link map is just a part of the process. To take this into account we do one dlopen with $ORIGIN before calling mtrace to force the initialization of the executable link map. Signed-off-by: Carlos O'Donell OK to checkin? From 25cbacf1ba7b6685792c08e32156c2209376dc70 Mon Sep 17 00:00:00 2001 From: Carlos O'Donell Date: Tue, 12 Dec 2017 20:35:05 -0800 Subject: [PATCH] Fix tst-leaks1 (bug 14681) The test tst-leaks1 exercises calling dlopen with a $ORIGIN DST. This results in a theoretical leak e.g. Memory not freed: ----------------- Address Size Caller 0x0000000001d766c0 0x21 at 0x7fb1bd8bf4ab Or as seen via valgrind: ==27582== 33 bytes in 1 blocks are still reachable in loss record 1 of 1 ==27582== at 0x4C2CB6B: malloc (vg_replace_malloc.c:299) ==27582== by 0x40124AA: _dl_get_origin (dl-origin.c:50) ==27582== by 0x4007DB9: expand_dynamic_string_token (dl-load.c:382) ==27582== by 0x400899C: _dl_map_object (dl-load.c:2160) ==27582== by 0x4013020: dl_open_worker (dl-open.c:224) ==27582== by 0x5166F9B: _dl_catch_exception (dl-error-skeleton.c:198) ==27582== by 0x4012BD9: _dl_open (dl-open.c:594) ==27582== by 0x4E39EF5: dlopen_doit (dlopen.c:66) ==27582== by 0x5166F9B: _dl_catch_exception (dl-error-skeleton.c:198) ==27582== by 0x516700E: _dl_catch_error (dl-error-skeleton.c:217) ==27582== by 0x4E3A514: _dlerror_run (dlerror.c:162) ==27582== by 0x4E39F70: dlopen@@GLIBC_2.2.5 (dlopen.c:87) There is no real leak. The calling link map (the executable's link map) has it's l_origin expanded for future use as part of _dl_get_origin, and that results in the main executable link map having a N-byte allocation for l->l_origin that is never freed since the executable's link map is just a part of the process. To take this into account we do one dlopen with $ORIGIN before calling mtrace to force the initialization of the executable link map. Signed-off-by: Carlos O'Donell --- ChangeLog | 4 ++++ elf/tst-leaks1.c | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22df17b671..809e6db4c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2017-12-12 Carlos O'Donell + [BZ #14681] + * elf/tst-leaks1.c (do_test): Call one dlopen with $ORIGIN expansion + before mtrace. + * elf/Makefile [$(nss-crypt)$(static-nss-crypt) == yesno] (CFLAGS-tst-linkall-static.c): Undefine USE_CRYPT first. diff --git a/elf/tst-leaks1.c b/elf/tst-leaks1.c index d67e8269c4..75bc92d25f 100644 --- a/elf/tst-leaks1.c +++ b/elf/tst-leaks1.c @@ -6,13 +6,28 @@ static int do_test (void) { + void *h; + int ret = 0; + /* Carry out *one* failing call to dlopen before starting mtrace to + force any one-time inintialization that may happen to the + executable link map e.g. expansion and caching of $ORIGIN. */ + h = dlopen ("$ORIGIN/tst-leaks1.o", RTLD_LAZY); + if (h != NULL) + { + puts ("dlopen unexpectedly succeeded"); + ret = 1; + dlclose (h); + } + + /* Start tracing and run each test 5 times to see if there are any + leaks in the failing dlopen. */ mtrace (); - int ret = 0; for (int i = 0; i < 10; i++) { - void *h = dlopen (i < 5 ? "./tst-leaks1.c" - : "$ORIGIN/tst-leaks1.o", RTLD_LAZY); + h = dlopen (i < 5 + ? "./tst-leaks1.c" + : "$ORIGIN/tst-leaks1.o", RTLD_LAZY); if (h != NULL) { puts ("dlopen unexpectedly succeeded"); -- 2.14.3