Skip to content

Commit

Permalink
mm: Adjust do_pages_stat() so gcc can see copy_from_user() is safe
Browse files Browse the repository at this point in the history
Slightly adjust the logic for determining the size of the
copy_form_user() in do_pages_stat(); with this change, gcc can see
that the copying is safe.

Without this, we get a build error for i386 allyesconfig:

/home/hpa/kernel/linux-2.6-tip.urgent/arch/x86/include/asm/uaccess_32.h:213:
error: call to ‘copy_from_user_overflow’ declared with attribute
error: copy_from_user() buffer size is not provably correct

Unlike an earlier patch from Arjan, this doesn't introduce new
variables; merely reshuffles the compare so that gcc can see that an
overflow cannot happen.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Brice Goglin <Brice.Goglin@inria.fr>
Cc: Arjan van de Ven <arjan@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
LKML-Reference: <20090926205406.30d55b08@infradead.org>
  • Loading branch information
H. Peter Anvin committed Dec 11, 2009
1 parent 2eaad1f commit b925585
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mm/migrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,
int err;

for (i = 0; i < nr_pages; i += chunk_nr) {
if (chunk_nr + i > nr_pages)
if (chunk_nr > nr_pages - i)
chunk_nr = nr_pages - i;

err = copy_from_user(chunk_pages, &pages[i],
Expand Down

0 comments on commit b925585

Please sign in to comment.