Skip to content

Commit 1ea0f91

Browse files
aspskAlexei Starovoitov
authored andcommitted
bpf: Fix map permissions check
The map_lookup_and_delete_elem() function should check for both FMODE_CAN_WRITE and FMODE_CAN_READ permissions because it returns a map element to user space. Fixes: bd513cd ("bpf: add MAP_LOOKUP_AND_DELETE_ELEM syscall") Signed-off-by: Anton Protopopov <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent efbc3b8 commit 1ea0f91

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/bpf/syscall.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,8 @@ static int map_lookup_and_delete_elem(union bpf_attr *attr)
14721472
map = __bpf_map_get(f);
14731473
if (IS_ERR(map))
14741474
return PTR_ERR(map);
1475-
if (!(map_get_sys_perms(map, f) & FMODE_CAN_WRITE)) {
1475+
if (!(map_get_sys_perms(map, f) & FMODE_CAN_READ) ||
1476+
!(map_get_sys_perms(map, f) & FMODE_CAN_WRITE)) {
14761477
err = -EPERM;
14771478
goto err_put;
14781479
}

0 commit comments

Comments
 (0)