From patchwork Sat Oct 22 07:21:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7230 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1090653wrr; Sat, 22 Oct 2022 00:47:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5kktyqDmmujLuzV6MeSQtHkVUOTkGRjDijgl3MXfz0zWPaQSGauA32gU1YkRIKroG+eT3V X-Received: by 2002:a17:903:2450:b0:185:4165:be54 with SMTP id l16-20020a170903245000b001854165be54mr23280801pls.104.1666424877716; Sat, 22 Oct 2022 00:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424877; cv=none; d=google.com; s=arc-20160816; b=dZeiO4aCQybwWk//nXRatbEZgJVOtr9Fuk3Kj0l13nabE/1BDYbQB5Of3nqzFzZwQn XNVXFc/pScIrwJS/2ZUu7OjaG+8wA0cv80Aml3np7IvfTw+zJVMofyHbccpMC7Qjo4CM B+EEzJP9j/Go80k0nGUaOWGFF24wybXaixaaju/PSbTRC7FawbhGm60+QB0E0mhk2Y59 BxRLSduCjHMWmXS4QTvxqJYlbi6kwWJ9PQCEzg6VXk9tyM1wcEllomxAT9EGkXRyD3tn fI9jAHob7/WkOVSLQ1TBX2cxgw5E5AACTqnNw7CeOs1s6YIkl5KVtNszlsVcIGvNDH9q 9qBw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=t05utgu4jM38zfag2flAiy1ZS5Rw35Cv58UVMurbTvw=; b=clhLNwBoOFTzoDvFOSbQ6IPIdjlrqatjJON9kFZbr7rDVp92eH/tm3Hf7FKlEbBdr+ QX/14iL7YsS0DSy2unQ0RCYTy6f2ey4t0xaZNa6Tnhb8dIo2DxJHCVx35eTOOg0ZcKVP T5mbEJaz9X177f28F3l1KiZNjmJO6KYzbf5F0syMU5SQZGCsrRSgnK0NvQEL6PSMQAfS FGhlnEn2zsr5tZYqCAEoWVzgZWJ2GxGPESSwj+46r65WzKgsRzqqaRD3OmZh4vywyMTZ PyN3lX5B5aUTrUDS+uQ4cA3qkiumBIqTzV2c94mBlrO9bmie2jsv3zC97s1msMp9uHuS FPDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TdIms5Me; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020a170903018700b001781c0dda3fsi30001210plg.12.2022.10.22.00.47.44; Sat, 22 Oct 2022 00:47:57 -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=@linuxfoundation.org header.s=korg header.b=TdIms5Me; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231546AbiJVHrJ (ORCPT + 99 others); Sat, 22 Oct 2022 03:47:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231709AbiJVHpL (ORCPT ); Sat, 22 Oct 2022 03:45:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8A4F8A6C2; Sat, 22 Oct 2022 00:43:40 -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 ams.source.kernel.org (Postfix) with ESMTPS id B10BCB82E0A; Sat, 22 Oct 2022 07:42:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED59EC433C1; Sat, 22 Oct 2022 07:42:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424568; bh=HFFF37R3oYOiJnZ/OBH3lRHLRux8zKszRban/GNbQAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TdIms5Mevot0585sU584EM2QOaYn77TSCuLN7biW+lmKBBFJKm1BIOKSzAoz1unT1 O+HoYgOH/jifcZtIecPZCcE9yUHuUo1aUheLrYiHKXuoa2EqxVxjEimPEKF/rVO8xy ykma1EtRBT60aKrWdHlLY/qCCcILEonJ72KLm/iI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sami Tolvanen , "Peter Zijlstra (Intel)" , Kees Cook , Sasha Levin Subject: [PATCH 5.19 193/717] objtool: Preserve special st_shndx indexes in elf_update_symbol Date: Sat, 22 Oct 2022 09:21:12 +0200 Message-Id: <20221022072449.694892946@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 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 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?1747373132796236038?= X-GMAIL-MSGID: =?utf-8?q?1747373132796236038?= From: Sami Tolvanen [ Upstream commit 5141d3a06b2da1731ac82091298b766a1f95d3d8 ] elf_update_symbol fails to preserve the special st_shndx values between [SHN_LORESERVE, SHN_HIRESERVE], which results in it converting SHN_ABS entries into SHN_UNDEF, for example. Explicitly check for the special indexes and ensure these symbols are not marked undefined. Fixes: ead165fa1042 ("objtool: Fix symbol creation") Signed-off-by: Sami Tolvanen Acked-by: Peter Zijlstra (Intel) Tested-by: Peter Zijlstra (Intel) Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20220908215504.3686827-17-samitolvanen@google.com Signed-off-by: Sasha Levin --- tools/objtool/elf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index c25e957c1e52..7e24b09b1163 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -619,6 +619,11 @@ static int elf_update_symbol(struct elf *elf, struct section *symtab, Elf64_Xword entsize = symtab->sh.sh_entsize; int max_idx, idx = sym->idx; Elf_Scn *s, *t = NULL; + bool is_special_shndx = sym->sym.st_shndx >= SHN_LORESERVE && + sym->sym.st_shndx != SHN_XINDEX; + + if (is_special_shndx) + shndx = sym->sym.st_shndx; s = elf_getscn(elf->elf, symtab->idx); if (!s) { @@ -704,7 +709,7 @@ static int elf_update_symbol(struct elf *elf, struct section *symtab, } /* setup extended section index magic and write the symbol */ - if (shndx >= SHN_UNDEF && shndx < SHN_LORESERVE) { + if ((shndx >= SHN_UNDEF && shndx < SHN_LORESERVE) || is_special_shndx) { sym->sym.st_shndx = shndx; if (!shndx_data) shndx = 0;