Skip to content

Commit 0bf5f94

Browse files
Christoph Hellwigtorvalds
authored andcommitted
mm: fix the MAP_UNINITIALIZED flag
We can't expose UAPI symbols differently based on CONFIG_ symbols, as userspace won't have them available. Instead always define the flag, but only respect it based on the config option. Link: http://lkml.kernel.org/r/20190703122359.18200-2-hch@lst.de Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Vladimir Murzin <vladimir.murzin@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c633324 commit 0bf5f94

3 files changed

Lines changed: 7 additions & 11 deletions

File tree

‎arch/xtensa/include/uapi/asm/mman.h‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@
5656
#define MAP_STACK 0x40000 /* give out an address that is best suited for process/thread stacks */
5757
#define MAP_HUGETLB 0x80000 /* create a huge page mapping */
5858
#define MAP_FIXED_NOREPLACE 0x100000 /* MAP_FIXED which doesn't unmap underlying mapping */
59-
#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
60-
# define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory could be
59+
#define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory could be
6160
* uninitialized */
62-
#else
63-
# define MAP_UNINITIALIZED 0x0 /* Don't support this flag */
64-
#endif
6561

6662
/*
6763
* Flags for msync

‎include/uapi/asm-generic/mman-common.h‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
#define MAP_TYPE 0x0f /* Mask for type of mapping */
2020
#define MAP_FIXED 0x10 /* Interpret addr exactly */
2121
#define MAP_ANONYMOUS 0x20 /* don't use a file */
22-
#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
23-
# define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory could be uninitialized */
24-
#else
25-
# define MAP_UNINITIALIZED 0x0 /* Don't support this flag */
26-
#endif
2722

2823
/* 0x0100 - 0x80000 flags are defined in asm-generic/mman.h */
2924
#define MAP_FIXED_NOREPLACE 0x100000 /* MAP_FIXED which doesn't unmap underlying mapping */
3025

26+
#define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory could be
27+
* uninitialized */
28+
3129
/*
3230
* Flags for mlock
3331
*/

‎mm/nommu.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,9 @@ unsigned long do_mmap(struct file *file,
12611261
add_nommu_region(region);
12621262

12631263
/* clear anonymous mappings that don't ask for uninitialized data */
1264-
if (!vma->vm_file && !(flags & MAP_UNINITIALIZED))
1264+
if (!vma->vm_file &&
1265+
(!IS_ENABLED(CONFIG_MMAP_ALLOW_UNINITIALIZED) ||
1266+
!(flags & MAP_UNINITIALIZED)))
12651267
memset((void *)region->vm_start, 0,
12661268
region->vm_end - region->vm_start);
12671269

0 commit comments

Comments
 (0)