From patchwork Fri Jun 2 10:12:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 102461 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp927964vqr; Fri, 2 Jun 2023 03:35:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4zSS3eK+zFlUPmGA0vyCFNkkoGWgRb8UabtpXlYWuX7/lYBGeKmRBO54gly81w3RI3zqDZ X-Received: by 2002:a17:903:22c7:b0:1aa:86a4:37ed with SMTP id y7-20020a17090322c700b001aa86a437edmr1085163plg.55.1685702141073; Fri, 02 Jun 2023 03:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685702141; cv=none; d=google.com; s=arc-20160816; b=Pe+tXSCMzfnmWHxMrKTCBuBvQaUWmZpaGu7+HUrPZ+UbEcs5O7V0sk80WG/E3XU2Pg O+g0ORMBsYD4N9i6VeG+aS7P3e/JhSxulLHKM6rzmlhVMYEAmR4y5mxb0XyOnnuI1pkI uCkv8rcdowjWQlPCE6yXND0YmuggYNiMcpcKFelAaAsn8BJt5hpQWEEUn6IjDk1fX7GD fRz24V5JNQJ/i408gp2G89RDKj23u8kPUEWeNM2mwWx4mo5JoS+HjAHER0VNuhtTubk8 qakWOV9LpGKOC2K/Ji08xovd3cGOEQREptiA1R24Oft+L/QGdBveJITZfhB2Fld6wJWu YBbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=S3lEqGjsTGw1NWcFmbt4O+4A6ddMT7nl/cAxjp7Py8E=; b=FjT5Yai+SQZTHu/rdI8VDU1/HKrlP4T+d64UJHOBVE/3Yn9ycHwj9+O7zrG7WAbtdF +qDcvd55CrSCIiOKNTQFSlftgGMwgZr+Lqk4RooQjmhTEAY/OHPYQnA/L+6/Gb3J1xE+ SYtj6W+G9edtOuLnJog5ZGNbzwc/GiwGpUYFb5Zm4lXVAjSz8yC3Fm2d6+MQOGHd+ajp MZHSfUT2+jZP9nxuOvFChXvYzuw0ISYRCcFu8GyEKMswSIkkKEDHEsUn951yz6y/tD3f ZCASW2VPdWC3DbTkMWnT6/jszcjF8XlDnDLccGB3ujnDP6curoKg3wqSgcvlqHa/ReD0 5rqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GZ1i4lSN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u1-20020a170902e80100b001b1be1317a2si753161plg.103.2023.06.02.03.35.26; Fri, 02 Jun 2023 03:35:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GZ1i4lSN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235473AbjFBKXZ (ORCPT + 99 others); Fri, 2 Jun 2023 06:23:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235110AbjFBKWj (ORCPT ); Fri, 2 Jun 2023 06:22:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43F8AE4A; Fri, 2 Jun 2023 03:22:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BC4DE6150D; Fri, 2 Jun 2023 10:22:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40178C4339E; Fri, 2 Jun 2023 10:22:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685701349; bh=ygI81p6SqewQoIn6tCgoZLUH2Qo5tPVgo3BNvwGSS3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GZ1i4lSNKD6ujUUsHx+hPnCpXcwIdXt7P5tqVeJtNUBNzyDpooOlOTw+T21o+TsZv naJVHYDHvDFpzoY0b86GkXMYO5xTC/ZyTyTEqTpYFvgVj0WUt6vCGCLzH9QWjSzgJ+ /zlHY32uUjWUK6/K83Npl3OFBknz761RAdthFdtMKVkrDh8ngOd7itHF8mjqPA3pic oqJZSI30+M/doTqE8bM3PhF/Z88E+6P0U47FmAiCuWuIfAj25VzsJnJQSUJFw3uJmq IKHAMrwJWUWcpgcNxCn2MWywcOTMvNtaTOdSUWlYuL7/29Z3XWZDXQkyH3O+yc6HYn K+ej+axOgFS6A== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Evgeniy Baskov , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , Gerd Hoffmann , Dave Young , Mario Limonciello , Kees Cook , Tom Lendacky , "Kirill A . Shutemov" , Linus Torvalds , Joerg Roedel Subject: [PATCH v4 05/21] x86/decompressor: Use proper sequence to take the address of the GOT Date: Fri, 2 Jun 2023 12:12:57 +0200 Message-Id: <20230602101313.3557775-6-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230602101313.3557775-1-ardb@kernel.org> References: <20230602101313.3557775-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1770; i=ardb@kernel.org; h=from:subject; bh=ygI81p6SqewQoIn6tCgoZLUH2Qo5tPVgo3BNvwGSS3U=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIaXywNJ9MbLVZ4udDPN2ps4Pn9SSvGH2vsUaWfVlujOqd hx/UanRUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACbydRbD/9Tq5ZsP/5x+825W lvFh/z0C51+52kyxidQ9pZbMz1SrmcnwPyQ3hI/BZYrdas6alLLsTyGux3ZJ6PLsFVASevzi650 2LgA= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767586808273131704?= X-GMAIL-MSGID: =?utf-8?q?1767586808273131704?= The 32-bit decompressor does not actually use a global offset table (GOT), but as is common for 32-bit position independent code, it uses the magic symbol _GLOBAL_OFFSET_TABLE_ as an anchor from which to derive the actual runtime addresses of other symbols, using special @GOTOFF symbol references that are resolved at link time, and populated with the distance between the address of the magic _GLOBAL_OFFSET_TABLE_ anchor and the address of the symbol in question. This means _GLOBAL_OFFSET_TABLE_ is the only symbol whose actual runtime address needs to be determined explicitly, which is one of the first things that happens in startup_32. However, it does so by taking the absolute address via the immediate field of an ADD instruction (plus a small offset), which seems to defeat the point. Fortunately, the assembler knows that _GLOBAL_OFFSET_TABLE_ is magic, and emits a special relative relocation instead, and so the resulting code works as expected. However, this is not obvious for someone reading the code, and the use of LEA with an explicit relative addend is more idiomatic so use that instead. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_32.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index 8876ffe30e9a4819..3530465b5b85ccf3 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S @@ -58,7 +58,7 @@ SYM_FUNC_START(startup_32) leal (BP_scratch+4)(%esi), %esp call 1f 1: popl %edx - addl $_GLOBAL_OFFSET_TABLE_+(.-1b), %edx + leal (_GLOBAL_OFFSET_TABLE_ - 1b)(%edx), %edx /* Load new GDT */ leal gdt@GOTOFF(%edx), %eax