From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id F2B84394D82C for ; Tue, 3 May 2022 15:37:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F2B84394D82C Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-160-nsAaaeQuMByawKtvK79ZzA-1; Tue, 03 May 2022 11:37:27 -0400 X-MC-Unique: nsAaaeQuMByawKtvK79ZzA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 408363838FC9; Tue, 3 May 2022 11:53:21 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4DC7402183; Tue, 3 May 2022 11:53:20 +0000 (UTC) From: Florian Weimer To: Szabolcs Nagy via Libc-alpha Cc: Szabolcs Nagy Subject: Re: [PATCH v3 1/2] aarch64: Use generic argv adjustment in ld.so [BZ #23293] References: <4a157fa95462503bd1b6c3218644a0334ae52325.1649854695.git.szabolcs.nagy@arm.com> Date: Tue, 03 May 2022 13:53:19 +0200 In-Reply-To: <4a157fa95462503bd1b6c3218644a0334ae52325.1649854695.git.szabolcs.nagy@arm.com> (Szabolcs Nagy via Libc-alpha's message of "Wed, 13 Apr 2022 14:00:22 +0100") Message-ID: <875ymmx26o.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 May 2022 15:37:37 -0000 * Szabolcs Nagy via Libc-alpha: > When an executable is invoked as > > ./ld.so [ld.so-args] ./exe [exe-args] > > then the argv is adujusted in ld.so before calling the entry point of > the executable so ld.so args are not visible to it. On most targets > this requires moving argv, env and auxv on the stack to ensure correct > stack alignment at the entry point. This had several issues: > > - The code for this adjustment on the stack is written in asm as part > of the target specific ld.so _start code which is hard to maintain. > > - The adjustment is done after _dl_start returns, where it's too late > to update GLRO(dl_auxv), as it is already readonly, so it points to > memory that was clobbered by the adjustment. This is bug 23293. > > - _environ is also wrong in ld.so after the adjustment, but it is > likely not used after _dl_start returns so this is not user visible. > > - _dl_argv was updated, but for this it was moved out of relro, which > changes security properties across targets unnecessarily. > > This patch introduces a generic _dl_start_args_adjust function that > handles the argument adjustments after ld.so processed its own args > and before relro protection is applied. It sets _dl_skip_args to 0 so > the existing adjustment in asm is not invoked. Each target has to > opt-in to use this new adjustment since some targets don't need it. > Once all targets are updated, _dl_argv declaration can be simplified. > > A new _dl_start_argptr was introduced because the original sp is not > passed to dl_main which now has to do the adjustments. > > -- > v2: > - use p != NULL, and a_type != AT_NULL > - remove the confusing paragraph from the commit message. Looks good to me. Reviewed-by: Florian Weimer Thanks, Florian