Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754829Ab3CLAYf (ORCPT ); Mon, 11 Mar 2013 20:24:35 -0400 Received: from mail-pb0-f41.google.com ([209.85.160.41]:58431 "EHLO mail-pb0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754446Ab3CLAYd (ORCPT ); Mon, 11 Mar 2013 20:24:33 -0400 Date: Mon, 11 Mar 2013 17:24:29 -0700 From: Michel Lespinasse To: Andrew Morton Cc: Tommi Rantala , Andy Lutomirski , Ingo Molnar , Al Viro , Hugh Dickins , Jorn_Engel , Rik van Riel , "linux-mm@kvack.org" , LKML , Dave Jones Subject: Re: [PATCH 4/9] mm: use mm_populate() for blocking remap_file_pages() Message-ID: <20130312002429.GA24360@google.com> References: <1356050997-2688-1-git-send-email-walken@google.com> <1356050997-2688-5-git-send-email-walken@google.com> <20130311160322.830cc6b670fd24faa8366413@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130311160322.830cc6b670fd24faa8366413@linux-foundation.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2939 Lines: 88 (Sorry for the late reply) On Mon, Mar 11, 2013 at 4:03 PM, Andrew Morton wrote: > On Sun, 10 Mar 2013 20:55:21 +0200 Tommi Rantala wrote: > >> 2012/12/21 Michel Lespinasse : >> > Signed-off-by: Michel Lespinasse >> >> Hello, this patch introduced the following bug, seen while fuzzing with trinity: >> >> [ 396.825414] BUG: unable to handle kernel NULL pointer dereference >> at 0000000000000050 Good catch... > From: Andrew Morton > Subject: mm/fremap.c: fix oops on error path > > If find_vma() fails, sys_remap_file_pages() will dereference `vma', which > contains NULL. Fix it by checking the pointer. > > (We could alternatively check for err==0, but this seems more direct) > > (The vm_flags change is to squish a bogus used-uninitialised warning > without adding extra code). > > Reported-by: Tommi Rantala > Cc: Michel Lespinasse > Signed-off-by: Andrew Morton > --- > > mm/fremap.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff -puN mm/fremap.c~mm-fremapc-fix-oops-on-error-path mm/fremap.c > --- a/mm/fremap.c~mm-fremapc-fix-oops-on-error-path > +++ a/mm/fremap.c > @@ -163,7 +163,8 @@ SYSCALL_DEFINE5(remap_file_pages, unsign > * and that the remapped range is valid and fully within > * the single existing vma. > */ > - if (!vma || !(vma->vm_flags & VM_SHARED)) > + vm_flags = vma->vm_flags; > + if (!vma || !(vm_flags & VM_SHARED)) > goto out; Your commit message indicates the vm_flags load here doesn't generate any code, but this seems very brittle and compiler dependent. If the compiler was to generate an actual load here, the issue with vma == NULL would reappear. > if (!vma->vm_ops || !vma->vm_ops->remap_pages) > @@ -254,7 +255,8 @@ get_write_lock: > */ > > out: > - vm_flags = vma->vm_flags; > + if (vma) > + vm_flags = vma->vm_flags; > if (likely(!has_write_lock)) > up_read(&mm->mmap_sem); > else Would the following work ? I think it's simpler, and with the compiler I'm using here it doesn't emit warnings: diff --git a/mm/fremap.c b/mm/fremap.c index 0cd4c11488ed..329507e832fb 100644 --- a/mm/fremap.c +++ b/mm/fremap.c @@ -254,7 +254,8 @@ get_write_lock: */ out: - vm_flags = vma->vm_flags; + if (!err) + vm_flags = vma->vm_flags; if (likely(!has_write_lock)) up_read(&mm->mmap_sem); else -- Michel "Walken" Lespinasse A program is never fully debugged until the last user dies. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/