From patchwork Fri Sep 9 18:30:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 1676177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=uclibc-ng.org (client-ip=2a00:1828:2000:679::23; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=VQWNAY3k; dkim-atps=neutral Received: from helium.openadk.org (helium.openadk.org [IPv6:2a00:1828:2000:679::23]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MPPkh56nSz1yj1 for ; Sat, 10 Sep 2022 04:33:16 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 9322531E071E; Fri, 9 Sep 2022 20:32:56 +0200 (CEST) Authentication-Results: helium.openadk.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=VQWNAY3k; dkim-atps=neutral Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by helium.openadk.org (Postfix) with ESMTPS id 940C031E00B1 for ; Fri, 9 Sep 2022 20:30:37 +0200 (CEST) Received: by mail-pj1-f47.google.com with SMTP id j6-20020a17090a694600b00200bba67dadso2410226pjm.5 for ; Fri, 09 Sep 2022 11:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=MZ+iGpMYPn/8L8Wi+d2WEKkIJ/fBrhj+wb7mduEmlOs=; b=VQWNAY3koYPiJBRruY08V3WbCQg3L2ayQc7yYpFBpshzG25p3StcIcCYJCT9FM2CvC 1a/Ew03piLlJQHD195HoilC89F/fCOhiyjYPFl+ONdy0iT2g7S+yXRWiig3yYIfblgDi u4lzQy8Wf6wQ64N0naKcXXulLfUouQlPlrWuvyBSHHR1TpxeyXMi05KdIOwiPzf3/TXk MG+Wt9mXXO/lUcXYN9p6/ge/375vqAJUB15FF46Qylr/j3tRqC7sHL3RXJR0jrCL7KDw 1NgnZhvbfqInJ/Os09Ze0GYtgwJIgbs9zlg1CSRNE6I6TFkQkFCm3+QM+qRakhrlEwml x8VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=MZ+iGpMYPn/8L8Wi+d2WEKkIJ/fBrhj+wb7mduEmlOs=; b=berpDJCMl0KYRvxKq6KFqZ6ygKKeqLsIMK9FZdrBu0xrH5jq1coPS8KzljwazCEYuJ 7PTbcEfe7KvRLI+ISkS+MUEdhpqydeM1RZsXrCqTF8fI9iEiZSG6rAoRqjmfgOouJ+EW mZcIbCAWUy+uTBQ2p5pVXZ23jPgj/VgOQ5fqMk4V3/7GH+bSgeRjvTl4gOe7SzMNx0Gv JxLDdAghdiQWl02Str2t/vzt9wlnZ0nTaVB0ZWh8o4a0nXOS+cDuNPClrVAYYBmQKv1h XXzEcgVZZTp3DgaN5pqEPSNZCLOWuO43wqqH59CnmW/Us4GcLYw6TRuU+IHQshOJ4IHW kmkQ== X-Gm-Message-State: ACgBeo2uxhLrSPEoQDssFKTCtSHwKMwxQ6m0d6zBvk1NLJ/9vJrGLt1Z mvDycRx7WmFomjHE6o506L5Kq6YFmzYCgw== X-Google-Smtp-Source: AA6agR5hNW/EwucEd5MNxTTNiBGNM4jciZAHfAjK1ajT3y5yBffzLouSthbbnV0qvTkWVdn71SB7dQ== X-Received: by 2002:a17:90b:1e0d:b0:202:91ec:e167 with SMTP id pg13-20020a17090b1e0d00b0020291ece167mr3165148pjb.174.1662748235052; Fri, 09 Sep 2022 11:30:35 -0700 (PDT) Received: from octofox.metropolis (c-24-130-93-68.hsd1.ca.comcast.net. [24.130.93.68]) by smtp.gmail.com with ESMTPSA id q6-20020a170902dac600b00174a4bcefc7sm755709plx.217.2022.09.09.11.30.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 11:30:34 -0700 (PDT) From: Max Filippov To: devel@uclibc-ng.org Date: Fri, 9 Sep 2022 11:30:07 -0700 Message-Id: <20220909183009.4111393-4-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220909183009.4111393-1-jcmvbkbc@gmail.com> References: <20220909183009.4111393-1-jcmvbkbc@gmail.com> MIME-Version: 1.0 Message-ID-Hash: WBW7S5S6HMD3VXQDDDJCH2QSKPU2WXLB X-Message-ID-Hash: WBW7S5S6HMD3VXQDDDJCH2QSKPU2WXLB X-MailFrom: jcmvbkbc@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: linted X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] [PATCH 3/5] xtensa: make GOT protection adjustment conditional List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Xtensa PERFORM_BOOTSTRAP_GOT macro uses mprotect to make bits of GOT writable, but noMMU linux kernel returns ENOSYS to mprotect syscalls, and syscall wrapper tries to update errno with the error code. This happens well before the relocations are done and results in writes to unrelated locations, memory corruption or protection violations. Split GOT protection update from PERFORM_BOOTSTRAP_GOT and only do it when building configuration with MMU support. Signed-off-by: Max Filippov --- ldso/ldso/xtensa/dl-startup.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ldso/ldso/xtensa/dl-startup.h b/ldso/ldso/xtensa/dl-startup.h index db223feadc90..19955ffc77a5 100644 --- a/ldso/ldso/xtensa/dl-startup.h +++ b/ldso/ldso/xtensa/dl-startup.h @@ -88,12 +88,11 @@ __asm__ ( /* Function calls are not safe until the GOT relocations have been done. */ #define NO_FUNCS_BEFORE_BOOTSTRAP -#define PERFORM_BOOTSTRAP_GOT(tpnt) \ +#if defined(__ARCH_USE_MMU__) +#define PERFORM_BOOTSTRAP_GOT_ADJUST_PROTECTION(tpnt) \ do { \ xtensa_got_location *got_loc; \ unsigned long l_addr = tpnt->loadaddr; \ - Elf32_Word relative_count; \ - unsigned long rel_addr; \ Elf32_Addr prev_got_start = 0, prev_got_end = 0; \ int x; \ \ @@ -125,7 +124,19 @@ do { \ prev_got_end - prev_got_start, \ PROT_READ | PROT_WRITE | PROT_EXEC); \ } \ +} while (0) +#else +#define PERFORM_BOOTSTRAP_GOT_ADJUST_PROTECTION(tpnt) \ +do { \ +} while (0) +#endif + +#define PERFORM_BOOTSTRAP_GOT(tpnt) \ +do { \ + Elf32_Word relative_count; \ + unsigned long rel_addr; \ \ + PERFORM_BOOTSTRAP_GOT_ADJUST_PROTECTION(tpnt); \ /* The following is a stripped down version of the code following \ the invocation of PERFORM_BOOTSTRAP_GOT in dl-startup.c. That \ code is skipped when PERFORM_BOOTSTRAP_GOT is defined, so it has \