linma / rpms / iproute

Forked from rpms/iproute 4 years ago
Clone

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

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