From patchwork Fri Nov 29 21:03:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 180502 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp2090092ile; Fri, 29 Nov 2019 13:04:25 -0800 (PST) X-Google-Smtp-Source: APXvYqynWncqu3hDVjdjsNA78nZrCZJAYKiqkPYPqD3S2HAGnk6xAj0epQEI/lirsxVILskEh/G/ X-Received: by 2002:a17:906:7042:: with SMTP id r2mr63126069ejj.166.1575061465363; Fri, 29 Nov 2019 13:04:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575061465; cv=none; d=google.com; s=arc-20160816; b=AKtP/lxo2E1PGp+Q+XqRp3bYD0nIaWz92tRpFuwhMnsa961kJEt5xq1JJ/ysl5MXdo MAwEZdxTq9NlQSoRJVumSUDLNNSz0fkoPYFRHWX74EmyhiN5uLrJQK4bNPJQRI5cYhbp WZU+vVN10lavQEZK+jPhvDzWmIhe7nKhIifVz5x6+ImUUd5tqurGLSI7aeWtEjuBTdKl AUz/an8tK4asyBZOVPLd9wtYZ2HEnC4y2nx+MzDZEQNqFYCrRMu/bq7/qe46W0lZW+fd gJAdNad69rW6jNhjrleACr/kcoh0rLr85cOV/Jkq1fQECaOyA85nbywsd630uwxLKBo4 9OZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=uZ7ljY/tPkpsfNmkSLtnbeMdTkZ8/CcTaqA/754S96I=; b=mgMJ7MhDa9iUE4nX8jDA9TeZ9KA3pWQp3H8Vk45cRfg+X6d8SpIGNraCMnth4/64hN jtMZuxLqeH7eBTC7tY0M5Gff5/N7WUM2gaWUt5MamnlvahbeVK3w8DqcKVTzAEd7PMAd qn+5g451hLbxP5QgUb+P7p+lOEV7e/dh7OCR+sWmwqBrJoqICEPUuQs9GDsbVWx3RuLj Pbr8HPra7Ci4qKr4hRZm2aSj+l7fcZw90hNE+tlRy7OyKzVl0fxPDM2Q/ICTCOXFJDNE kvSxJpfuENeiKzLJswArwQhqnviS605m5pIfOlpWDjJ/yLmdB0jiszQZ9T2a99R6KXYu I4Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=yFlFTJIk; dkim=pass header.i=@linaro.org header.s=google header.b="T/qG1jGa"; spf=pass (google.com: domain of libc-alpha-return-107562-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107562-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id d18si3572489eds.125.2019.11.29.13.04.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Nov 2019 13:04:25 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-107562-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=yFlFTJIk; dkim=pass header.i=@linaro.org header.s=google header.b="T/qG1jGa"; spf=pass (google.com: domain of libc-alpha-return-107562-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-107562-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=NLjA5+U/wA1tiey/rvYyoADsE98w6Ws imJ3yTb8ZZhj3ai8NJMSBsFwDhpO76/mu6ngnc3zAmdEUEb2QLcp46x++0w/ikJ6 zz3eNiAp2vEb9EGOxBjzyWYT+9e1KhsDUVandWHou8ZQLnR43uE9k0QT6HzloAf2 8tG3q5mo6NU4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=Nb7wWiSgRFg9wVn/2EZoscFtwg0=; b=yFlFT JIkU2YkPayRo+Jy8Kv1Y+5fDlifrh72G4afmkjBrHUCluwglLHFQicXKWF+bSuh4 UdiyE8W4X+4MJ5qbnnINyTd+wKJ/woKaGMCzBzpHeVb3EhLT6XG96MVBHe/sDP9f FCpCieaK/BgTj6/W3tdxC+TJW+VNs3ZrOxXfBk= Received: (qmail 72392 invoked by alias); 29 Nov 2019 21:03:44 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 72334 invoked by uid 89); 29 Nov 2019 21:03:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=sk:sparc64 X-HELO: mail-qk1-f195.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=uZ7ljY/tPkpsfNmkSLtnbeMdTkZ8/CcTaqA/754S96I=; b=T/qG1jGaDm1rpRD6rX9fMr0FRuCwXewIEnSnanmw8jJe0qXWmA+Pt1LnQoyL2a87on 8nIgEIOFJiTTffWkDKTc/DhTWC/hUCUK0QPossAMKK35zlTViLVTZfAnwXFKsIkDEz1e vTm/HLX9BR2LtLwXGBMXhOhR7OjzVOv5iOw7sEMsPK+R++vXa7xEcZx2BOBRKN/nF4Qo 7h3LCRH9Wja1EFDlLLacb07q8VzV4XHROkdwPs/V3MumG8LQnitc9Rfj/7UnApZ+eGiN 4DoJ0VmNbdo/5UXumSvakSnq5LkFHhxa/bAhA2IKdDfAgZBFWpdc6XxwldEIF6VLofED PU4A== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 5/7] elf: Enable relro for static build Date: Fri, 29 Nov 2019 18:03:25 -0300 Message-Id: <20191129210327.26434-5-adhemerval.zanella@linaro.org> In-Reply-To: <20191129210327.26434-1-adhemerval.zanella@linaro.org> References: <20191129210327.26434-1-adhemerval.zanella@linaro.org> The code is similar to the one at rtld.c, where its check for the PT_GNU_RELRO header values from program headers and call _dl_protected_relro with the updated l_relro_{addr,size} values. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu, aarch64-linux-gnu, s390x-linux-gnu, and sparc64-linux-gnu. --- elf/dl-support.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/elf/dl-support.c b/elf/dl-support.c index 5526d5ee6e..bdb5c2ae91 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -367,14 +367,24 @@ _dl_non_dynamic_init (void) if (_dl_platform != NULL) _dl_platformlen = strlen (_dl_platform); - /* Scan for a program header telling us the stack is nonexecutable. */ if (_dl_phdr != NULL) - for (uint_fast16_t i = 0; i < _dl_phnum; ++i) - if (_dl_phdr[i].p_type == PT_GNU_STACK) + for (const ElfW(Phdr) *ph = _dl_phdr; ph < &_dl_phdr[_dl_phnum]; ++ph) + switch (ph->p_type) { - _dl_stack_flags = _dl_phdr[i].p_flags; + /* Check if the stack is nonexecutable. */ + case PT_GNU_STACK: + _dl_stack_flags = ph->p_flags; + break; + + case PT_GNU_RELRO: + _dl_main_map.l_relro_addr = ph->p_vaddr; + _dl_main_map.l_relro_size = ph->p_memsz; break; } + + /* Setup relro on the binary itself. */ + if (_dl_main_map.l_relro_size) + _dl_protect_relro (&_dl_main_map); } #ifdef DL_SYSINFO_IMPLEMENTATION