Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754175AbYG2BZk (ORCPT ); Mon, 28 Jul 2008 21:25:40 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751893AbYG2BZb (ORCPT ); Mon, 28 Jul 2008 21:25:31 -0400 Received: from extu-mxob-2.symantec.com ([216.10.194.135]:46242 "EHLO extu-mxob-2.symantec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751790AbYG2BZb (ORCPT ); Mon, 28 Jul 2008 21:25:31 -0400 Date: Tue, 29 Jul 2008 02:25:07 +0100 (BST) From: Hugh Dickins X-X-Sender: hugh@blonde.site To: Linus Torvalds cc: Johannes Weiner , Alexey Dobriyan , akpm@linuxfoundation.org, torvalds@linuxfoundation.org, npiggin@suse.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86: do not overrun page table ranges in gup In-Reply-To: Message-ID: References: <20080728184947.GA5041@martell.zuzino.mipt.ru> <20080728185316.GA19479@martell.zuzino.mipt.ru> <87y73l5zlj.fsf_-_@saeurebad.de> <87tze95yrk.fsf@saeurebad.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1721 Lines: 55 On Mon, 28 Jul 2008, Linus Torvalds wrote: > On Mon, 28 Jul 2008, Linus Torvalds wrote: > > > > So no, the right fix would be to align 'start' first, which means that > > everything else (including 'end') will be page-aligned. Aligning just one > > or the other is very very wrong. > > Does this work? > > Not pretty, but it stands _some_ chance of being correct. > > Linus Acked-by: Hugh Dickins Seeing the bug report, I was working up a patch along the same lines as this; but got the access_ok() issue backwards: yours looks right. I see Alexey has tested it, confess I haven't. > > > --- > arch/x86/mm/gup.c | 9 ++++++--- > 1 files changed, 6 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c > index 3085f25..007bb06 100644 > --- a/arch/x86/mm/gup.c > +++ b/arch/x86/mm/gup.c > @@ -223,14 +223,17 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write, > struct page **pages) > { > struct mm_struct *mm = current->mm; > - unsigned long end = start + (nr_pages << PAGE_SHIFT); > - unsigned long addr = start; > + unsigned long addr, len, end; > unsigned long next; > pgd_t *pgdp; > int nr = 0; > > + start &= PAGE_MASK; > + addr = start; > + len = (unsigned long) nr_pages << PAGE_SHIFT; > + end = start + len; > if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ, > - start, nr_pages*PAGE_SIZE))) > + start, len))) > goto slow_irqon; > > /* -- 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/