From: Alex Gartrell Date: Wed, 26 Aug 2020 07:55:49 +0000 (-0700) Subject: libbpf: Fix unintentional success return code in bpf_object__load X-Git-Tag: v5.8.17~454 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b87f9ce106ed934e10e1e811304d49764790e08;p=thirdparty%2Fkernel%2Fstable.git libbpf: Fix unintentional success return code in bpf_object__load [ Upstream commit ef05afa66c59c2031a3798916ef3ff3778232129 ] There are code paths where EINVAL is returned directly without setting errno. In that case, errno could be 0, which would mask the failure. For example, if a careless programmer set log_level to 10000 out of laziness, they would have to spend a long time trying to figure out why. Fixes: 4f33ddb4e3e2 ("libbpf: Propagate EPERM to caller on program load") Signed-off-by: Alex Gartrell Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/20200826075549.1858580-1-alexgartrell@gmail.com Signed-off-by: Sasha Levin --- diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 236c91aff48f8..e4d304247c1ba 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -5253,7 +5253,7 @@ retry_load: free(log_buf); goto retry_load; } - ret = -errno; + ret = errno ? -errno : -LIBBPF_ERRNO__LOAD; cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg)); pr_warn("load bpf program failed: %s\n", cp); pr_perm_msg(ret);