Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp885721rwi; Wed, 19 Oct 2022 04:18:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Fe4SMiRjt5iKcYYFjyiL3TYF4qAcbEYoW3lH0YVuOz3xO30eYvYtmb8ToIiu2q1ad/WHQ X-Received: by 2002:a17:907:724d:b0:78d:acf4:4c57 with SMTP id ds13-20020a170907724d00b0078dacf44c57mr6250303ejc.516.1666178336601; Wed, 19 Oct 2022 04:18:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666178336; cv=none; d=google.com; s=arc-20160816; b=Kt4/aJ+RbdcMzOsWJm7h+xQGe6DCR6KXpswlRIIXrvgnSt4eSXJPQ26rVEig9EoDDa nVPCBhc+vvtk5g4u3RhF6JcGCWIHfarUXDqYEjWPIkNGKgUO1zFCDLAIYNevCIELNsfS 2lTyL+pHK46wkdNtejc6savaPECJUkQPmQPfKV4SLr3P1GHE0bGCMac9P/reMJaddz15 +hCCpJ1uWOUbq+w2h2guahPp/oC2QNFCq1kASWCDzZsBSOT+PqYeG+5xYsooku3F/IA1 MVUKqx8FEHYqEN2vEJuNTn/okaKv9f5tHmdluopdtNaD6cdqNkmBbUEAx06NcpvlIpp4 mrTQ== 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=pEFD99VJmPKC5MNTTyN3bXS0Gzh0g8cjnX+d0n8qdRAmhUo5YzjmlIyrsvmS4SlmjU 8gCGmGoJS3MvV3SDXeuQrBRtacTSB28eOPUzK/FEvjilwwL0ngRguh0Qkp5Vyp91/Tta qaFyEip+JtKjDxevbpPLhtE9rV6N+2gVvzUStqKdhYTlZVlR6fBnTC98q3KceyCpOE3Y O5NX9pCY/z1ZkuVoXSGDHPba/NAlZdGopFR71zDZMn/umN4SKwkQNcg+mroVu+ZsqGqc 4VoczMTw8mlXqa1aRyQXNNFqEDvPQHGTchKIOfdaHhfHI+cWObDLnlWTxsw+1lSmwbZl 78Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JCPo4k60; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j9-20020a05640211c900b0045db850a506si6259675edw.46.2022.10.19.04.18.30; Wed, 19 Oct 2022 04:18:56 -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=JCPo4k60; 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 S232789AbiJSKrF (ORCPT + 99 others); Wed, 19 Oct 2022 06:47:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232062AbiJSKor (ORCPT ); Wed, 19 Oct 2022 06:44:47 -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 5908311877D; Wed, 19 Oct 2022 03:21:16 -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 D853AB8231D; Wed, 19 Oct 2022 08:48:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DE6CC433D6; Wed, 19 Oct 2022 08:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169286; bh=HFFF37R3oYOiJnZ/OBH3lRHLRux8zKszRban/GNbQAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JCPo4k60POx/tyzu3+Rv3Nu0yk/lr8pbD6ewan6Dd+88Z8hALC1LuBMCvkD40e1xk 79Rmh49pVJfaaetVIKPLzubBmC/l83RsXFG46/p/dI0/Mei408k6uVqLMBmZnSD7Ea LjeSoSURGtTq1ApiA75Wv927BWwGqaU9vyp5yKts= 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 6.0 220/862] objtool: Preserve special st_shndx indexes in elf_update_symbol Date: Wed, 19 Oct 2022 10:25:07 +0200 Message-Id: <20221019083259.753894368@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 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 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; -- 2.35.1