From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x931.google.com (mail-ua1-x931.google.com [IPv6:2607:f8b0:4864:20::931]) by sourceware.org (Postfix) with ESMTPS id 0D860385841A for ; Thu, 11 Nov 2021 18:54:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0D860385841A Received: by mail-ua1-x931.google.com with SMTP id b17so14003551uas.0 for ; Thu, 11 Nov 2021 10:54:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=d8DFWy/vub5iQK5LEKS8Dnk96QzoSZelU24q/vZEuIY=; b=TlYYeGk1fhAwB28HiBnrPETkFGwf0s9nY4nrZs/HAjml/ZSHC+Zhtg02/I7XmWRmab K7fYT9DD+lbj+tkHpyvpREeNP7+4958qP3KhiHSq2QR9NZB25kxsrYqbgdT9XU7QXLgy Oi/oJJxyOreIgH1b4eAbmqNjPtfxrsVcDn5H25njpA4hb+HQopsqaplzjNeDSg1tajoa ty5112zQiUfz7DYCgJgVdenLc9lt0DbFKT87z2/aclFBhFK2RW5lC5x3k2jkib6ovIhw 8Ku7sykp5gKmkmyPlZf9DededuoMGNKaP/e/sQZNRg0ZycXS3I7Vreftj6v1fiYjA+7e 3+mg== X-Gm-Message-State: AOAM531bGzPDYIBsQqtbtBCI3nrr234iZIsQYj0B2uK1OdEWGV4o3NWe uGdcU1EDhtWorK5SNjXifOpI+w== X-Google-Smtp-Source: ABdhPJzGPvUtxfb283H+yAO0AmYK5Tct1TrEJEh1Q//mQNDcmjEXRsuAtwZK5lba/YBW+uF+RSeimg== X-Received: by 2002:ab0:15a1:: with SMTP id i30mr13355335uae.122.1636656877222; Thu, 11 Nov 2021 10:54:37 -0800 (PST) Received: from ?IPV6:2804:431:c7cb:55a:48f2:1d0b:8ae8:643a? ([2804:431:c7cb:55a:48f2:1d0b:8ae8:643a]) by smtp.gmail.com with ESMTPSA id c2sm2777435uab.11.2021.11.11.10.54.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Nov 2021 10:54:37 -0800 (PST) Message-ID: Date: Thu, 11 Nov 2021 15:54:34 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH v5 05/22] elf: Fix initial-exec TLS access on audit modules (BZ #28096) Content-Language: en-US To: Florian Weimer Cc: libc-alpha@sourceware.org, John Mellor-Crummey , Ben Woodard References: <20211109183347.2943786-1-adhemerval.zanella@linaro.org> <20211109183347.2943786-6-adhemerval.zanella@linaro.org> <87v9105el8.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella In-Reply-To: <87v9105el8.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Nov 2021 18:54:39 -0000 On 10/11/2021 10:23, Florian Weimer wrote: > * Adhemerval Zanella: > >> diff --git a/elf/Makefile b/elf/Makefile >> index 4758cb23c4..861e83236e 100644 >> --- a/elf/Makefile >> +++ b/elf/Makefile > >> +$(objpfx)tst-audit21.out: $(objpfx)tst-auditmod21.so >> +tst-audit21-ENV = LD_AUDIT=$(objpfx)tst-auditmod21.so > > This is needed to fix a Hurd build failure: > > $(objpfx)tst-audit21: $(shared-thread-library) Ack. > >> diff --git a/elf/dl-object.c b/elf/dl-object.c >> index 1875599eb2..eb2158a84b 100644 >> --- a/elf/dl-object.c >> +++ b/elf/dl-object.c >> @@ -175,6 +175,9 @@ _dl_new_object (char *realname, const char *libname, int type, >> >> new->l_local_scope[0] = &new->l_searchlist; >> >> + if (mode & __RTLD_AUDIT) >> + new->l_dont_set_tls_static = 1; >> + >> /* Determine the origin. If allocating the link map for the main >> executable, the realname is not known and "". In this case, the >> origin needs to be determined by other means. However, in case > >> diff --git a/elf/rtld.c b/elf/rtld.c >> index 8953347b00..db1817655f 100644 >> --- a/elf/rtld.c >> +++ b/elf/rtld.c >> @@ -1055,6 +1055,8 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d); >> >> /* Mark the DSO as being used for auditing. */ >> dlmargs.map->l_auditing = 1; >> + /* Mark the DSO to not clear the TLS bss in tls initialization. */ >> + dlmargs.map->l_dont_set_tls_static = 1; >> } >> >> /* Notify the the audit modules that the object MAP has already been > > I'm not sure if this actually works. As far as I understand it, > everything in an audit namespace needs this special treatment, and not > just the audit module itself. Yes, and since each audit modules is loaded with LM_ID_NEWLM it means all its dependencies. Adding some instrumentation, it works on the audit modules does have some dependencies: $ ldd /home/azanella/Projects/glibc/build/x86_64-linux-gnu/elf/tst-auditmod21a.so linux-vdso.so.1 (0x00007fff4a172000) /home/azanella/Projects/glibc/build/x86_64-linux-gnu/elf/tst-auditmod21b.so (0x00007fcd11fa5000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcd11d61000) /lib64/ld-linux-x86-64.so.2 (0x00007fcd11fb1000) $ LD_AUDIT=elf/tst-auditmod21a.so elf/ld.so --library-path . elf/tst-audit21 2281374: [../elf/dl-tls.c:603] map->l_name= l_dont_set_tls_static=0 2281374: [../elf/dl-tls.c:603] map->l_name=elf/tst-auditmod21a.so l_dont_set_tls_static=1 2281374: [../elf/dl-tls.c:603] map->l_name=/home/azanella/Projects/glibc/build/x86_64-linux-gnu/elf/tst-auditmod21b.so l_dont_set_tls_static=1 2281374: [../elf/dl-tls.c:603] map->l_name=./libc.so.6 l_dont_set_tls_static=1 2281374: [../elf/dl-tls.c:603] map->l_name=/home/azanella/Projects/glibc/build/x86_64-linux-gnu/elf/tst-auditmod21c.so l_dont_set_tls_static=0 2281374: [../elf/dl-tls.c:603] map->l_name=./libc.so.6 l_dont_set_tls_static=0 2281374: [../elf/dl-tls.c:603] map->l_name= l_dont_set_tls_static=0 2281374: [../elf/dl-tls.c:603] map->l_name=elf/tst-auditmod21a.so l_dont_set_tls_static=0 2281374: [../elf/dl-tls.c:603] map->l_name=/home/azanella/Projects/glibc/build/x86_64-linux-gnu/elf/tst-auditmod21b.so l_dont_set_tls_static=0 2281374: [../elf/dl-tls.c:603] map->l_name=./libc.so.6 l_dont_set_tls_static=0 2281374: [../elf/dl-tls.c:603] map->l_name=/home/azanella/Projects/glibc/build/x86_64-linux-gnu/elf/tst-auditmod21c.so l_dont_set_tls_static=0 2281374: [../elf/dl-tls.c:603] map->l_name=./libc.so.6 l_dont_set_tls_static=0 The l_dont_set_tls_static should be set for the audit module and its dependencies. > > I think we shuld add a parameter to _dl_allocate_tls_init and that > indicates the initialization should only be applied to objects in the > base namespace. This way, initialization is also skipped for dlopen'ed > modules in an audit namespace. I am not sure if this would be best solution, I will check whether dlopen does work with this patch.