naccyde / rpms / iproute

Forked from rpms/iproute 8 months ago
Clone

Blame SOURCES/0063-bpf-initialise-map-symbol-before-retrieving-and-comp.patch

7e752c
From 9348ded117d05ba1d54a748173db009d473c707c Mon Sep 17 00:00:00 2001
7e752c
From: Andrea Claudi <aclaudi@redhat.com>
7e752c
Date: Thu, 13 Jun 2019 14:37:57 +0200
7e752c
Subject: [PATCH] bpf: initialise map symbol before retrieving and comparing
7e752c
 its type
7e752c
7e752c
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1716361
7e752c
Upstream Status: iproute2.git commit 1a7d3ad8a5862
7e752c
7e752c
commit 1a7d3ad8a5862ca9ce9dd19326faeea77e5e6142
7e752c
Author: Quentin Monnet <quentin.monnet@netronome.com>
7e752c
Date:   Tue Nov 20 01:26:27 2018 +0000
7e752c
7e752c
    bpf: initialise map symbol before retrieving and comparing its type
7e752c
7e752c
    In order to compare BPF map symbol type correctly in regard to the
7e752c
    latest LLVM, commit 7a04dd84a7f9 ("bpf: check map symbol type properly
7e752c
    with newer llvm compiler") compares map symbol type to both NOTYPE and
7e752c
    OBJECT. To do so, it first retrieves the type from "sym.st_info" and
7e752c
    stores it into a temporary variable.
7e752c
7e752c
    However, the type is collected from the symbol "sym" before this latter
7e752c
    symbol is actually updated. gelf_getsym() is called after that and
7e752c
    updates "sym", and when comparison with OBJECT or NOTYPE happens it is
7e752c
    done on the type of the symbol collected in the previous passage of the
7e752c
    loop (or on an uninitialised symbol on the first passage). This may
7e752c
    eventually break map collection from the ELF file.
7e752c
7e752c
    Fix this by assigning the type to the temporary variable only after the
7e752c
    call to gelf_getsym().
7e752c
7e752c
    Fixes: 7a04dd84a7f9 ("bpf: check map symbol type properly with newer llvm compiler")
7e752c
    Reported-by: Ron Philip <ron.philip@netronome.com>
7e752c
    Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
7e752c
    Reviewed-by: Jiong Wang <jiong.wang@netronome.com>
7e752c
    Acked-by: Yonghong Song <yhs@fb.com>
7e752c
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
7e752c
---
7e752c
 lib/bpf.c | 10 +++++++---
7e752c
 1 file changed, 7 insertions(+), 3 deletions(-)
7e752c
7e752c
diff --git a/lib/bpf.c b/lib/bpf.c
7e752c
index 45f279fa4a416..6aff8f7bad7fb 100644
7e752c
--- a/lib/bpf.c
7e752c
+++ b/lib/bpf.c
7e752c
@@ -1758,11 +1758,12 @@ static const char *bpf_map_fetch_name(struct bpf_elf_ctx *ctx, int which)
7e752c
 	int i;
7e752c
 
7e752c
 	for (i = 0; i < ctx->sym_num; i++) {
7e752c
-		int type = GELF_ST_TYPE(sym.st_info);
7e752c
+		int type;
7e752c
 
7e752c
 		if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym)
7e752c
 			continue;
7e752c
 
7e752c
+		type = GELF_ST_TYPE(sym.st_info);
7e752c
 		if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL ||
7e752c
 		    (type != STT_NOTYPE && type != STT_OBJECT) ||
7e752c
 		    sym.st_shndx != ctx->sec_maps ||
7e752c
@@ -1851,11 +1852,12 @@ static int bpf_map_num_sym(struct bpf_elf_ctx *ctx)
7e752c
 	GElf_Sym sym;
7e752c
 
7e752c
 	for (i = 0; i < ctx->sym_num; i++) {
7e752c
-		int type = GELF_ST_TYPE(sym.st_info);
7e752c
+		int type;
7e752c
 
7e752c
 		if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym)
7e752c
 			continue;
7e752c
 
7e752c
+		type = GELF_ST_TYPE(sym.st_info);
7e752c
 		if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL ||
7e752c
 		    (type != STT_NOTYPE && type != STT_OBJECT) ||
7e752c
 		    sym.st_shndx != ctx->sec_maps)
7e752c
@@ -1931,10 +1933,12 @@ static int bpf_map_verify_all_offs(struct bpf_elf_ctx *ctx, int end)
7e752c
 		 * the table again.
7e752c
 		 */
7e752c
 		for (i = 0; i < ctx->sym_num; i++) {
7e752c
-			int type = GELF_ST_TYPE(sym.st_info);
7e752c
+			int type;
7e752c
 
7e752c
 			if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym)
7e752c
 				continue;
7e752c
+
7e752c
+			type = GELF_ST_TYPE(sym.st_info);
7e752c
 			if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL ||
7e752c
 			    (type != STT_NOTYPE && type != STT_OBJECT) ||
7e752c
 			    sym.st_shndx != ctx->sec_maps)
7e752c
-- 
7e752c
2.20.1
7e752c