From patchwork Wed Oct 19 08:25:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp250006wrs; Wed, 19 Oct 2022 03:47:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4kquvIgIF8SKP5jIYgIAcoziDk0idge2Q4Y7L2c7O8amQnEVGtcmjoFcxJ0/LfUIiCL1N6 X-Received: by 2002:a17:907:7da6:b0:791:997e:58fc with SMTP id oz38-20020a1709077da600b00791997e58fcmr6353977ejc.385.1666176470495; Wed, 19 Oct 2022 03:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666176470; cv=none; d=google.com; s=arc-20160816; b=yd/8xNh0F/O0FOMXtaliV/kzDUHIqVh231LF/DnIDbvtvS6gqMc7ixEqwzCgc7U4Il 0jTuoV5vxz1Q0NrWzCvWOMbXSL4BsjLrtOIZ7gEQU1KgYJpLUsu57Y6k6+Xb04/rMMfB HGFF6XeHdudiULsWByI4AQmvfgBc0VOySWZ7CCW+Dxs9aB5PcOlDiY8XGj1xKiJmEmUn GfWowaL09reCRO3ZhFPCXAu/Lf5C3vI/7gkfawzg7ydhfZszfqo++BVs+5jxk4R+Ma0K qzTuL92TkeB0drZyLxIdB9nP8rKE/HEr4Ys1DQoEFDiR5dN/lNu8AA7/7dtf5XRBMyk8 23+w== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf26-20020a0564021a5a00b0045c83fb19d4si12960257edb.578.2022.10.19.03.47.25; Wed, 19 Oct 2022 03:47:50 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747112658663671012?= X-GMAIL-MSGID: =?utf-8?q?1747112658663671012?= 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;