bpf: Fix error return code in map_lookup_and_delete_elem()
authorWei Yongjun <weiyongjun1@huawei.com>
Thu, 30 Apr 2020 08:18:51 +0000 (08:18 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 30 Apr 2020 14:19:08 +0000 (16:19 +0200)
Fix to return negative error code -EFAULT from the copy_to_user() error
handling case instead of 0, as done elsewhere in this function.

Fixes: bd513cd08f10 ("bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200430081851.166996-1-weiyongjun1@huawei.com
kernel/bpf/syscall.c

index 7626b802447128f4fc5ec789e24d9bb6d8e96a27..2843bbba9ca10a30ac48359a8f4f1e4dfdc7c5db 100644 (file)
@@ -1485,8 +1485,10 @@ static int map_lookup_and_delete_elem(union bpf_attr *attr)
        if (err)
                goto free_value;
 
-       if (copy_to_user(uvalue, value, value_size) != 0)
+       if (copy_to_user(uvalue, value, value_size) != 0) {
+               err = -EFAULT;
                goto free_value;
+       }
 
        err = 0;