Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp619826ybl; Fri, 24 Jan 2020 06:33:56 -0800 (PST) X-Google-Smtp-Source: APXvYqxJYIj+/FlvfTr7VcpdLyWIVqF60XdCQc3+AJDeni8odpf5HzMTwDfkxt6Nrqke/Vzl11Uv X-Received: by 2002:a05:6830:1607:: with SMTP id g7mr2896934otr.320.1579876436677; Fri, 24 Jan 2020 06:33:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579876436; cv=none; d=google.com; s=arc-20160816; b=NIV9eLlFARBlTLFXRcS62r6RbPLwp2uts6iTu4qobr7gDK4bHHaIz6JK9vDBcA9nmw Q0teKWrYuoXdiZqXDtsJLIfkRXlin4p2NXQ7BcAFHh18pV7rSKhb4bCRbroj7lvSIbgu 7jr5q+zNfZTWVe/QRZp6h8r/X/vb64dED7Tg0uOv8Fg8MAHwULOQZ21BjEfFmTkuoN9a YfIw+KxUiqM/Nh2Qc2Ac7vQIYwqZCnUB1gFn53LIgVIHVwcRT2ab7Y3oYErS51RQnSCI 6K50BQxVJMMy5ZCxLBllSrnGc7IT0HPvWc1+cHL/bKJe6lFxshyID5+xbGBnJQq2gw1D xHPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cZmUSA9o6kWIo9jAixye4KhPEORnFp9CXPRJA9UBjEU=; b=qNfLDK+3VZKhlRQ9sQ0fLXvyoA9BGUmlT+serkJr8xf9es1SItpksju+0INpO25gXE zmVONGgXlmh2gdGRwwd791F5NVSbtsfRRy/X6VtlhNF9fJ3fiFFVGlSxSuDVRRvb7tSX 7MKzaDoE9wAZHU/bjlR3AFT42f/DxCFXqXq/COgJA7nMNnwNYeL+kjjcP4xKjwtJe8M7 OuHu3hMIlepwn4jN8yAzWkSKhjbao1+ZBi5Gs90+Ll7SQL03K7n2jzUpKJBH4EcPjOpO fbH1sfR+EyfwQWaxS3vr39kK/+42Ds0T7Z8jq2xFpmxwL3bYtQ1TTr5vno/HnI9ZHKPV C6gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iKuhRvDd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e26si2975041otj.113.2020.01.24.06.33.44; Fri, 24 Jan 2020 06:33:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iKuhRvDd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404981AbgAXLhE (ORCPT + 99 others); Fri, 24 Jan 2020 06:37:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:57180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388743AbgAXLhA (ORCPT ); Fri, 24 Jan 2020 06:37:00 -0500 Received: from localhost (ip-213-127-102-57.ip.prioritytelecom.net [213.127.102.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 58F3D206D4; Fri, 24 Jan 2020 11:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579865819; bh=aQyNDUQ3C6+QBGz+8iD6Fpox3yVMod9VJAD6N27FgzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iKuhRvDdaEnY3uyjab8I2fpXUdfVmS7X3vAe6rrddf4QQ5Oi8Szn1GguzfAZliq7W nPU17UzSoPZmEP/uD4vek7JKIrpCq/S/WnuUHjW5Xr9oLfgGIo2+rPU2aT3Z8UFhBk IfFWHYc4BtEyDC7TZZxJwHe3JuSI75zJWqNhk4vA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jesper Dangaard Brouer , Alexei Starovoitov , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Andrii Nakryiko , Sasha Levin Subject: [PATCH 4.19 634/639] samples/bpf: Fix broken xdp_rxq_info due to map order assumptions Date: Fri, 24 Jan 2020 10:33:24 +0100 Message-Id: <20200124093209.035359872@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124093047.008739095@linuxfoundation.org> References: <20200124093047.008739095@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jesper Dangaard Brouer [ Upstream commit edbca120a8cdfa5a5793707e33497aa5185875ca ] In the days of using bpf_load.c the order in which the 'maps' sections were defines in BPF side (*_kern.c) file, were used by userspace side to identify the map via using the map order as an index. In effect the order-index is created based on the order the maps sections are stored in the ELF-object file, by the LLVM compiler. This have also carried over in libbpf via API bpf_map__next(NULL, obj) to extract maps in the order libbpf parsed the ELF-object file. When BTF based maps were introduced a new section type ".maps" were created. I found that the LLVM compiler doesn't create the ".maps" sections in the order they are defined in the C-file. The order in the ELF file is based on the order the map pointer is referenced in the code. This combination of changes lead to xdp_rxq_info mixing up the map file-descriptors in userspace, resulting in very broken behaviour, but without warning the user. This patch fix issue by instead using bpf_object__find_map_by_name() to find maps via their names. (Note, this is the ELF name, which can be longer than the name the kernel retains). Fixes: be5bca44aa6b ("samples: bpf: convert some XDP samples from bpf_load to libbpf") Fixes: 451d1dc886b5 ("samples: bpf: update map definition to new syntax BTF-defined map") Signed-off-by: Jesper Dangaard Brouer Signed-off-by: Alexei Starovoitov Acked-by: Toke Høiland-Jørgensen Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/157529025128.29832.5953245340679936909.stgit@firesoul Signed-off-by: Sasha Levin --- samples/bpf/xdp_rxq_info_user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/bpf/xdp_rxq_info_user.c b/samples/bpf/xdp_rxq_info_user.c index ef26f882f92f4..a55c81301c1a9 100644 --- a/samples/bpf/xdp_rxq_info_user.c +++ b/samples/bpf/xdp_rxq_info_user.c @@ -472,9 +472,9 @@ int main(int argc, char **argv) if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) return EXIT_FAIL; - map = bpf_map__next(NULL, obj); - stats_global_map = bpf_map__next(map, obj); - rx_queue_index_map = bpf_map__next(stats_global_map, obj); + map = bpf_object__find_map_by_name(obj, "config_map"); + stats_global_map = bpf_object__find_map_by_name(obj, "stats_global_map"); + rx_queue_index_map = bpf_object__find_map_by_name(obj, "rx_queue_index_map"); if (!map || !stats_global_map || !rx_queue_index_map) { printf("finding a map in obj file failed\n"); return EXIT_FAIL; -- 2.20.1