]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
bpf: Prevent mmap()'ing read-only maps as writable
authorAndrii Nakryiko <andriin@fb.com>
Tue, 19 May 2020 05:38:24 +0000 (22:38 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 May 2020 15:48:30 +0000 (17:48 +0200)
commitf469812cdabc2f0422c8df24657948621cf4f7d1
tree8a3abd5bf71769b6b8b7555c4d63bfbfed73ffec
parentf8acf4915283019bccf59e94e7e0de408e70745d
bpf: Prevent mmap()'ing read-only maps as writable

[ Upstream commit dfeb376dd4cb2c5004aeb625e2475f58a5ff2ea7 ]

As discussed in [0], it's dangerous to allow mapping BPF map, that's meant to
be frozen and is read-only on BPF program side, because that allows user-space
to actually store a writable view to the page even after it is frozen. This is
exacerbated by BPF verifier making a strong assumption that contents of such
frozen map will remain unchanged. To prevent this, disallow mapping
BPF_F_RDONLY_PROG mmap()'able BPF maps as writable, ever.

  [0] https://lore.kernel.org/bpf/CAEf4BzYGWYhXdp6BJ7_=9OQPJxQpgug080MMjdSB72i9R+5c6g@mail.gmail.com/

Fixes: fc9702273e2e ("bpf: Add mmap() support for BPF_MAP_TYPE_ARRAY")
Suggested-by: Jann Horn <jannh@google.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Jann Horn <jannh@google.com>
Link: https://lore.kernel.org/bpf/20200519053824.1089415-1-andriin@fb.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/bpf/syscall.c
tools/testing/selftests/bpf/prog_tests/mmap.c
tools/testing/selftests/bpf/progs/test_mmap.c