Skip to content

Commit 3c7b204

Browse files
berndstorvalds
authored andcommitted
nommu: allow private mappings of read-only devices
Slightly rearrange the logic that determines capabilities and vm_flags. Disable BDI_CAP_MAP_DIRECT in all cases if the device can't support the protections. Allow private readonly mappings of readonly backing devices. Signed-off-by: Bernd Schmidt <bernds_cb1@t-online.de> Signed-off-by: Mike Frysinger <vapier@gentoo.org> Acked-by: David McCullough <davidm@snapgear.com> Acked-by: Greg Ungerer <gerg@uclinux.org> Acked-by: Paul Mundt <lethal@linux-sh.org> Acked-by: David Howells <dhowells@redhat.com> Cc: Hugh Dickins <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0cae345 commit 3c7b204

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

‎mm/nommu.c‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -918,14 +918,6 @@ static int validate_mmap_request(struct file *file,
918918
if (!(capabilities & BDI_CAP_MAP_DIRECT))
919919
return -ENODEV;
920920

921-
if (((prot & PROT_READ) && !(capabilities & BDI_CAP_READ_MAP)) ||
922-
((prot & PROT_WRITE) && !(capabilities & BDI_CAP_WRITE_MAP)) ||
923-
((prot & PROT_EXEC) && !(capabilities & BDI_CAP_EXEC_MAP))
924-
) {
925-
printk("MAP_SHARED not completely supported on !MMU\n");
926-
return -EINVAL;
927-
}
928-
929921
/* we mustn't privatise shared mappings */
930922
capabilities &= ~BDI_CAP_MAP_COPY;
931923
}
@@ -941,6 +933,20 @@ static int validate_mmap_request(struct file *file,
941933
capabilities &= ~BDI_CAP_MAP_DIRECT;
942934
}
943935

936+
if (capabilities & BDI_CAP_MAP_DIRECT) {
937+
if (((prot & PROT_READ) && !(capabilities & BDI_CAP_READ_MAP)) ||
938+
((prot & PROT_WRITE) && !(capabilities & BDI_CAP_WRITE_MAP)) ||
939+
((prot & PROT_EXEC) && !(capabilities & BDI_CAP_EXEC_MAP))
940+
) {
941+
capabilities &= ~BDI_CAP_MAP_DIRECT;
942+
if (flags & MAP_SHARED) {
943+
printk(KERN_WARNING
944+
"MAP_SHARED not completely supported on !MMU\n");
945+
return -EINVAL;
946+
}
947+
}
948+
}
949+
944950
/* handle executable mappings and implied executable
945951
* mappings */
946952
if (file->f_path.mnt->mnt_flags & MNT_NOEXEC) {
@@ -996,22 +1002,20 @@ static unsigned long determine_vm_flags(struct file *file,
9961002
unsigned long vm_flags;
9971003

9981004
vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags);
999-
vm_flags |= VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
10001005
/* vm_flags |= mm->def_flags; */
10011006

10021007
if (!(capabilities & BDI_CAP_MAP_DIRECT)) {
10031008
/* attempt to share read-only copies of mapped file chunks */
1009+
vm_flags |= VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
10041010
if (file && !(prot & PROT_WRITE))
10051011
vm_flags |= VM_MAYSHARE;
1006-
}
1007-
else {
1012+
} else {
10081013
/* overlay a shareable mapping on the backing device or inode
10091014
* if possible - used for chardevs, ramfs/tmpfs/shmfs and
10101015
* romfs/cramfs */
1016+
vm_flags |= VM_MAYSHARE | (capabilities & BDI_CAP_VMFLAGS);
10111017
if (flags & MAP_SHARED)
1012-
vm_flags |= VM_MAYSHARE | VM_SHARED;
1013-
else if ((((vm_flags & capabilities) ^ vm_flags) & BDI_CAP_VMFLAGS) == 0)
1014-
vm_flags |= VM_MAYSHARE;
1018+
vm_flags |= VM_SHARED;
10151019
}
10161020

10171021
/* refuse to let anyone share private mappings with this process if

0 commit comments

Comments
 (0)