Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4696663imw; Tue, 12 Jul 2022 12:37:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1spfPRG4y7jpbZRJS3suFnUwcyGgP0SO20eNKws1WYgtoKluNG4aKKzPMepTmYaDC1GNnAN X-Received: by 2002:a17:90b:4acb:b0:1f0:62ab:2956 with SMTP id mh11-20020a17090b4acb00b001f062ab2956mr4925118pjb.178.1657654644774; Tue, 12 Jul 2022 12:37:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657654644; cv=none; d=google.com; s=arc-20160816; b=qzX1Z/1T2qXu+9x2KMbVg8plKHHqL02DJt0V91SBLpx1QSfolvYP+ZX5lTlpq3jQeU lzDO8hNd6kDSY34S1fwlmQ0Dq/QHmN+nVrJhQ4LUGrgojE+Phc0izjTWTSJb+NPvQv+f qkXZ6o45DUywJ8ACFRUs6Ifq4pYM3LkxTV7sZOrMJOUzEwS4dbWpg562twvAeq9bTAeg 9GgArVDSvdEOjvPFklyGdHABcXQMPZ2RX00RZALRw/WdoONPhZHiYZhVV/kIamrQqKRd kFlimLWJy15FToX00sH16nFHm861675sONZzXt3LP0Lo0GkYDBL01x4KDWUY6xwbzeGE Yhpw== 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=IBD/+eHhxnbltyqt+Qc6LA88pnFKJVfg7Nav6bykDlQ=; b=HBm/0urez1C/dVQzEWBJX7hQb/uIthlw+VKTXciMa7CdjX4VvO9fg4wE3XGhkPAd1p gxaEJH1bjMkYED9HU98NW7f75qGoedFTw/FVX16ZrnaPkBu5bObpYHw8higimMa/vRkp UgUtpXVXnL7Dqd+0zGCi97oQfLLZDm8MEJYDS/IcHGkKPa8hgsC7uMSakp6vHSkjj0ke NYL08yQFCwWA3xQZfXRapWJ+IYz1qdz9wmvCk1WbFGdWkWYjDLscj7wqNdg2HOl8Xh2t FMuWm4tzkCrpdg4JjPu9ZcxCYUZz/siS7Paub3tFggNGeKARtFBx5o76IBPRdAtlchIT R1mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t6C3Qk0p; 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 t15-20020a63224f000000b0041212cbf59dsi15136009pgm.201.2022.07.12.12.37.12; Tue, 12 Jul 2022 12:37:24 -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=t6C3Qk0p; 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 S234156AbiGLSoN (ORCPT + 99 others); Tue, 12 Jul 2022 14:44:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229954AbiGLSnF (ORCPT ); Tue, 12 Jul 2022 14:43:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEFE5D9179; Tue, 12 Jul 2022 11:41:56 -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 36199B81BBD; Tue, 12 Jul 2022 18:41:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 658BEC3411E; Tue, 12 Jul 2022 18:41:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651313; bh=OPAVYdq/Nb9TUWPRrzva7ewq9dIjGGbmoWDHPMaNNOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t6C3Qk0pNGV2O0OZQu5hBCQBqthr1kPfng/WddiN7WuTodvVF9OVC1IvH8HQhwdhM 4Fv/W2mCeZg8GFsiXRYLTYSv/QXxsLdzboY3rguZ6mFX+Utv2352dAp4hxdFCM06Sb WgcdoQ+Y4I26U9vkZ3rnYbRbAPhUFOxQFRQ0DKIo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nick Desaulniers , Fangrui Song , "Peter Zijlstra (Intel)" , Ben Hutchings Subject: [PATCH 5.10 037/130] objtool: Fix .symtab_shndx handling for elf_create_undef_symbol() Date: Tue, 12 Jul 2022 20:38:03 +0200 Message-Id: <20220712183248.114403669@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183246.394947160@linuxfoundation.org> References: <20220712183246.394947160@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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 From: Peter Zijlstra commit 584fd3b31889852d0d6f3dd1e3d8e9619b660d2c upstream. When an ELF object uses extended symbol section indexes (IOW it has a .symtab_shndx section), these must be kept in sync with the regular symbol table (.symtab). So for every new symbol we emit, make sure to also emit a .symtab_shndx value to keep the arrays of equal size. Note: since we're writing an UNDEF symbol, most GElf_Sym fields will be 0 and we can repurpose one (st_size) to host the 0 for the xshndx value. Fixes: 2f2f7e47f052 ("objtool: Add elf_create_undef_symbol()") Reported-by: Nick Desaulniers Suggested-by: Fangrui Song Signed-off-by: Peter Zijlstra (Intel) Tested-by: Nick Desaulniers Link: https://lkml.kernel.org/r/YL3q1qFO9QIRL/BA@hirez.programming.kicks-ass.net Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- tools/objtool/elf.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -768,7 +768,7 @@ static int elf_add_string(struct elf *el struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name) { - struct section *symtab; + struct section *symtab, *symtab_shndx; struct symbol *sym; Elf_Data *data; Elf_Scn *s; @@ -819,6 +819,29 @@ struct symbol *elf_create_undef_symbol(s symtab->len += data->d_size; symtab->changed = true; + symtab_shndx = find_section_by_name(elf, ".symtab_shndx"); + if (symtab_shndx) { + s = elf_getscn(elf->elf, symtab_shndx->idx); + if (!s) { + WARN_ELF("elf_getscn"); + return NULL; + } + + data = elf_newdata(s); + if (!data) { + WARN_ELF("elf_newdata"); + return NULL; + } + + data->d_buf = &sym->sym.st_size; /* conveniently 0 */ + data->d_size = sizeof(Elf32_Word); + data->d_align = 4; + data->d_type = ELF_T_WORD; + + symtab_shndx->len += 4; + symtab_shndx->changed = true; + } + sym->sec = find_section_by_index(elf, 0); elf_add_symbol(elf, sym);