Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp12517687rwd; Fri, 23 Jun 2023 07:12:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5MaYXI4DQWSFy3JGcFzGVZTdg2tkYMLSsmBEiKLD+InAhlDzey4CSqn6dQoTkx1FY1FyDP X-Received: by 2002:a17:902:ab0c:b0:1b5:28a7:d703 with SMTP id ik12-20020a170902ab0c00b001b528a7d703mr20010506plb.41.1687529563926; Fri, 23 Jun 2023 07:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687529563; cv=none; d=google.com; s=arc-20160816; b=LYj7F0emPSYvOAStonB2zkLsRficCw4riJ7FJBLHsjFWDlM2zO8O6/rCvZwtf+GzHt e8nvoRtaCl0wSoRyjfns9oLmVFSyZH0/LA7m7y3kYT1sNWtgVx97vSEmMmkHB8RXwWSW pB71QQgPDPR2wBJQmTE7YAL7SU/t7L7EDOzJCxAUjoXXMMuBt3gGCW6GZYpcQulT6Z+H 7tphz78wKuDX6u33KQ/PdyALBu5cRPfzEvcHESaOwJmKMZcHOV90WqqkLCIpcxqyg9rM SDAdfCq6/XXOtBGUT1KN4e9rSrt1/l54/STErT2mVWyfDXcpl6jmJ/uYH1iaTeuCPuDL hgcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=cV5eV4K2lP3JdocpoyhdRSV7+8Zq44rHPd1l2tSEicI=; b=X3laUo4kmr81r5nMCXYeaNBLU1JmDqDrgDxW8s5f+d8MncTxzkVc6KzAFSGRg9cuor JJGt7bl4vGT6DB5AbvjfXtCxvKpejX/dr4hodSUvBMtoQ3yuAw62GZYTimwEBGfqJS// HKcyqgjdVF2ozM5jQ4nY6dJrLlPETtarMo5EBWFksqsqI6MS/XbkpEGBojRDx2Sc/9cH iFpncQUd35U0yphISIgJTcRmnJXKKL/+/fnXuLN4hSSd7pBwUbUuibcd0VEIGLuRzXqk dOoEEjvGlCE2ihyRQeVhSoW7i3I+aELlLrKBHFItaW/qmVmbS02GltqVAIeQ9U1G95pH Mm6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qAUdPn1V; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jx14-20020a170903138e00b001b3d5f01c28si8445915plb.252.2023.06.23.07.12.27; Fri, 23 Jun 2023 07:12:43 -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=qAUdPn1V; 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 S231168AbjFWOAr (ORCPT + 99 others); Fri, 23 Jun 2023 10:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjFWOAp (ORCPT ); Fri, 23 Jun 2023 10:00:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4246B189; Fri, 23 Jun 2023 07:00:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C4F1361A5C; Fri, 23 Jun 2023 14:00:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C5B3C433D9; Fri, 23 Jun 2023 14:00:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687528843; bh=sU0qvZS8lc5okVj+Wd/3PIl9/7CnriyY1ONPXUzclvg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=qAUdPn1VK3h4MfZkOBRgysXOcXGCCSnnEy2vUx5VsQVwb1UckT9ak0Ygke6HrEn3+ aU99bG0JVQK4y7kZKHVuFq9wr9JPteuA534X9JYs7AKyfIrQHVrFDIKuiGDFQaBXq4 DjWl1IBJQ6PcSVEcu9rwHraNB7q8OT1WaMFdc1TdfXY15kPuHyHV/kFVnxiZbp1YX0 y0HX+AkzNJ7f+nRB7QxRldiOzTExk4j0OyXH3w07vlaNIUy+dpJvJ3VnV1DPBPtTFS FAdywzkkADKTTKvRijh6I5N1ndVe5wHkTBVZdJpse6XqpIsr58HYpb4KhtjBovvrpf O+iy4EDLOxMWg== Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-4f87592eccfso811033e87.2; Fri, 23 Jun 2023 07:00:42 -0700 (PDT) X-Gm-Message-State: AC+VfDytDiIB6TxMg0ZCMwXk6mYL28nt0C+YTowjVfaIB1osqWSe8E5g xoAHiJGUYbLrNehPnRJBEfp/CGAiA0gZL893ITE= X-Received: by 2002:a05:6512:3c88:b0:4f9:6a7b:b8de with SMTP id h8-20020a0565123c8800b004f96a7bb8demr3628980lfv.3.1687528841114; Fri, 23 Jun 2023 07:00:41 -0700 (PDT) MIME-Version: 1.0 References: <20230607072342.4054036-1-ardb@kernel.org> <20230607072342.4054036-6-ardb@kernel.org> <20230621110852.GAZJLaRAuGBCc5R4yb@fat_crate.local> In-Reply-To: <20230621110852.GAZJLaRAuGBCc5R4yb@fat_crate.local> From: Ard Biesheuvel Date: Fri, 23 Jun 2023 16:00:30 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 05/20] x86/decompressor: Use proper sequence to take the address of the GOT To: Borislav Petkov Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Evgeniy Baskov , 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 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 On Wed, 21 Jun 2023 at 13:09, Borislav Petkov wrote: > > On Wed, Jun 07, 2023 at 09:23:27AM +0200, Ard Biesheuvel wrote: > > 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 > > Which special relocation do you mean? > > This guy: > > Relocation section '.rel.head.text' at offset 0x3a0 contains 12 entries: > Offset Info Type Sym.Value Sym. Name > 00000010 00000d0a R_386_GOTPC 00000000 _GLOBAL_OFFSET_TABLE_ > > ? Yep. if you assemble this movl $_GLOBAL_OFFSET_TABLE_, %eax movl $_GLOBAL_OFFSET_TABLE, %eax you'll end up with 0: b8 01 00 00 00 mov $0x1,%eax 1: R_386_GOTPC _GLOBAL_OFFSET_TABLE_ 5: b8 00 00 00 00 mov $0x0,%eax 6: R_386_32 _GLOBAL_OFFSET_TABLE So it is not possible to take the absolute address of _GLOBAL_OFFSET_TABLE_ via an absolute relocation, you will always get the relative offset instead.