From 2b57ef87900716e72a0ddae9a7dbb49bec60fc56 Mon Sep 17 00:00:00 2001 From: Stanislav Fomichev Date: Wed, 24 Aug 2022 11:19:48 +0800 Subject: [PATCH] libbpf: Cap retries in sys_bpf_prog_load mainline inclusion from mainline-5.11-rc1 commit d6d418bd8f92aaa4c7c26d606188147c2ee0dae9 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d6d418bd8f92aaa4c7c26d606188147c2ee0dae9 ------------------------------------------------- I've seen a situation, where a process that's under pprof constantly generates SIGPROF which prevents program loading indefinitely. The right thing to do probably is to disable signals in the upper layers while loading, but it still would be nice to get some error from libbpf instead of an endless loop. Let's add some small retry limit to the program loading: try loading the program 5 (arbitrary) times and give up. v2: * 10 -> 5 retires (Andrii Nakryiko) Signed-off-by: Stanislav Fomichev Signed-off-by: Andrii Nakryiko Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20201202231332.3923644-1-sdf@google.com (cherry picked from commit d6d418bd8f92aaa4c7c26d606188147c2ee0dae9) Signed-off-by: Wang Yufen --- tools/lib/bpf/bpf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 13e08c0d8b1a..fa6dbd5aec3d 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -67,11 +67,12 @@ static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr, static inline int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size) { + int retries = 5; int fd; do { fd = sys_bpf(BPF_PROG_LOAD, attr, size); - } while (fd < 0 && errno == EAGAIN); + } while (fd < 0 && errno == EAGAIN && retries-- > 0); return fd; } -- GitLab