From d7cb6182e9fe50d539a661eb31480215aef7a26d Mon Sep 17 00:00:00 2001 From: Prashant Bhole Date: Tue, 19 Feb 2019 22:15:13 +0800 Subject: [PATCH] bpf: error handling when map_lookup_elem isn't supported mainline inclusion from mainline-4.20 commit 509db2833e0d category: bugfix bugzilla: 9355 CVE: NA ------------------------------------------------- The error value returned by map_lookup_elem doesn't differentiate whether lookup was failed because of invalid key or lookup is not supported. Lets add handling for -EOPNOTSUPP return value of map_lookup_elem() method of map, with expectation from map's implementation that it should return -EOPNOTSUPP if lookup is not supported. The errno for bpf syscall for BPF_MAP_LOOKUP_ELEM command will be set to EOPNOTSUPP if map lookup is not supported. Signed-off-by: Prashant Bhole Acked-by: Alexei Starovoitov Acked-by: Song Liu Signed-off-by: Alexei Starovoitov Signed-off-by: Cheng Jian Reviewed-by: Hanjun Guo Signed-off-by: Yang Yingliang --- kernel/bpf/syscall.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 31af04277aa6..4f32e713e673 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -717,10 +717,15 @@ static int map_lookup_elem(union bpf_attr *attr) } else { rcu_read_lock(); ptr = map->ops->map_lookup_elem(map, key); - if (ptr) + if (IS_ERR(ptr)) { + err = PTR_ERR(ptr); + } else if (!ptr) { + err = -ENOENT; + } else { + err = 0; memcpy(value, ptr, value_size); + } rcu_read_unlock(); - err = ptr ? 0 : -ENOENT; } if (err) -- GitLab