treewide-use-initializer-for-struct-vm_unmapped_area_info.patch removed from -mm tree
The quilt patch titled
Subject: treewide: use initializer for struct vm_unmapped_area_info
has been removed from the -mm tree. Its filename was
treewide-use-initializer-for-struct-vm_unmapped_area_info.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Rick Edgecombe <[email protected]>
Subject: treewide: use initializer for struct vm_unmapped_area_info
Date: Mon, 25 Mar 2024 19:16:52 -0700
Future changes will need to add a new member to struct vm_unmapped_area_info. This would cause trouble for any call site that doesn't initialize the struct. Currently every caller sets each member manually, so if new ones are added they will be uninitialized and the core code parsing the struct will see garbage in the new member.
It could be possible to initialize the new member manually to 0 at each call site. This and a couple other options were discussed. Having some struct vm_unmapped_area_info instances not zero initialized will put those sites at risk of feeding garbage into vm_unmapped_area(), if the convention is to zero initialize the struct and any new field addition missed a call site that initializes each field manually. So it is useful to do things similar across the kernel.
The consensus (see links) was that in general the best way to accomplish taking into account both code cleanliness and minimizing the chance of introducing bugs, was to do C99 static initialization. As in: struct vm_unmapped_area_info info = {};
With this method of initialization, the whole struct will be zero initialized, and any statements setting fields to zero will be unneeded. The change should not leave cleanup at the call sides.
While iterating though the possible solutions a few archs kindly acked other variations that still zero initialized the struct. These sites have been modified in previous changes using the pattern acked by the respective arch.
So to be reduce the chance of bugs via uninitialized fields, perform a tree wide change using the consensus for the best general way to do this change. Use C99 static initializing to zero the struct and remove and statements that simply set members to zero.
---
arch/alpha/kernel/osf_sys.c | 5 +---- arch/arc/mm/mmap.c | 4 +--- arch/arm/mm/mmap.c | 5 ++--- arch/loongarch/mm/mmap.c | 3 +-- arch/mips/mm/mmap.c | 3 +-- arch/s390/mm/hugetlbpage.c | 7 ++----- arch/s390/mm/mmap.c | 5 ++--- arch/sh/mm/mmap.c | 5 ++--- arch/sparc/kernel/sys_sparc_32.c | 3 +-- arch/sparc/kernel/sys_sparc_64.c | 5 ++--- arch/sparc/mm/hugetlbpage.c | 7 ++----- arch/x86/kernel/sys_x86_64.c | 7 ++----- arch/x86/mm/hugetlbpage.c | 7 ++----- fs/hugetlbfs/inode.c | 7 ++----- mm/mmap.c | 9 ++------- 15 files changed, 25 insertions(+), 57 deletions(-)
arch/alpha/kernel/osf_sys.c renamed from arch/alpha/kernel/osf_sys.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +1 -4
@@ -1218,14 +1218,11 @@ static unsigned long arch_get_unmapped_area_1(unsigned long addr, unsigned long len, unsigned long limit) { -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {}; - info.flags =0 ; info.length = len; info.low_limit = addr; info.high_limit = limit; - info.align_mask =0 ; - info.align_offset =0 ;return vm_unmapped_area (&info); }
arch/arc/mm/mmap.c renamed from arch/arc/mm/mmap.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +1 -3
@@ -27,7 +27,7 @@ arch_get_unmapped_area(struct file *filp {struct mm_struct *mm = current->mm;struct vm_area_struct *vma; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};/* * We enforce the MAP_FIXED case.
@@ -51,11 +51,9 @@ arch_get_unmapped_area(struct file *filpreturn addr; } - info.flags =0 ; info.length = len; info.low_limit = mm->mmap_base; info.high_limit =TASK_SIZE ; - info.align_mask =0 ; info.align_offset = pgoff <<PAGE_SHIFT ;return vm_unmapped_area (&info); }
arch/arm/mm/mmap.c renamed from arch/arm/mm/mmap.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +2 -3
@@ -34,7 +34,7 @@ arch_get_unmapped_area(struct file *filpstruct vm_area_struct *vma;int do_align =0 ;int aliasing =cache_is_vipt_aliasing (); -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};/* * We only need to do colour alignment if either the I or D
@@ -68,7 +68,6 @@ arch_get_unmapped_area(struct file *filpreturn addr; } - info.flags =0 ; info.length = len; info.low_limit = mm->mmap_base; info.high_limit =TASK_SIZE ;
@@ -87,7 +86,7 @@ arch_get_unmapped_area_topdown(struct fiunsigned long addr = addr0;int do_align =0 ;int aliasing =cache_is_vipt_aliasing (); -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};/* * We only need to do colour alignment if either the I or D
arch/loongarch/mm/mmap.c renamed from arch/loongarch/mm/mmap.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +1 -2
@@ -25,7 +25,7 @@ static unsigned long arch_get_unmapped_astruct vm_area_struct *vma;unsigned long addr = addr0;int do_color_align; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};if (unlikely (len >TASK_SIZE ))return -ENOMEM ;
@@ -83,7 +83,6 @@ static unsigned long arch_get_unmapped_a*/ } - info.flags =0 ; info.low_limit = mm->mmap_base; info.high_limit =TASK_SIZE ;return vm_unmapped_area (&info);
arch/mips/mm/mmap.c renamed from arch/mips/mm/mmap.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +1 -2
@@ -34,7 +34,7 @@ static unsigned long arch_get_unmapped_astruct vm_area_struct *vma;unsigned long addr = addr0;int do_color_align; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};if (unlikely (len >TASK_SIZE ))return -ENOMEM ;
@@ -92,7 +92,6 @@ static unsigned long arch_get_unmapped_a*/ } - info.flags =0 ; info.low_limit = mm->mmap_base; info.high_limit =TASK_SIZE ;return vm_unmapped_area (&info);
arch/s390/mm/hugetlbpage.c renamed from arch/s390/mm/hugetlbpage.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +2 -5
@@ -248,14 +248,12 @@ static unsigned long hugetlb_get_unmappe unsigned long pgoff, unsigned long flags) {struct hstate *h =hstate_file (file); -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {}; - info.flags =0 ; info.length = len; info.low_limit = current->mm->mmap_base; info.high_limit =TASK_SIZE ; info.align_mask =PAGE_MASK & ~huge_page_mask (h); - info.align_offset =0 ;return vm_unmapped_area (&info); }
@@ -264,7 +262,7 @@ static unsigned long hugetlb_get_unmappe unsigned long pgoff, unsigned long flags) {struct hstate *h =hstate_file (file); -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};unsigned long addr; info.flags =VM_UNMAPPED_AREA_TOPDOWN ;
@@ -272,7 +270,6 @@ static unsigned long hugetlb_get_unmappe info.low_limit =PAGE_SIZE ; info.high_limit = current->mm->mmap_base; info.align_mask =PAGE_MASK & ~huge_page_mask (h); - info.align_offset =0 ; addr =vm_unmapped_area (&info);/*
arch/s390/mm/mmap.c renamed from arch/s390/mm/mmap.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +2 -3
@@ -86,7 +86,7 @@ unsigned long arch_get_unmapped_area(str {struct mm_struct *mm = current->mm;struct vm_area_struct *vma; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};if (len >TASK_SIZE - mmap_min_addr)return -ENOMEM ;
@@ -102,7 +102,6 @@ unsigned long arch_get_unmapped_area(str goto check_asce_limit; } - info.flags =0 ; info.length = len; info.low_limit = mm->mmap_base; info.high_limit =TASK_SIZE ;
@@ -122,7 +121,7 @@ unsigned long arch_get_unmapped_area_top {struct vm_area_struct *vma;struct mm_struct *mm = current->mm; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};/* requested length too big for entire address space */ if (len >TASK_SIZE - mmap_min_addr)
arch/sh/mm/mmap.c renamed from arch/sh/mm/mmap.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +2 -3
@@ -57,7 +57,7 @@ unsigned long arch_get_unmapped_area(strstruct mm_struct *mm = current->mm;struct vm_area_struct *vma;int do_colour_align; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};if (flags &MAP_FIXED ) {/* We do not accept a shared mapping if it would violate
@@ -88,7 +88,6 @@ unsigned long arch_get_unmapped_area(strreturn addr; } - info.flags =0 ; info.length = len; info.low_limit =TASK_UNMAPPED_BASE ; info.high_limit =TASK_SIZE ;
@@ -106,7 +105,7 @@ arch_get_unmapped_area_topdown(struct fistruct mm_struct *mm = current->mm;unsigned long addr = addr0;int do_colour_align; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};if (flags &MAP_FIXED ) {/* We do not accept a shared mapping if it would violate
arch/sparc/kernel/sys_sparc_32.c renamed from arch/sparc/kernel/sys_sparc_32.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +1 -2
@@ -41,7 +41,7 @@ SYSCALL_DEFINE0(getpagesize)unsigned long arch_get_unmapped_area (struct file *filp,unsigned long addr,unsigned long len,unsigned long pgoff,unsigned long flags) { -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};if (flags &MAP_FIXED ) {/* We do not accept a shared mapping if it would violate
@@ -59,7 +59,6 @@ unsigned long arch_get_unmapped_area(strif (!addr) addr =TASK_UNMAPPED_BASE ; - info.flags =0 ; info.length = len; info.low_limit = addr; info.high_limit =TASK_SIZE ;
arch/sparc/kernel/sys_sparc_64.c renamed from arch/sparc/kernel/sys_sparc_64.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +2 -3
@@ -93,7 +93,7 @@ unsigned long arch_get_unmapped_area(strstruct vm_area_struct * vma;unsigned long task_size =TASK_SIZE ;int do_color_align; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};if (flags &MAP_FIXED ) {/* We do not accept a shared mapping if it would violate
@@ -126,7 +126,6 @@ unsigned long arch_get_unmapped_area(strreturn addr; } - info.flags =0 ; info.length = len; info.low_limit =TASK_UNMAPPED_BASE ; info.high_limit =min (task_size,VA_EXCLUDE_START );
@@ -154,7 +153,7 @@ arch_get_unmapped_area_topdown(struct fiunsigned long task_size =STACK_TOP32 ;unsigned long addr = addr0;int do_color_align; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};/* This should only ever run for 32-bit processes. */ BUG_ON (!test_thread_flag (TIF_32BIT ));
arch/sparc/mm/hugetlbpage.c renamed from arch/sparc/mm/hugetlbpage.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +2 -5
@@ -31,17 +31,15 @@ static unsigned long hugetlb_get_unmappe {struct hstate *h =hstate_file (filp);unsigned long task_size =TASK_SIZE ; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};if (test_thread_flag (TIF_32BIT )) task_size =STACK_TOP32 ; - info.flags =0 ; info.length = len; info.low_limit =TASK_UNMAPPED_BASE ; info.high_limit =min (task_size,VA_EXCLUDE_START ); info.align_mask =PAGE_MASK & ~huge_page_mask (h); - info.align_offset =0 ; addr =vm_unmapped_area (&info);if ((addr & ~PAGE_MASK ) && task_size >VA_EXCLUDE_END ) {
@@ -63,7 +61,7 @@ hugetlb_get_unmapped_area_topdown(structstruct hstate *h =hstate_file (filp);struct mm_struct *mm = current->mm;unsigned long addr = addr0; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};/* This should only ever run for 32-bit processes. */ BUG_ON (!test_thread_flag (TIF_32BIT ));
@@ -73,7 +71,6 @@ hugetlb_get_unmapped_area_topdown(struct info.low_limit =PAGE_SIZE ; info.high_limit = mm->mmap_base; info.align_mask =PAGE_MASK & ~huge_page_mask (h); - info.align_offset =0 ; addr =vm_unmapped_area (&info);/*
arch/x86/kernel/sys_x86_64.c renamed from arch/x86/kernel/sys_x86_64.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +2 -5
@@ -118,7 +118,7 @@ arch_get_unmapped_area(struct file *filp {struct mm_struct *mm = current->mm;struct vm_area_struct *vma; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};unsigned long begin, end;if (flags &MAP_FIXED )
@@ -137,11 +137,9 @@ arch_get_unmapped_area(struct file *filpreturn addr; } - info.flags =0 ; info.length = len; info.low_limit = begin; info.high_limit = end; - info.align_mask =0 ; info.align_offset = pgoff <<PAGE_SHIFT ;if (filp) { info.align_mask =get_align_mask ();
@@ -158,7 +156,7 @@ arch_get_unmapped_area_topdown(struct fistruct vm_area_struct *vma;struct mm_struct *mm = current->mm;unsigned long addr = addr0; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};/* requested length too big for entire address space */ if (len >TASK_SIZE )
@@ -203,7 +201,6 @@ get_unmapped_area:if (addr >DEFAULT_MAP_WINDOW && !in_32bit_syscall ()) info.high_limit +=TASK_SIZE_MAX -DEFAULT_MAP_WINDOW ; - info.align_mask =0 ; info.align_offset = pgoff <<PAGE_SHIFT ;if (filp) { info.align_mask =get_align_mask ();
arch/x86/mm/hugetlbpage.c renamed from arch/x86/mm/hugetlbpage.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +2 -5
@@ -25,9 +25,8 @@ static unsigned long hugetlb_get_unmappe unsigned long pgoff, unsigned long flags) {struct hstate *h =hstate_file (file); -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {}; - info.flags =0 ; info.length = len; info.low_limit =get_mmap_base (1 );
@@ -39,7 +38,6 @@ static unsigned long hugetlb_get_unmappe task_size_32bit() : task_size_64bit(addr > DEFAULT_MAP_WINDOW); info.align_mask =PAGE_MASK & ~huge_page_mask (h); - info.align_offset =0 ;return vm_unmapped_area (&info); }
@@ -48,7 +46,7 @@ static unsigned long hugetlb_get_unmappe unsigned long pgoff, unsigned long flags) {struct hstate *h =hstate_file (file); -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {}; info.flags =VM_UNMAPPED_AREA_TOPDOWN ; info.length = len;
@@ -63,7 +61,6 @@ static unsigned long hugetlb_get_unmappe info.high_limit +=TASK_SIZE_MAX -DEFAULT_MAP_WINDOW ; info.align_mask =PAGE_MASK & ~huge_page_mask (h); - info.align_offset =0 ; addr =vm_unmapped_area (&info);/*
fs/hugetlbfs/inode.c renamed from fs/hugetlbfs/inode.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +2 -5
@@ -176,14 +176,12 @@ hugetlb_get_unmapped_area_bottomup(struc unsigned long len, unsigned long pgoff, unsigned long flags) { struct hstate *h = hstate_file(file); -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {}; - info.flags =0 ; info.length = len; info.low_limit = current->mm->mmap_base; info.high_limit =arch_get_mmap_end (addr, len, flags); info.align_mask =PAGE_MASK & ~huge_page_mask (h); - info.align_offset =0 ;return vm_unmapped_area (&info); }
@@ -192,14 +190,13 @@ hugetlb_get_unmapped_area_topdown(struct unsigned long len, unsigned long pgoff, unsigned long flags) { struct hstate *h = hstate_file(file); -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {}; info.flags =VM_UNMAPPED_AREA_TOPDOWN ; info.length = len; info.low_limit =PAGE_SIZE ; info.high_limit =arch_get_mmap_base (addr, current->mm->mmap_base); info.align_mask =PAGE_MASK & ~huge_page_mask (h); - info.align_offset =0 ; addr =vm_unmapped_area (&info);/*
mm/mmap.c renamed from mm/mmap.c~treewide-use-initializer-for-struct-vm_unmapped_area_info +2 -7
@@ -1704,7 +1704,7 @@ generic_get_unmapped_area(struct file *f {struct mm_struct *mm = current->mm;struct vm_area_struct *vma, *prev; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};const unsigned long mmap_end =arch_get_mmap_end (addr, len, flags);if (len > mmap_end - mmap_min_addr)
@@ -1722,12 +1722,9 @@ generic_get_unmapped_area(struct file *freturn addr; } - info.flags =0 ; info.length = len; info.low_limit = mm->mmap_base; info.high_limit = mmap_end; - info.align_mask =0 ; - info.align_offset =0 ;return vm_unmapped_area (&info); }
@@ -1752,7 +1749,7 @@ generic_get_unmapped_area_topdown(struct {struct vm_area_struct *vma, *prev;struct mm_struct *mm = current->mm; -struct vm_unmapped_area_info info; +struct vm_unmapped_area_info info = {};const unsigned long mmap_end =arch_get_mmap_end (addr, len, flags);/* requested length too big for entire address space */
@@ -1776,8 +1773,6 @@ generic_get_unmapped_area_topdown(struct info.length = len; info.low_limit =PAGE_SIZE ; info.high_limit =arch_get_mmap_base (addr, mm->mmap_base); - info.align_mask =0 ; - info.align_offset =0 ; addr =vm_unmapped_area (&info);/*
_
Patches currently in -mm which might be from [email protected] are