Skip to content

Commit

Permalink
bpf: Fix bad unlock balance on freeze_mutex
Browse files Browse the repository at this point in the history
Commit c4c84f6 ("bpf: drop unnecessary bpf_capable() check in
BPF_MAP_FREEZE command") moved the permissions check outside of the
freeze_mutex in the map_freeze() handler. The error paths still jumps
to the err_put which tries to unlock the freeze_mutex even though it
was not locked in the first place. Fix it.

Fixes: c4c84f6 ("bpf: drop unnecessary bpf_capable() check in BPF_MAP_FREEZE command")
Reported-by: syzbot+8982e75c2878b9ffeac5@syzkaller.appspotmail.com
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
  • Loading branch information
borkmann committed May 26, 2023
1 parent 4aadd29 commit 4266f41
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/bpf/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1932,8 +1932,8 @@ static int map_freeze(const union bpf_attr *attr)
}

if (!(map_get_sys_perms(map, f) & FMODE_CAN_WRITE)) {
err = -EPERM;
goto err_put;
fdput(f);
return -EPERM;
}

mutex_lock(&map->freeze_mutex);
Expand Down

0 comments on commit 4266f41

Please sign in to comment.