Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2828992pxv; Mon, 12 Jul 2021 02:59:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrhKFxgLRVmij47NUIZLHkzzv/7InsVoByRA6fNOxGPwUfakA+gQr0MrZi0yeq5NAyKsKC X-Received: by 2002:a92:c60c:: with SMTP id p12mr18955396ilm.7.1626083943706; Mon, 12 Jul 2021 02:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626083943; cv=none; d=google.com; s=arc-20160816; b=mPF7Lbvq+Wd1io8qD1tYVw1gujymoxiqEGx34RD3TVRSC4A7VrtOV2YeDoQYR+5/Am UO66uh4xaf2VFQgIGyFL3iIOB+lk//P52fYYPNq/v5dD7WXpr2xYOC8HFQafm8NHtrYs xmSD6xgTILm1oD1CpCrejuh4Qx509Tyvdx/K333WI1uQU5r8yRR3/IrMjqsR10/qalsC wVYrouIci5LcnJHLln4t1EfrMupD5a3dFnxKg6+l7bAXEaRQ1uS4gJKBv+XW4A0AnXLu alrImQC5taYYt92LHskWfYT++wLOoER26JKAYfnvtK0cES/eiWGLI18+lgvjMtbuNpqV dEVw== 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=awo4BaVKhXxOAe4+eczWL7vKrL3h3lR1+6hx/ISLGDs=; b=AGtuIR4jpxFweYm0t4o06fOxl+F8/ta6zfr2LSv80gFkkXuNI/Zw9kK7F5gI/cGkYa dtRDpUCQB0S+EalI4vI6+TFNqZVRyc4bFpMGVfSowB5+OIJmHy50bdBhDXh2oLuflzbc DI3rhxtz6OkxoFCNFf2Y8b1SffhvK6iJBDOQ1VCqR9W68aCMfSyblcePOtnVBJhJV6JQ N/u3P+ADOpdqe//NnlzH/5sQmjiFHARd/fSeA58RztrD+GYXPpjUTxZRKSqElfXcLaSa c2J2ClbW8/r6QCztTVrC20ULcEeMphsAyFNWxmspC8iwG5O9GWidjpFfHo/vFfnOZRhz 582Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vfEbmyZ6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k25si7661260jan.106.2021.07.12.02.58.51; Mon, 12 Jul 2021 02:59:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vfEbmyZ6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S239390AbhGLHDP (ORCPT + 99 others); Mon, 12 Jul 2021 03:03:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:41908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237353AbhGLGqK (ORCPT ); Mon, 12 Jul 2021 02:46:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F021A6052B; Mon, 12 Jul 2021 06:42:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072123; bh=ZdHYDiM4CBsddFR3O9SZ3RVMggxlOK7IXi8dyjDYJe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vfEbmyZ6cW1b6UMfI/xZBaH56qB5zhaIH9T+2XW5/dbMyxfaJzipc4HbogNo2FKND xEdlBup4txJ0QJtQCIYizqaNwScGAFz197WrxVGo328BCMPjsKjf+88kvM1Posp+xo rH/T2mGrEB7qm5xh+a+Kk+WQuIAtTx4BrA5HdfCU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tony Ambardar , Daniel Borkmann , Jiri Olsa , Frank Eigler , Mark Wielaard , Jiri Olsa , Yonghong Song , Sasha Levin Subject: [PATCH 5.10 364/593] bpf: Fix libelf endian handling in resolv_btfids Date: Mon, 12 Jul 2021 08:08:44 +0200 Message-Id: <20210712060926.573059514@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tony Ambardar [ Upstream commit 61e8aeda9398925f8c6fc290585bdd9727d154c4 ] The vmlinux ".BTF_ids" ELF section is declared in btf_ids.h to hold a list of zero-filled BTF IDs, which is then patched at link-time with correct values by resolv_btfids. The section is flagged as "allocable" to preclude compression, but notably the section contents (BTF IDs) are untyped. When patching the BTF IDs, resolve_btfids writes in host-native endianness and relies on libelf for any required translation on reading and updating vmlinux. However, since the type of the .BTF_ids section content defaults to ELF_T_BYTE (i.e. unsigned char), no translation occurs. This results in incorrect patched values when cross-compiling to non-native endianness, and can manifest as kernel Oops and test failures which are difficult to troubleshoot [1]. Explicitly set the type of patched data to ELF_T_WORD, the architecture- neutral ELF type corresponding to the u32 BTF IDs. This enables libelf to transparently perform any needed endian conversions. Fixes: fbbb68de80a4 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object") Signed-off-by: Tony Ambardar Signed-off-by: Daniel Borkmann Acked-by: Jiri Olsa Cc: Frank Eigler Cc: Mark Wielaard Cc: Jiri Olsa Cc: Yonghong Song Link: https://lore.kernel.org/bpf/CAPGftE_eY-Zdi3wBcgDfkz_iOr1KF10n=9mJHm1_a_PykcsoeA@mail.gmail.com [1] Link: https://lore.kernel.org/bpf/20210618061404.818569-1-Tony.Ambardar@gmail.com Signed-off-by: Sasha Levin --- tools/bpf/resolve_btfids/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c index d636643ddd35..f32c059fbfb4 100644 --- a/tools/bpf/resolve_btfids/main.c +++ b/tools/bpf/resolve_btfids/main.c @@ -649,6 +649,9 @@ static int symbols_patch(struct object *obj) if (sets_patch(obj)) return -1; + /* Set type to ensure endian translation occurs. */ + obj->efile.idlist->d_type = ELF_T_WORD; + elf_flagdata(obj->efile.idlist, ELF_C_SET, ELF_F_DIRTY); err = elf_update(obj->efile.elf, ELF_C_WRITE); -- 2.30.2