From patchwork Wed Jul 31 20:02: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: 1967282 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=TSCP7Kjs; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZ32P0qqSz1yYq for ; Thu, 1 Aug 2024 06:03:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4B534385828B for ; Wed, 31 Jul 2024 20:03:55 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 589B13858283 for ; Wed, 31 Jul 2024 20:03:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 589B13858283 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 589B13858283 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::632 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722456208; cv=none; b=xk37XJ5l1dxBPM5RImBLOBcwR4IHQ65LoucU/kCizQMD/vbxVPFUFKOQ2EgoJJsqq2qfxXl1YpXSuY5qqtFm5HH+hC2Dtv7K0bJb8erUWUZaoIoBWxKwo4Wjtl/i9P33ICRKIRbX/hNnoSOUBILHRUBumktjxFfxi9GuNQV91B0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722456208; c=relaxed/simple; bh=5jiJmsfvQMHb7PuaooYFabjo3SJSxld3HJVCtpZR2ls=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=G3+ETeFFvalsvnl1U7APzaPC2D+omoFMATnX2iqjWicBpuvpXbPfpiPHsk6R3EFiTO8y61LytxT5Oo6a5LVzL6wgxvu1j7s4Gx8Z09owqB/vSWfwhJ8jz1yBeudxVTjH9A8Kfx/GNftBHw7UzBxSYgzuy+XwcKWhuH/VPMDlc3Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1fd9e70b592so42803825ad.3 for ; Wed, 31 Jul 2024 13:03:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722456203; x=1723061003; 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=Fgt9d5LP1LprzxcdzicBf+tjVmYkCVud6ErtxvVCba8=; b=TSCP7KjsaaPMO/FJGfugZB3tkes/rg1skOS+wnmI+Tpg0gfpcllFny6TeK39ZhRvHv wDx5lRY7UGOaD15LxzX5avVG/ONifCo5eKAI9hLgWEwE3tK1hKv9Stkq6vELsrElrXZF eKFtJodly4Vll69HR6yzZYvfbYa6dDm2x6OoZZa2imacOG8BrTrYKtgCDgUluIXUend6 Na1uRRTJ/xF/bWHYCzIis+gkLZojkdUxijTAWW8e7SFc2TpTAtV62pWOxkLKfHbC1wCx 9oHron2w7r3P7wKnr857MJsrqMZTAf2AMmR7YOSc+2iOaO7nnHA01DvzaXe+aj7IDeVx Vy/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722456203; x=1723061003; 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=Fgt9d5LP1LprzxcdzicBf+tjVmYkCVud6ErtxvVCba8=; b=DXXqSZlql1VN7NB8pe28UxnlG8IDcYEzxQNt/g7siatokfRDhlhhfWnEnfLfHBNjOG xXqD461IBAlAJgm6b8mZC/FgMN2uafGaz4p+DNFyVJI8hAJCvD9iY/ndCvvlpG1mUhzK 41n+CpKXv0s18J96y2FVX0+AtGe2mxeyNHo96pNfdMINlTcHPtZXYsRTt0zaoWIVcfJ9 Uyq6yj9ZstzaceX01QzpX1HO4Zy5hUs7ir9dvaU9GSvnzHCzydaver7JnYK0REijXl9i AJoppYlPtZtordNouyTQ5ovZ/UFr4Ipo9E8oeH0EHYfDNP6FneWUKi0Vy/pxKgrDFRlr PJSg== X-Gm-Message-State: AOJu0Yz2hFISuLaN5fZwrmRAeb63YYAU5cpEYDiSKlr8r3FizpHhqmSp ofd+0qRDwl5kVbliSVygjQQLAcsrCcX32WZl7theZEcI2njwP25C2BvyzNLjjZdddgGk2twOcUH z X-Google-Smtp-Source: AGHT+IHC5r8Hm3R0x8DeD0iZf35dkNwPpNMvPCNzGvS6j+SAzdRdBcld+5O3QGcFoGve6BpT2ssx3w== X-Received: by 2002:a17:903:28c3:b0:1fc:86cc:4254 with SMTP id d9443c01a7336-1ff4ceaefbcmr4207625ad.33.1722456203636; Wed, 31 Jul 2024 13:03:23 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c1:1944:b913:6070:fef0:3852]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7fbd8d4sm124106725ad.271.2024.07.31.13.03.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 13:03:22 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Stephen Roettger , Jeff Xu , Florian Weimer , Mike Hommey Subject: [PATCH v2 4/5] elf: Also parse gnu properties for static linked binaries Date: Wed, 31 Jul 2024 17:02:07 -0300 Message-ID: <20240731200307.2269811-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240731200307.2269811-1-adhemerval.zanella@linaro.org> References: <20240731200307.2269811-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 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 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~incoming=patchwork.ozlabs.org@sourceware.org So the static binary can opt-out 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 8290a380f3..a02ae712b3 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -45,6 +45,7 @@ #include #include #include +#include #include extern char *__progname; @@ -336,6 +337,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);