From: Daniel Borkmann Date: Mon, 6 Mar 2017 12:06:00 +0000 (+0100) Subject: bpf: test for valid type in bpf_get_work_dir X-Git-Tag: v4.11.0~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51361a9f1cfca81259c68515cb24fbaace03136a;p=thirdparty%2Fiproute2.git bpf: test for valid type in bpf_get_work_dir Jan-Erik reported an assertion in bpf_prog_to_subdir() failed where type was BPF_PROG_TYPE_UNSPEC, which is only used in bpf_init_env() to auto-mount and cache the bpf fs mount point. Therefore, make sure when bpf_init_env() is called multiple times (f.e. eBPF classifier with eBPF action attached) and bpf_mnt_cached is set already that the type is also valid. In bpf_init_env(), we're only interested in the mount point and not a type-specific subdir. Fixes: e42256699cac ("bpf: make tc's bpf loader generic and move into lib") Reported-by: Jan-Erik Rediger Signed-off-by: Daniel Borkmann --- diff --git a/lib/bpf.c b/lib/bpf.c index 211c3d185..04ee1ab9b 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -596,7 +596,7 @@ static const char *bpf_get_work_dir(enum bpf_prog_type type) if (bpf_mnt_cached) { const char *out = mnt; - if (out) { + if (out && type) { snprintf(bpf_tmp, sizeof(bpf_tmp), "%s%s/", out, bpf_prog_to_subdir(type)); out = bpf_tmp;