From patchwork Mon Sep 30 20:08:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 831572 Delivered-To: patch@linaro.org Received: by 2002:a5d:66c8:0:b0:367:895a:4699 with SMTP id k8csp2120399wrw; Mon, 30 Sep 2024 13:09:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVSzHxpW0aUBTTHYv+EL7sxI0QUDEwQ4EjJgAuYGtR0wRK7VVr/E0+OeKP4ULeYhi7nJcaPLw==@linaro.org X-Google-Smtp-Source: AGHT+IHivDBqm5zQjqxTUSJaSoL/zbCQ5b1KorZww7olCDz27VFec14SJb+LlTzHl2ksw0dUNHE2 X-Received: by 2002:a05:620a:3907:b0:7ab:36c7:b9f6 with SMTP id af79cd13be357-7ae37855d20mr1805370585a.31.1727726962520; Mon, 30 Sep 2024 13:09:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1727726962; cv=pass; d=google.com; s=arc-20240605; b=MpPpirGtmqffpdhUxvG5vXkiz+OShvsZLQD2vtuK6jyAPyl7bdRvbpN1TxEBIMLaIZ yB0XRPIfnwd/XIvW0g60ZVXNtOMP/SurzQW57BZniCHi0dgldwJskd9buiRjf0/RmAcV eRkyDrIgL7jQiV131rnO9lLBr76xJA4hJYiGBjSB0jdNxmJo+hfOilR8Iolkdw/z2SiZ s8v/GwQNda3CgADvNrj3NXyFHniI9peuU40sg8bVLsLB0m7SgehNRg1wabji4ksXvhLE yYDDqdMb0NRj4oC085aKgx1WZiNVVRlLanL+Vye6EzJnRfJQ2Zcio8uqVGphCDptvjq9 u/FQ== 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:arc-filter:dmarc-filter:delivered-to; bh=/Ev8XSb5kk42nkyW8i5qwZA6ZqW5ViycIWf1gef3Y1g=; fh=3tUIaab7WH3k5DYf15UFmY7vUQNGmrLDHVJFJrkNDfY=; b=F+9MKk7Rb5i73Nw/0ROZkK6l8I4xzghqWjxLMpoTC7OMO2JOVS1q3Bt+NMj88zJoQg rYjQWbDBs8+9QVAWfmrrM/Nwg1VBiSzORVLJPhVUffYf83ciAXm/RhuihU4Ly7lV8825 487vnRjy3t/5Ig9d7NR6vqghDS6XLux37txU6VJDlmbWawdKf0fFVdPiWCe2FXWEqS/o Kg5RCDBQGKxakjNqm0LWoYwmwEXI3PsbySl8wMzoFgd5AbJDVTsWUHo7cA5F3K9D4ltD FFtLHMkJwtfGbHLoiQEgoiIL4s5YXaU9r2JdNvEfAGyFCKWI/BDYQdFv+g2e8zU1LYTH 8Bwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cTKO5tEH; 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 af79cd13be357-7ae378381c4si922876385a.292.2024.09.30.13.09.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 13:09:22 -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=cTKO5tEH; 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 117B538449D0 for ; Mon, 30 Sep 2024 20:09:22 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id 6D46738460B2 for ; Mon, 30 Sep 2024 20:08:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D46738460B2 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 6D46738460B2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::234 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727726931; cv=none; b=EJ8jKkbUv8wT/uYo7rJp0tytLR7PorFu3GK+j20+3fx1iXURhW1n5lg+SzgNcv+083YlQNytaVMihcBC5qaxEvgl/xxn70UDpd9+zJEOomG0q2hNGJhLghRK//I2QuPxXpiOXxQ0E5CVwu0rmMRSpKTslnJq4O8fddLiKgCMc1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727726931; c=relaxed/simple; bh=X91pcQ+0YKdGOgxrL5b35s6+P0LD3m7ILCR+K8KY3lg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ogF/zER+d9KjyOX82epmHnsTh3G/neXE3gEP/mHrdrV2t9kC5g+2zRxfSjkotSx7L37uDUPTqLACMFMWbgqU/yk+Czvui1ikSxSnVfnvmpklq1QIMo3Jrdo2iPLecgZYcdI4ioVLznQgzXv9Yr7JYhTUaoRgeg7CXDgfG9l+hKk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3e03f8ecef8so3050896b6e.1 for ; Mon, 30 Sep 2024 13:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727726927; x=1728331727; 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=/Ev8XSb5kk42nkyW8i5qwZA6ZqW5ViycIWf1gef3Y1g=; b=cTKO5tEHH+GKKUC7n8Xul/brHkjRUMfE2cGVuflY8Frt3633nlzlpTE0e1VA//ENsk CSIy5LCvKncFxYlAUqYsSNdRxXDPRTQ3AWUpSO0OUleycf2QEwdyo885JyEGEFCOKu/8 w3VtJgwjDkS7ib3TjjnrNlKfu2b2tbcY6y6PJ4ac+fOZKwohhIMZv6Eods5t51tN7Mid cN319yx/voWCSCDdGIGJsTgiCDKxP0TaSix5nrVP0ll3+CjDU8BRSc9d1JbOVNxLGdyi Tk1HIwgiFN3GyIvj0R2l312LTkCM48+ZvYY9sBvDSmSHlE75hlEcjzmDfjgbiIdCnbSe uCHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727726927; x=1728331727; 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=/Ev8XSb5kk42nkyW8i5qwZA6ZqW5ViycIWf1gef3Y1g=; b=UPynt8B5uiZd7z1Q8Q1ZWkuwN1SE6iZbb8zNXP99AOejD7rpH3LCDJDP6oUDs9gy9a vOuzSqEiISqFxSJdn/u7EsysLDNpz9d0X+nVL/ky6/7gm/AX0dXbhHo9AYQf3h+eLS8q Zevn4BxB4n7TKcC7GJ6+BV4JUzBQCYAqYzk9hs7/pViHMOI1FbBVPud5ciVIx221xvpD rkGwrK0+ndeBR0RxOEFfZlQ0jewcxzCYAzvsZTj4KUCTQTNviKOR4Ae7GfyonXS8MO/7 WKpZdI8aCz3do6r4nLFxbd0iOP91z5M5Q0CCOiUlhcc2ARUfYJSTJBW0bKPRqDeBuR/1 qwAA== X-Gm-Message-State: AOJu0YyYi5F3iBS90dtIeR5a4QIi3i+4uLNjtMkMORcd0YUIhm8G32vr EN78tr8lnFGWuGG7Z7CJ7nvYcWNtmGAbIBRC8nCdDOX/pg1tt6ONzbDPBJqVAtS1QQBHfgq7Pnr /vY8= X-Received: by 2002:a05:6808:181c:b0:3da:a032:24a6 with SMTP id 5614622812f47-3e39396963bmr10248776b6e.19.1727726927106; Mon, 30 Sep 2024 13:08:47 -0700 (PDT) Received: from ubuntu-vm.. (201-92-183-102.dsl.telesp.net.br. [201.92.183.102]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e6db2c4845sm6869565a12.43.2024.09.30.13.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 13:08:46 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Stephen Roettger , Jeff Xu , Florian Weimer , Mike Hommey , Adhemerval Zanella Subject: [PATCH v3 2/9] elf: Parse gnu properties for static linked binaries Date: Mon, 30 Sep 2024 17:08:24 -0300 Message-Id: <20240930200831.1669010-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240930200831.1669010-1-adhemerval.zanella@linaro.org> References: <20240930200831.1669010-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 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, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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 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 451932dd03..bd02a77d1a 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);