mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-07 04:12:04 -04:00
BACKPORT: bpf: Prevent mmap()'ing read-only maps as writable
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> Change-Id: Ie3d1ad3f200ec3ee69b69c951482d22596d4cdb7 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
This commit is contained in:
parent
72906343f2
commit
23d812723b
1 changed files with 14 additions and 3 deletions
|
|
@ -627,9 +627,20 @@ static int bpf_map_mmap(struct file *filp, struct vm_area_struct *vma)
|
|||
|
||||
mutex_lock(&map->freeze_mutex);
|
||||
|
||||
if ((vma->vm_flags & VM_WRITE) && map->frozen) {
|
||||
err = -EPERM;
|
||||
goto out;
|
||||
if (vma->vm_flags & VM_WRITE) {
|
||||
if (map->frozen) {
|
||||
err = -EPERM;
|
||||
goto out;
|
||||
}
|
||||
/* map is meant to be read-only, so do not allow mapping as
|
||||
* writable, because it's possible to leak a writable page
|
||||
* reference and allows user-space to still modify it after
|
||||
* freezing, while verifier will assume contents do not change
|
||||
*/
|
||||
if (map->map_flags & BPF_F_RDONLY_PROG) {
|
||||
err = -EACCES;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* set default open/close callbacks */
|
||||
|
|
|
|||
Loading…
Reference in a new issue