From patchwork Mon Oct 24 11:28:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9651 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp534193wru; Mon, 24 Oct 2022 09:10:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7VMizm6KQorJ/PBvRGyAcHU+Je6fpJeVYnINarSaFKf95E8KY8mfD1hfQXY01KOm+1I4UU X-Received: by 2002:a17:902:e8c3:b0:177:f078:7871 with SMTP id v3-20020a170902e8c300b00177f0787871mr34447679plg.90.1666627844213; Mon, 24 Oct 2022 09:10:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666627844; cv=none; d=google.com; s=arc-20160816; b=PPkvEue86XXevEPdFlJ4SQYOHYhfXIdp236OxcodcINAD48sDVb01WhMAuMXsqd+2s ABxBh1ArzzxAnHrO2DQIi9IzyltjW3pz5V90EaMsXftn7yVB3CZXb/fHl/RmHkdTpmDD AFkJFqKg9XHU4o97bwWm9l+6d64JQJQPCqz4IQ+dWOE7QwXaCccgBQCiN2V1TkkeSV6L aMkHFTVSMVsCf8+PSjXSaPMrNiYMJcgAMBsL28LRVrkDirEISVMbUQmk20BZsnD6Xkf6 mSgAn1EVOCur459VOScNBBh7wBDViHRmGXmmcFKFBql+evEIAO6fN7/VrVhNO+KHCBHj CAQQ== 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=K4l43jaR0B92t29F2muHhccMNTRGpmNRFhKOby5lRRk=; b=aqvuY/aML8WEkFdrh4wQ5ksBVgQAr3i+Gh3GpgO5/iO1tuEqkTbtnvHcz0q6tD0267 UZ62gLP2m6hyI42aFf/4HN/X8H1Hufw5KY0DtKMaj19tcHvFlSFXAhAy+EIyw1wjIBcS WtZ18UI7iUrnjUgqXts0QGB4WMUeiWhtzYVp84xj0YYo5s7n9+ht2P0GaAD4O3fVrbzF js1uwSrQf8Flp9dal89IcHfjgr3CYKB4dVpQDQXIL6y4jyDcdQEzyZCc7oF8j8WKq6Gq GN8sueNd5L+s0pQdzjHpolz7T/R9NrweSGZ5lcVZz/MNOa1JRIypSMs0xThRwTCCmkgH ctig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eL3NQIod; 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 a8-20020a17090a854800b001fe4eebefe5si8565220pjw.135.2022.10.24.09.10.30; Mon, 24 Oct 2022 09:10:44 -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=eL3NQIod; 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 S231424AbiJXQIZ (ORCPT + 99 others); Mon, 24 Oct 2022 12:08:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233400AbiJXQEl (ORCPT ); Mon, 24 Oct 2022 12:04:41 -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 89BE325E8B; Mon, 24 Oct 2022 07:57:05 -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 DB583B81645; Mon, 24 Oct 2022 12:20:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35566C433D7; Mon, 24 Oct 2022 12:20:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614008; bh=CuwPXSO5nQD6+tQbPlDUkxV3DhhtWO58vcsfSI7QTA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eL3NQIodQmRch5yYYddPDcm9q0FuiuAiJuPZI1Fu416+6r6/qa8azaBHRpfEXnsVZ RtA86RjVaQDVCpr6b6EX6LleWeX2th/p1ZXotzmI8xQgtW23mhJeu67HFVjxj/CYHM 12pJAvS2dq+XdzBDQsapRCVMP8GU7H8w29GTWx8M= 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.10 098/390] objtool: Preserve special st_shndx indexes in elf_update_symbol Date: Mon, 24 Oct 2022 13:28:15 +0200 Message-Id: <20221024113026.825316947@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747585958669643785?= X-GMAIL-MSGID: =?utf-8?q?1747585958669643785?= 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 5aa3b4e76479..a2ea3931e01d 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -578,6 +578,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) { @@ -663,7 +668,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;