From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id 4AB333858438 for ; Tue, 18 Jan 2022 12:58:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4AB333858438 Received: by mail-oi1-x22a.google.com with SMTP id bb37so617395oib.1 for ; Tue, 18 Jan 2022 04:58:47 -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=KlzYvIxJCzkY7JtEqcOj5lWGszV+ibPsxOJZOACOKEU=; b=PjrFUIFpzpz7R4tNWuHk2sdZIXwAh1+2lxcbcFrmTJ68uJ0V8kpnIawyTZtFUVJdRC VwdKIcalMaOk93p35wIJoI/Cml4jqAjuCV5n/dVirVe8G+yMzQoJKJ2EHaZiTbPyY26j fqSLVohuFaSaGClrSOWK8xb7rinw0GSxTSntmqhnCCejeL9XmeTZkuWQCR80/Pc8vvlw y9oSgbAY71KBQ0CYMx0OXUWzY7hPJIkwATijS6J7Su6/qOXV5nKxQ1EiCuq3wmSbg5Ba T2B4ybDFjZaxNWM+uS8NvLwv3zP1vxzEe1xf2CQnsOXfc3K0jG2isReHtzjWSqRdCaVV Hmwg== X-Gm-Message-State: AOAM5300aosjpVF67HiiOFps5XvNPCMqbtXyolZ6XgOwMHz8//JsGciK CKp/Koi5ClF/OSj8DChRnFv3BBbk88N9Eg== X-Google-Smtp-Source: ABdhPJwFenv6Gen6j8kzuLrW7DU3Xwh4jaQFPIYMv0XJYNvCfmOJbwQt0zOxji2Q+xBJJgtn8GpbSg== X-Received: by 2002:aca:5cc2:: with SMTP id q185mr26982566oib.74.1642510726680; Tue, 18 Jan 2022 04:58:46 -0800 (PST) Received: from ?IPV6:2804:431:c7cb:989a:d7f1:4df2:e2ef:5281? ([2804:431:c7cb:989a:d7f1:4df2:e2ef:5281]) by smtp.gmail.com with ESMTPSA id b4sm5028009oop.35.2022.01.18.04.58.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Jan 2022 04:58:46 -0800 (PST) Message-ID: Date: Tue, 18 Jan 2022 09:58:43 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v10 2/4] elf: Fix initial-exec TLS access on audit modules (BZ #28096) Content-Language: en-US To: Florian Weimer , Adhemerval Zanella via Libc-alpha Cc: jma14 , Carlos O'Donell , John Mellor-Crummey References: <20220117213136.1327053-1-adhemerval.zanella@linaro.org> <20220117213136.1327053-3-adhemerval.zanella@linaro.org> <87r195jn1p.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella In-Reply-To: <87r195jn1p.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.9 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, URIBL_BLACK 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: Tue, 18 Jan 2022 12:58:48 -0000 On 18/01/2022 08:33, Florian Weimer wrote: > * Adhemerval Zanella via Libc-alpha: > >> diff --git a/elf/dl-tls.c b/elf/dl-tls.c >> index 8ba70c9a9d..8ed91ff599 100644 >> --- a/elf/dl-tls.c >> +++ b/elf/dl-tls.c >> @@ -520,7 +520,7 @@ _dl_resize_dtv (dtv_t *dtv, size_t max_modid) >> >> >> void * >> -_dl_allocate_tls_init (void *result) >> +_dl_allocate_tls_init (void *result, bool init_tls) >> { >> if (result == NULL) >> /* The memory allocation failed. */ >> @@ -593,7 +593,14 @@ _dl_allocate_tls_init (void *result) >> some platforms use in static programs requires it. */ >> dtv[map->l_tls_modid].pointer.val = dest; >> >> - /* Copy the initialization image and clear the BSS part. */ >> + /* Copy the initialization image and clear the BSS part. For >> + audit modules or depedencies with initial-exec TLS, we can not >> + set the initial TLS image on default loader initialization >> + because it would already be set by the audit setup. However, >> + subsequent thread creation would need to follow the default >> + behaviour. */ >> + if (__glibc_unlikely (map->l_auditing && !init_tls)) >> + continue; >> memset (__mempcpy (dest, map->l_tls_initimage, >> map->l_tls_initimage_size), '\0', >> map->l_tls_blocksize - map->l_tls_initimage_size); > > I don't understand why the map->l_auditing condition is correct. > Shouldn't it be > > map->l_ns == LM_ID_BASE && !init_tls > > ? Everything else has been loaded via dlopen or dlmopen, so TLS > initialization for the main thread has already happened. This is not suffice (I tried before in fact) because we need to skip solely for the audit modules and dependencies at the startup. For instance with tst-audit21 we have with some _dl_debug_printf to show what is happening 1533769: [rtld.c:966] load_audit_module 1533769: [rtld.c:973] load_audit_module 1533769: [rtld.c:2465] dl_main 1533769: [../elf/dl-tls.c:603] map->l_name= map->l_ns=0 map->l_auditing=0 init_tls=0 [INIT] 1533769: [../elf/dl-tls.c:603] map->l_name=[...]/elf/tst-auditmod21a.so map->l_ns=1 map->l_auditing=1 init_tls=0 1533769: [../elf/dl-tls.c:603] map->l_name=[...]/libc.so.6 map->l_ns=1 map->l_auditing=1 init_tls=0 1533769: [../elf/dl-tls.c:603] map->l_name=[...]/libc.so.6 map->l_ns=0 map->l_auditing=0 init_tls=0 [INIT] 1533769: [../elf/dl-tls.c:621] 1533769: [rtld.c:2467] dl_main [allocatestack.c:435] allocate_stack 1533769: [../elf/dl-tls.c:633] _dl_allocate_tls 1533769: [../elf/dl-tls.c:603] map->l_name= map->l_ns=0 map->l_auditing=0 init_tls=1 [INIT] 1533769: [../elf/dl-tls.c:603] [...]/elf/tst-auditmod21a.so map->l_ns=1 map->l_auditing=1 init_tls=1 [INIT] 1533769: [../elf/dl-tls.c:603] [...]/libc.so.6 map->l_ns=1 map->l_auditing=1 init_tls=1 [INIT] 1533769: [../elf/dl-tls.c:603] [...]/libc.so.6 map->l_ns=0 map->l_auditing=0 init_tls=1 [INIT] 1533769: [../elf/dl-tls.c:621] 1533769: [../elf/dl-tls.c:642] _dl_allocate_tls [allocatestack.c:446] allocate_stack So we need to avoid initialization only for the libc.so loading by audit libraries, the default one should still be initialized (marked as [INIT]). Later when new threads are created we need to initialized everything.