From patchwork Tue Jun 11 15:27:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 803249 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:e87:b0:35b:5a80:51b4 with SMTP id dz7csp368156wrb; Tue, 11 Jun 2024 08:34:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUAQIDqotF62xVS52artQZrPOhVO6DhapwcBGjSztBtxzIVN+bFC/JHm7RkCwsT3JyR0eE+N4zBcbriuSGTCoUJ X-Google-Smtp-Source: AGHT+IE/JlkgCf083TuaAf4vaOILFPNaKVH6rYLz+dkT3agdZS/RzGOHFPzdVW3EGZbbFJBYwA8V X-Received: by 2002:a05:622a:108:b0:440:f0be:4bd3 with SMTP id d75a77b69052e-440f0be4fb6mr72101671cf.58.1718120041212; Tue, 11 Jun 2024 08:34:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718120041; cv=pass; d=google.com; s=arc-20160816; b=iAR0sXvVAPcpsgfsvnOltg1xPOB0JoxLkoa/UpYyhdxUvZxWkCjcTYuh+sCPVwOqVz Xd7RCbUEhcihvCR3fXZMsfXyYiwjRAGV0nr/h4X51yGLJiF6g7RCI+rusgjfpUbBl25F lkcTm8uSvtU7eCid0JCydM2X/i2ixGq7RRMlIEQS3MFCVr85pdquT5ssZlHav+gVB803 jOsbDDPwAcw7xmSFmjteeIX+w1ySAtD+mWdIYafQZavWEp2vZ+1sjZb9fOMkX8MSiw7j B3OdFcv75sy5izE85ggRbAZAR1s4QLkn5KwzpEZ53WEZKsZPR2lye7uhy85ObkcFXhpE bjMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=d7OwYwsoI1uYihWPd3RXq9N6NWQFWWHaUyyCVwn96ak=; fh=Xe8CcRFBQpY3WaKalMJwtTjJfhW8yymKb7+oOheBL8A=; b=VG5nrfh1PURBgRayTQdEKRTsXdnfqabwu/zyCb1i0W94cRVNH+uJf2j6noHOpeXI9r dc3WO9AK17gLXU8T3SwDzIoRJEZU6pA8Msu7hBtMvl8a5XbQiwpxdDryMJilNiTiqdtv AOqrSAWdA2YJ0tF2juCm3l+KM3pCWFOZlDNkZKtSrRz3yZA7jgd6JVPjsGhZVxwoIICX xgNuQn4QTPbNbn5xNARrtFpxsa0DYyOsbwbf4CZyUc91dl27x8IbvD/ximxoJFB+QiJy IJ2ag5Z52Vfd7NIWWvBmIHfpJTt5e0oGsf8nKAg106R+vH2z7OaP+0pW8ujeCnSFKh9n N87Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iCdMvUNU; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d75a77b69052e-440f1c3b012si50529461cf.53.2024.06.11.08.34.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 08:34:01 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iCdMvUNU; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2B38385DDD1 for ; Tue, 11 Jun 2024 15:34:00 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id D2D7A385DDE5 for ; Tue, 11 Jun 2024 15:32:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D2D7A385DDE5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D2D7A385DDE5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::435 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718119962; cv=none; b=wJhtbpTPXDt2MNqOET2Mrj4VQjFREbiXIVPwfeKCiLnekRiRXx9l+xFn2YxgpGp8F7NILawx9gDTATmCofCr7lVCxGzzkKexPcnQr8kd7Sa56PmdARdT7EIMxonSJFveHZcvO+zzh12nuPgwSjzzWR8/Aplx97p3QaOCSBafhYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718119962; c=relaxed/simple; bh=DfbxejrHFnW0UR7Qxn/DyvdFw8uu83lTIIi6oBEtmPs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Q/X6ixvknF+XsRf8jzdDEms6Yz1/hljo5P2Y+qsWOLujKZ0tE9FnLpMf8SmM6Hd+5+r5FxHCa0oLd1XFBdTlFxeCXwJOIp3ysFQZAx/+4UBhIHpX92HGQF+E/ZRc/wZrOcnmUFeOQOKmX7HciLM7gVNy7/JqCxZ+EdWlKhOiSCk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-70436ac8882so1143704b3a.2 for ; Tue, 11 Jun 2024 08:32:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718119958; x=1718724758; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d7OwYwsoI1uYihWPd3RXq9N6NWQFWWHaUyyCVwn96ak=; b=iCdMvUNUNeFmmr37dRKwrzOlGJGnkrncJu+b0D/9yBnCPCKCppzfzqtcH5reKiu6fc WQc7itXKYWgxOwkhWMLBPWwvfzILKHYB3GnemjXTpNHuo3Vadvx4jj8uk74KmmG4JQuw g0lFeG4gZ6/89FjKgq7QxnMFdkuAQZEXR0R8oceg+X0nYsQ3ITjXbQUcUo/OuPZX6IkG WLNZkMe7wPPCgGuGLWzx9TmbgYLqW8hLM3hQeZ4PZNBXIHQ4LupsafR6JG0gc7UiB1ap U7Zvwrs/3O2muQU8vcbb66GO5zWI5NCzOl8rG2rfY1R9aBSnZgkzalUP/pP3GU8tOT+I kt4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718119958; x=1718724758; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d7OwYwsoI1uYihWPd3RXq9N6NWQFWWHaUyyCVwn96ak=; b=CGhWWSCIVtQEGERTeN4avPuFYXLW+KCdYdMZVziFtoz1oPbUEzcFXGudOvqmijXKTP G+6dlH0qprCNFRcaos6Vp1BGLwwt4sjfJiCNiZOHoClJWa0z3RpSq/KUM0IQoKjDf2+O C/VfHm0ne6ATharI8xDxlobHwy8pMVNsv/3MYYIj9kqHRiwJSHo3gKsVsSSKSUFbAn4i b6Rt20W80vA1TMR0joK5/8YBLjeYeHiVaU6DyLZ2m3UBvTe++dmrLh20ij0BD/z7T8gF 3he2o1ISMs9I1xD934/ib4JmTxjb/A6uKUrpD43jBrQCB9TWUZ256Xl2+UOnRy8oXySd LAzg== X-Gm-Message-State: AOJu0YyX34XlF6R5sIxh26mvpSyPMOA75e4gkquVtdXu3R86kRFVyYQH Yl0ojtrF5YZ82I/bpRWNN5XxfbsPkGx0u7j8GmyZKkdDYT8zuf1a6szC/gNNK3nFIEOGXmQ2Lpz 7 X-Received: by 2002:a05:6a20:9755:b0:1af:f8bd:1e4e with SMTP id adf61e73a8af0-1b2f9dcc579mr9879024637.62.1718119958148; Tue, 11 Jun 2024 08:32:38 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:c5fb:1cf6:d480:34ef:aedf]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70422c977dasm6023811b3a.62.2024.06.11.08.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 08:32:37 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Stephen Roettger , jeffxu@chromium.org, Carlos O'Donell , Florian Weimer Subject: [RFC 4/5] elf: Enable RTLD_NODELETE on __libc_unwind_link_get Date: Tue, 11 Jun 2024 12:27:07 -0300 Message-ID: <20240611153220.165430-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240611153220.165430-1-adhemerval.zanella@linaro.org> References: <20240611153220.165430-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org The libgcc_s.so can also be sealed. The library is loaded once and not unloaded during process execution (only for memory debug with __libc_unwind_link_freeres). Checked on x86_64-linux-gnu and aarch64-linux-gnu. --- include/dlfcn.h | 2 ++ manual/tunables.texi | 4 ++++ misc/unwind-link.c | 5 +++-- sysdeps/unix/sysv/linux/tst-dl_mseal.c | 13 +++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/dlfcn.h b/include/dlfcn.h index f49ee1b0c9..06e2ecbdd2 100644 --- a/include/dlfcn.h +++ b/include/dlfcn.h @@ -50,6 +50,8 @@ extern char **__libc_argv attribute_hidden; better error handling semantics for the library. */ #define __libc_dlopen(name) \ __libc_dlopen_mode (name, RTLD_NOW | __RTLD_DLOPEN) +#define __libc_dlopen_nodelete(name) \ + __libc_dlopen_mode (name, RTLD_NODELETE | RTLD_NOW | __RTLD_DLOPEN) extern void *__libc_dlopen_mode (const char *__name, int __mode) attribute_hidden; extern void *__libc_dlsym (void *__map, const char *__name) diff --git a/manual/tunables.texi b/manual/tunables.texi index 26fba6641d..be36d52cf9 100644 --- a/manual/tunables.texi +++ b/manual/tunables.texi @@ -381,6 +381,10 @@ Any preload libraries. @item Any library loaded with @code{dlopen} with @code{RTLD_NODELETE} flag. + +@item +Any runtime library used for process unwind (such as required by @code{backtrace} +or @code{pthread_exit}). @end itemize The tunable accepts three diferent values: @samp{0} where sealing is disabled, diff --git a/misc/unwind-link.c b/misc/unwind-link.c index 213a0162a4..7267ecbec3 100644 --- a/misc/unwind-link.c +++ b/misc/unwind-link.c @@ -48,7 +48,7 @@ __libc_unwind_link_get (void) /* Initialize a copy of the data, so that we do not need about unlocking in case the dynamic loader somehow triggers unwinding. */ - void *local_libgcc_handle = __libc_dlopen (LIBGCC_S_SO); + void *local_libgcc_handle = __libc_dlopen_nodelete (LIBGCC_S_SO); if (local_libgcc_handle == NULL) { __libc_lock_unlock (lock); @@ -100,7 +100,8 @@ __libc_unwind_link_get (void) __libc_lock_lock (lock); if (atomic_load_relaxed (&global_libgcc_handle) != NULL) - /* This thread lost the race. Clean up. */ + /* This thread lost the race. Drop the l_direct_opencount and issue + the debug log. */ __libc_dlclose (local_libgcc_handle); else { diff --git a/sysdeps/unix/sysv/linux/tst-dl_mseal.c b/sysdeps/unix/sysv/linux/tst-dl_mseal.c index 72a33d04c7..da1a3ebe5a 100644 --- a/sysdeps/unix/sysv/linux/tst-dl_mseal.c +++ b/sysdeps/unix/sysv/linux/tst-dl_mseal.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #define LIB_PRELOAD "lib-tst-dl_mseal-preload.so" @@ -70,6 +72,7 @@ static const char *expected_sealed_libs[] = LIB_NEEDED_2, LIB_DLOPEN_NODELETE, LIB_DLOPEN_NODELETE_DEP, + LIBGCC_S_SO, #endif "[vdso]", }; @@ -100,6 +103,13 @@ is_in_string_list (const char *s, const char *const list[], size_t len) return -1; } +static void * +tf (void *closure) +{ + pthread_exit (NULL); + return NULL; +} + static int handle_restart (void) { @@ -108,6 +118,9 @@ handle_restart (void) xdlopen (LIB_DLOPEN_DEFAULT, RTLD_NOW); #endif + /* pthread_exit will load LIBGCC_S_SO. */ + xpthread_join (xpthread_create (NULL, tf, NULL)); + FILE *fp = xfopen ("/proc/self/maps", "r"); char *line = NULL; size_t linesiz = 0;