From nobody Fri Dec 19 18:43:44 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15BDEC433FE for ; Sat, 22 Oct 2022 07:47:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231196AbiJVHrK (ORCPT ); Sat, 22 Oct 2022 03:47:10 -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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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@goog= le.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 s= ection *symtab, Elf64_Xword entsize =3D symtab->sh.sh_entsize; int max_idx, idx =3D sym->idx; Elf_Scn *s, *t =3D NULL; + bool is_special_shndx =3D sym->sym.st_shndx >=3D SHN_LORESERVE && + sym->sym.st_shndx !=3D SHN_XINDEX; + + if (is_special_shndx) + shndx =3D sym->sym.st_shndx; =20 s =3D elf_getscn(elf->elf, symtab->idx); if (!s) { @@ -704,7 +709,7 @@ static int elf_update_symbol(struct elf *elf, struct se= ction *symtab, } =20 /* setup extended section index magic and write the symbol */ - if (shndx >=3D SHN_UNDEF && shndx < SHN_LORESERVE) { + if ((shndx >=3D SHN_UNDEF && shndx < SHN_LORESERVE) || is_special_shndx) { sym->sym.st_shndx =3D shndx; if (!shndx_data) shndx =3D 0; --=20 2.35.1