Message ID | 20180706053545.GD32658@dhcp22.suse.cz (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
> Reported-by: syzbot <syzbot+5dcb560fe12aa5091c06@syzkaller.appspotmail.com> > [osalvador: fix up vm_brk_flags s@request@len@] > Tested-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> > Cc: stable > Signed-off-by: Michal Hocko <mhocko@suse.com> hi Michal, I gave it another spin and it works for me. FWIW: Reviewed-by: Oscar Salvador <osalvador@suse.de>
Hi Michal,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v4.18-rc3 next-20180705]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Michal-Hocko/mm-do-not-bug_on-on-incorrect-lenght-in-__mm_populate/20180706-134850
config: x86_64-randconfig-x015-201826 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64
All errors (new ones prefixed by >>):
mm/mmap.c: In function 'do_brk_flags':
>> mm/mmap.c:2936:16: error: 'len' redeclared as different kind of symbol
unsigned long len;
^~~
mm/mmap.c:2932:59: note: previous definition of 'len' was here
static int do_brk_flags(unsigned long addr, unsigned long len, unsigned long flags, struct list_head *uf)
^~~
vim +/len +2936 mm/mmap.c
^1da177e4 Linus Torvalds 2005-04-16 2926
^1da177e4 Linus Torvalds 2005-04-16 2927 /*
^1da177e4 Linus Torvalds 2005-04-16 2928 * this is really a simplified "do_mmap". it only handles
^1da177e4 Linus Torvalds 2005-04-16 2929 * anonymous maps. eventually we may be able to do some
^1da177e4 Linus Torvalds 2005-04-16 2930 * brk-specific accounting here.
^1da177e4 Linus Torvalds 2005-04-16 2931 */
e3049e198 Michal Hocko 2018-07-06 2932 static int do_brk_flags(unsigned long addr, unsigned long len, unsigned long flags, struct list_head *uf)
^1da177e4 Linus Torvalds 2005-04-16 2933 {
^1da177e4 Linus Torvalds 2005-04-16 2934 struct mm_struct *mm = current->mm;
^1da177e4 Linus Torvalds 2005-04-16 2935 struct vm_area_struct *vma, *prev;
16e72e9b3 Denys Vlasenko 2017-02-22 @2936 unsigned long len;
^1da177e4 Linus Torvalds 2005-04-16 2937 struct rb_node **rb_link, *rb_parent;
^1da177e4 Linus Torvalds 2005-04-16 2938 pgoff_t pgoff = addr >> PAGE_SHIFT;
3a4597568 Kirill Korotaev 2006-09-07 2939 int error;
^1da177e4 Linus Torvalds 2005-04-16 2940
16e72e9b3 Denys Vlasenko 2017-02-22 2941 /* Until we need other flags, refuse anything except VM_EXEC. */
16e72e9b3 Denys Vlasenko 2017-02-22 2942 if ((flags & (~VM_EXEC)) != 0)
16e72e9b3 Denys Vlasenko 2017-02-22 2943 return -EINVAL;
16e72e9b3 Denys Vlasenko 2017-02-22 2944 flags |= VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
3a4597568 Kirill Korotaev 2006-09-07 2945
2c6a10161 Al Viro 2009-12-03 2946 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
de1741a13 Alexander Kuleshov 2015-11-05 2947 if (offset_in_page(error))
3a4597568 Kirill Korotaev 2006-09-07 2948 return error;
3a4597568 Kirill Korotaev 2006-09-07 2949
363ee17f0 Davidlohr Bueso 2014-01-21 2950 error = mlock_future_check(mm, mm->def_flags, len);
363ee17f0 Davidlohr Bueso 2014-01-21 2951 if (error)
363ee17f0 Davidlohr Bueso 2014-01-21 2952 return error;
^1da177e4 Linus Torvalds 2005-04-16 2953
^1da177e4 Linus Torvalds 2005-04-16 2954 /*
^1da177e4 Linus Torvalds 2005-04-16 2955 * mm->mmap_sem is required to protect against another thread
^1da177e4 Linus Torvalds 2005-04-16 2956 * changing the mappings in case we sleep.
^1da177e4 Linus Torvalds 2005-04-16 2957 */
^1da177e4 Linus Torvalds 2005-04-16 2958 verify_mm_writelocked(mm);
^1da177e4 Linus Torvalds 2005-04-16 2959
^1da177e4 Linus Torvalds 2005-04-16 2960 /*
^1da177e4 Linus Torvalds 2005-04-16 2961 * Clear old maps. this also does some error checking for us
^1da177e4 Linus Torvalds 2005-04-16 2962 */
9fcd14571 Rasmus Villemoes 2015-04-15 2963 while (find_vma_links(mm, addr, addr + len, &prev, &rb_link,
9fcd14571 Rasmus Villemoes 2015-04-15 2964 &rb_parent)) {
897ab3e0c Mike Rapoport 2017-02-24 2965 if (do_munmap(mm, addr, len, uf))
^1da177e4 Linus Torvalds 2005-04-16 2966 return -ENOMEM;
^1da177e4 Linus Torvalds 2005-04-16 2967 }
^1da177e4 Linus Torvalds 2005-04-16 2968
^1da177e4 Linus Torvalds 2005-04-16 2969 /* Check against address space limits *after* clearing old maps... */
846383359 Konstantin Khlebnikov 2016-01-14 2970 if (!may_expand_vm(mm, flags, len >> PAGE_SHIFT))
^1da177e4 Linus Torvalds 2005-04-16 2971 return -ENOMEM;
^1da177e4 Linus Torvalds 2005-04-16 2972
^1da177e4 Linus Torvalds 2005-04-16 2973 if (mm->map_count > sysctl_max_map_count)
^1da177e4 Linus Torvalds 2005-04-16 2974 return -ENOMEM;
^1da177e4 Linus Torvalds 2005-04-16 2975
191c54244 Al Viro 2012-02-13 2976 if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
^1da177e4 Linus Torvalds 2005-04-16 2977 return -ENOMEM;
^1da177e4 Linus Torvalds 2005-04-16 2978
^1da177e4 Linus Torvalds 2005-04-16 2979 /* Can we just expand an old private anonymous mapping? */
ba470de43 Rik van Riel 2008-10-18 2980 vma = vma_merge(mm, prev, addr, addr + len, flags,
19a809afe Andrea Arcangeli 2015-09-04 2981 NULL, NULL, pgoff, NULL, NULL_VM_UFFD_CTX);
ba470de43 Rik van Riel 2008-10-18 2982 if (vma)
^1da177e4 Linus Torvalds 2005-04-16 2983 goto out;
^1da177e4 Linus Torvalds 2005-04-16 2984
^1da177e4 Linus Torvalds 2005-04-16 2985 /*
^1da177e4 Linus Torvalds 2005-04-16 2986 * create a vma struct for an anonymous mapping
^1da177e4 Linus Torvalds 2005-04-16 2987 */
c5e3b83e9 Pekka Enberg 2006-03-25 2988 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
^1da177e4 Linus Torvalds 2005-04-16 2989 if (!vma) {
^1da177e4 Linus Torvalds 2005-04-16 2990 vm_unacct_memory(len >> PAGE_SHIFT);
^1da177e4 Linus Torvalds 2005-04-16 2991 return -ENOMEM;
^1da177e4 Linus Torvalds 2005-04-16 2992 }
^1da177e4 Linus Torvalds 2005-04-16 2993
5beb49305 Rik van Riel 2010-03-05 2994 INIT_LIST_HEAD(&vma->anon_vma_chain);
^1da177e4 Linus Torvalds 2005-04-16 2995 vma->vm_mm = mm;
^1da177e4 Linus Torvalds 2005-04-16 2996 vma->vm_start = addr;
^1da177e4 Linus Torvalds 2005-04-16 2997 vma->vm_end = addr + len;
^1da177e4 Linus Torvalds 2005-04-16 2998 vma->vm_pgoff = pgoff;
^1da177e4 Linus Torvalds 2005-04-16 2999 vma->vm_flags = flags;
3ed75eb8f Coly Li 2007-10-18 3000 vma->vm_page_prot = vm_get_page_prot(flags);
^1da177e4 Linus Torvalds 2005-04-16 3001 vma_link(mm, vma, prev, rb_link, rb_parent);
^1da177e4 Linus Torvalds 2005-04-16 3002 out:
3af9e8592 Eric B Munson 2010-05-18 3003 perf_event_mmap(vma);
^1da177e4 Linus Torvalds 2005-04-16 3004 mm->total_vm += len >> PAGE_SHIFT;
846383359 Konstantin Khlebnikov 2016-01-14 3005 mm->data_vm += len >> PAGE_SHIFT;
128557ffe Michel Lespinasse 2013-02-22 3006 if (flags & VM_LOCKED)
ba470de43 Rik van Riel 2008-10-18 3007 mm->locked_vm += (len >> PAGE_SHIFT);
d9104d1ca Cyrill Gorcunov 2013-09-11 3008 vma->vm_flags |= VM_SOFTDIRTY;
5d22fc25d Linus Torvalds 2016-05-27 3009 return 0;
^1da177e4 Linus Torvalds 2005-04-16 3010 }
^1da177e4 Linus Torvalds 2005-04-16 3011
:::::: The code at line 2936 was first introduced by commit
:::::: 16e72e9b30986ee15f17fbb68189ca842c32af58 powerpc: do not make the entire heap executable
:::::: TO: Denys Vlasenko <dvlasenk@redhat.com>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
On Fri, Jul 06, 2018 at 03:50:53PM +0800, kbuild test robot wrote: > Hi Michal, > > I love your patch! Yet something to improve: > > [auto build test ERROR on linus/master] > [also build test ERROR on v4.18-rc3 next-20180705] > [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] > > url: https://github.com/0day-ci/linux/commits/Michal-Hocko/mm-do-not-bug_on-on-incorrect-lenght-in-__mm_populate/20180706-134850 > config: x86_64-randconfig-x015-201826 (attached as .config) > compiler: gcc-7 (Debian 7.3.0-16) 7.3.0 > reproduce: > # save the attached .config to linux build tree > make ARCH=x86_64 > > All errors (new ones prefixed by >>): > > mm/mmap.c: In function 'do_brk_flags': > >> mm/mmap.c:2936:16: error: 'len' redeclared as different kind of symbol > unsigned long len; > ^~~ > mm/mmap.c:2932:59: note: previous definition of 'len' was here > static int do_brk_flags(unsigned long addr, unsigned long len, unsigned long flags, struct list_head *uf) Somehow I missed that. Maybe some remains from yesterday. The local variable "len" must be dropped.
diff --git a/mm/gup.c b/mm/gup.c index b70d7ba7cc13..fc5f98069f4e 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1238,8 +1238,6 @@ int __mm_populate(unsigned long start, unsigned long len, int ignore_errors) int locked = 0; long ret = 0; - VM_BUG_ON(start & ~PAGE_MASK); - VM_BUG_ON(len != PAGE_ALIGN(len)); end = start + len; for (nstart = start; nstart < end; nstart = nend) { diff --git a/mm/mmap.c b/mm/mmap.c index d1eb87ef4b1a..9e68b7041ae3 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -186,8 +186,8 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma) return next; } -static int do_brk(unsigned long addr, unsigned long len, struct list_head *uf); - +static int do_brk_flags(unsigned long addr, unsigned long request, unsigned long flags, + struct list_head *uf); SYSCALL_DEFINE1(brk, unsigned long, brk) { unsigned long retval; @@ -245,7 +245,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk) goto out; /* Ok, looks good - let it rip. */ - if (do_brk(oldbrk, newbrk-oldbrk, &uf) < 0) + if (do_brk_flags(oldbrk, newbrk-oldbrk, 0, &uf) < 0) goto out; set_brk: @@ -2929,7 +2929,7 @@ static inline void verify_mm_writelocked(struct mm_struct *mm) * anonymous maps. eventually we may be able to do some * brk-specific accounting here. */ -static int do_brk_flags(unsigned long addr, unsigned long request, unsigned long flags, struct list_head *uf) +static int do_brk_flags(unsigned long addr, unsigned long len, unsigned long flags, struct list_head *uf) { struct mm_struct *mm = current->mm; struct vm_area_struct *vma, *prev; @@ -2938,12 +2938,6 @@ static int do_brk_flags(unsigned long addr, unsigned long request, unsigned long pgoff_t pgoff = addr >> PAGE_SHIFT; int error; - len = PAGE_ALIGN(request); - if (len < request) - return -ENOMEM; - if (!len) - return 0; - /* Until we need other flags, refuse anything except VM_EXEC. */ if ((flags & (~VM_EXEC)) != 0) return -EINVAL; @@ -3015,18 +3009,20 @@ static int do_brk_flags(unsigned long addr, unsigned long request, unsigned long return 0; } -static int do_brk(unsigned long addr, unsigned long len, struct list_head *uf) -{ - return do_brk_flags(addr, len, 0, uf); -} - -int vm_brk_flags(unsigned long addr, unsigned long len, unsigned long flags) +int vm_brk_flags(unsigned long addr, unsigned long request, unsigned long flags) { struct mm_struct *mm = current->mm; + unsigned long len; int ret; bool populate; LIST_HEAD(uf); + len = PAGE_ALIGN(request); + if (len < request) + return -ENOMEM; + if (!len) + return 0; + if (down_write_killable(&mm->mmap_sem)) return -EINTR;