Skip to contentSkip to conversation

bpf: fix return in load_bpf_file

PATCH Superseded Lawrence Brakmo 2 participants 3 messages Jul 4, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: fix return in load_bpf_file

The function load_bpf_file ignores the return value of load_and_attach(), so even if load_and_attach() returns an error, load_bpf_file() will return 0.

Now, load_bpf_file() can call load_and_attach() multiple times and some can succeed and some could fail. I think the correct behavor is to return error on the first failed load_and_attach().

---
 samples/bpf/bpf_load.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
samples/bpf/bpf_load.c +6 -2
index a4be7cf..899f403 100644
@@ -567,8 +567,12 @@ static int do_load_bpf_file(const char *path, fixup_map_cb fixup_map)
 		    memcmp(shname, "perf_event", 10) == 0 ||
 		    memcmp(shname, "socket", 6) == 0 ||
 		    memcmp(shname, "cgroup/", 7) == 0 ||
-		    memcmp(shname, "sockops", 7) == 0)
-			load_and_attach(shname, data->d_buf, data->d_size);
+		    memcmp(shname, "sockops", 7) == 0) {
+			ret = load_and_attach(shname, data->d_buf,
+					      data->d_size);
+			if (ret != 0)
+				goto done;
+		}
 	}
 
 	ret = 0;
Signature · 1 line
2.9.3
maintainer
#1 lore raw
Quoted 7 lines · Lawrence Brakmo

The function load_bpf_file ignores the return value of load_and_attach(), so even if load_and_attach() returns an error, load_bpf_file() will return 0.

Now, load_bpf_file() can call load_and_attach() multiple times and some can succeed and some could fail. I think the correct behavor is to return error on the first failed load_and_attach().

Your SOB is missing.

#2 lore raw

On 7/4/17, 3:14 PM, "Daniel Borkmann" <[email protected]> wrote:

On 07/04/2017 11:51 PM, Lawrence Brakmo wrote:
> The function load_bpf_file ignores the return value of
> load_and_attach(), so even if load_and_attach() returns an error, > load_bpf_file() will return 0.
>
> Now, load_bpf_file() can call load_and_attach() multiple times and some > can succeed and some could fail. I think the correct behavor is to > return error on the first failed load_and_attach().

Your SOB is missing.

Oops, thanks. New patch forthcoming.