From patchwork Fri Dec 6 17:37:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 847838 Delivered-To: patch@linaro.org Received: by 2002:a5d:50c2:0:b0:385:e875:8a9e with SMTP id f2csp910306wrt; Fri, 6 Dec 2024 09:39:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXLcTTyiaIYNSIVGn6QzBLMJtbT8wrPdkFLO8gOHggur36GfWD4p+ZD3VFTQaHFaHn/Fg2x1w==@linaro.org X-Google-Smtp-Source: AGHT+IECkDlECvQ89yDr/FqQbpUFIUAvQ2r/XsptqO+zgj4Mp9NH0VBlIX8EFeqvdVJJhKfn4MVE X-Received: by 2002:a05:6214:cc9:b0:6d8:b2f2:bcb8 with SMTP id 6a1803df08f44-6d8e712c0b7mr60755236d6.8.1733506779079; Fri, 06 Dec 2024 09:39:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1733506779; cv=pass; d=google.com; s=arc-20240605; b=b3/8p16LNzuZCrz7cgQLW/dnlZGHgfwAN1K34A8PsfUU8qUkxh4nZs1uK+iuOhpKYs yrKEQzlnSdn/lnekjiOkblvQUrWPe7y4HiK9Z1ujG0lHA7Ua7m2NbtL9KNPu+FbYfWf1 5fpOYI9xOEIxV5kBsUZ7DxOmLB+2rXrnX2oSqdkdIVW2Fk8EeCATvfXdhlS+kpfDUjxC M6BXwH+6G+xkGATCj1l1M/ohJ0QvSCVL528zegk/TDInWPqyY6OmRHR093mqfuONKsvG tU90/5uoB/AifK4T5oekCKVLbbZClkEzICRU9dP++1lzJ5lR/s4HysfCYrzP/iw+8dO7 iVQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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:dkim-filter:arc-filter:dmarc-filter :delivered-to:dkim-filter; bh=eLdwvVMsoFovliCe4lcLV4NXSopnP16JsgNztuRS9A8=; fh=39H2oohB6ZYGhyKHcKf9chiYMCdt+XzUdxuRAxp69qM=; b=a0nfzgrZhvy6083HhLomOEDr4GRMyPYJHdnQKE5AeKmdPSj4TE9iFAeiY7nRyKDB+a QV9oMMnjSOrkLsWH1SlToSgij3FWHr0Ke7UcOHYkn9wYlsfHwJADY8iBBteYKV4ma63B i1HA5xA3d0sHd6f5ElkjO9blT25PzqJk3oq8R1gZYv50sfLGLxfMfKSMFbnZ5YBvANTH yZlLLtSuuEbEI5litIK/vn2Vh/eB/85g3q3AQiBd+Gfz18IY1DcJDZJxzSOqJ4Jnfrxf R2d3jtTHmnFhNVx5SJ31wQCEr0cmvE/GwH0Qr7fP3r0nEMURf4fdvKVXkLZYD9iuoIJW rnog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XXR3htqH; 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 6a1803df08f44-6d8dac0b481si39582866d6.325.2024.12.06.09.39.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 09:39:39 -0800 (PST) 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=XXR3htqH; 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 9386A385840B for ; Fri, 6 Dec 2024 17:39:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9386A385840B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=XXR3htqH X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 439183858C42 for ; Fri, 6 Dec 2024 17:39:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 439183858C42 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 439183858C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::633 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733506742; cv=none; b=ctZNyoKWnJld3zhKU0ijbPq6/ZGq4vwBZC3nt80Ven6b4OyOM1ATXSu6FbiqRAFZdZhCnUz3MCqTOJxLX+rASSf8BlmrjgwVWwgrnSKGZKvfYSDWzLzohp1d3VjLq2DhhdwkWsPU0lNrt/vzC6FTNt/I4XZE6YjtwMJcx7Q/0kU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733506742; c=relaxed/simple; bh=Yu0Ox2J3hWIGFgKoaDMg6x2f9BD+FTjvKoS4XlB+EFo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uuj059nUPvlIfxS+SkhQmwfwN3FmhiP1dag4aw2IZJ82O6ZeoH04R1ceKvJELlGAhYjuZLbL5t0Tyxs0zmFo8mQ+UiqK+065lsffeLCM096LbDUaQR1oGgJpQjNfQEQF2wMlgUu+dw1l+0WIDssxYzlK0F0ouKhhN9iUldKaNXY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 439183858C42 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-215e194b65aso22459715ad.1 for ; Fri, 06 Dec 2024 09:39:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733506741; x=1734111541; 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=eLdwvVMsoFovliCe4lcLV4NXSopnP16JsgNztuRS9A8=; b=XXR3htqHRpu7yYajaOCK62e12XFYGycITMmBorKFh5eIpyudtRmuwpPaX9AuMI/JVi NTsOU9Hqa1AFLJWfrSSdbcUg9Fe/I7xEyfqWd7H+Ai/8x11+uLi8a6hds4Wx0hshbben YkHiqBbs5cyTSbvgonjrXiucaAYqYVzdrQuRY3a3bOiAz6OQtVK/V922Ci/wizET956w F21l4SFeYKnl7lHUMW73xtCUGM8DR7ojlfq6kc5Ux2Ek2Vl8gqdzB9ndwNTn4q6LSgPG sGxsGHdwJxgzjPW58ooc5GQ+0Pa1l3LBM2cgRr0obGhPFSTEIxV77ah1xc8r6UVW2hGW 5rCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733506741; x=1734111541; 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=eLdwvVMsoFovliCe4lcLV4NXSopnP16JsgNztuRS9A8=; b=W1qv1/J+u+WwXg1N0lvjSSJV58S/J0TjgVc6bLMFpv9RjBrnypsSFAK5C6R75QP7Ms JtsxIufwINtN2KyyyJqAVzfCE0xStOWitiNnlkQXTN9/uR/v2278fKIdAf+GGVHdzsbj 4RCmheyEhVX11EYu0KFcrJ55aKeU1ED/nGxkIKL8tit7Id3KHu8AnN+Heync/Mb8R8is grOgBTeAxAKVJ6QwjV5JZ4oOm+M/2vgxao8ML7rtspZJoqyD7QIXj0oGVJTyQ5RRfpHc By+bnXtClSovyw3lwjfofscM8Sh13o0Dx+8nS4h/Ho/N1HNE+OjravBux6m8o199yApa TxNQ== X-Gm-Message-State: AOJu0Yxl/OpiRSLS2rm8c6AQe9yFGqpI/7H19nBFa0RwyCWrUIDouydN 15gSQCjF8EsMrB9STYWCPH3eu2iODUeuDusVN75AhB6RinBSX962nQXa3Zw2st40fxhiWU5eOaJ m X-Gm-Gg: ASbGnctcgstNx2BqqFsjhtKpayVED5Nu3t0hcRSdgngP2+3zzX8RAnNfPq7ZQJxvYUh M7pVgNDzQooSblpLKbpMa50ru8N2klNf1iMC2+WnqzN54Xrwo6h4s6tsPBEB3/KYPR+ykze9u+x egf65AJ2Ym+0Uy9ruGxWIaO5kqjW1ys3Bra9IxohJO7P9QJxfzBO/fLjIoQxvBVbYawu3834wPI BQNm+lP4cLm2Yd91hRpdQh4E53oUbfMeW4mu2ufQ9k1wCxE1CEFhyPrzyUZrQ== X-Received: by 2002:a17:903:1d2:b0:215:7cde:7fa5 with SMTP id d9443c01a7336-21614e06d80mr57142865ad.56.1733506739607; Fri, 06 Dec 2024 09:38:59 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:2d1:1460:dd43:b597:c3fc]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-215f8f29635sm31409495ad.241.2024.12.06.09.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 09:38:59 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Jeff Xu , Florian Weimer , Mike Hommey , "H . J . Lu" Subject: [PATCH v4 2/9] elf: Parse gnu properties for static linked binaries Date: Fri, 6 Dec 2024 14:37:50 -0300 Message-ID: <20241206173850.3766841-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241206173850.3766841-1-adhemerval.zanella@linaro.org> References: <20241206173850.3766841-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 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 So the static binary can opt-in of memory sealing. Checked on x86_64-linux-gnu. --- elf/dl-support.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/elf/dl-support.c b/elf/dl-support.c index ee590edf93..f0b6be07e9 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -45,6 +45,7 @@ #include #include #include +#include extern char *__progname; char **_dl_argv = &__progname; /* This is checked for some error messages. */ @@ -334,6 +335,18 @@ _dl_non_dynamic_init (void) _dl_main_map.l_relro_size = ph->p_memsz; break; } + /* Process program headers again, but scan them backwards so + that PT_NOTE can be skipped if PT_GNU_PROPERTY exits. */ + for (const ElfW(Phdr) *ph = &_dl_phdr[_dl_phnum]; ph != _dl_phdr; --ph) + switch (ph[-1].p_type) + { + case PT_NOTE: + _dl_process_pt_note (&_dl_main_map, -1, &ph[-1]); + break; + case PT_GNU_PROPERTY: + _dl_process_pt_gnu_property (&_dl_main_map, -1, &ph[-1]); + break; + } call_function_static_weak (_dl_find_object_init);