Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756754Ab0FBCkc (ORCPT ); Tue, 1 Jun 2010 22:40:32 -0400 Received: from serv2.oss.ntt.co.jp ([222.151.198.100]:46733 "EHLO serv2.oss.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755527Ab0FBCkb (ORCPT ); Tue, 1 Jun 2010 22:40:31 -0400 Date: Wed, 2 Jun 2010 11:40:57 +0900 From: Takuya Yoshikawa To: David Howells Cc: torvalds@osdl.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Mike Frysinger , Alexander Viro , Daisuke HATAYAMA , Paul Mundt Subject: Re: [PATCH] binfmt_elf_fdpic: Fix clear_user() error handling Message-Id: <20100602114057.03b40af1.yoshikawa.takuya@oss.ntt.co.jp> In-Reply-To: <20100601131047.5456.34014.stgit@warthog.procyon.org.uk> References: <20100601131047.5456.34014.stgit@warthog.procyon.org.uk> X-Mailer: Sylpheed 3.0.2 (GTK+ 2.20.1; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3640 Lines: 113 David Howells wrote: > From: Takuya Yoshikawa > Thanks for updating, improving, the explanation! Takuya > clear_user() returns the number of bytes that could not be copied rather than > an error code. So we should return -EFAULT rather than directly returning the > results. > > Without this patch, positive values may be returned to elf_fdpic_map_file() > and the following error handlings do not function as expected. > > 1. > ret = elf_fdpic_map_file_constdisp_on_uclinux(params, file, mm); > if (ret < 0) > return ret; > 2. > ret = elf_fdpic_map_file_by_direct_mmap(params, file, mm); > if (ret < 0) > return ret; > > Signed-off-by: Takuya Yoshikawa > Signed-off-by: David Howells > Acked-by: Mike Frysinger > CC: Alexander Viro > CC: Andrew Morton > CC: Daisuke HATAYAMA > CC: Paul Mundt > --- > > fs/binfmt_elf_fdpic.c | 26 +++++++++++--------------- > 1 files changed, 11 insertions(+), 15 deletions(-) > > > diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c > index 2c5f9a0..63039ed 100644 > --- a/fs/binfmt_elf_fdpic.c > +++ b/fs/binfmt_elf_fdpic.c > @@ -990,10 +990,9 @@ static int elf_fdpic_map_file_constdisp_on_uclinux( > > /* clear any space allocated but not loaded */ > if (phdr->p_filesz < phdr->p_memsz) { > - ret = clear_user((void *) (seg->addr + phdr->p_filesz), > - phdr->p_memsz - phdr->p_filesz); > - if (ret) > - return ret; > + if (clear_user((void *) (seg->addr + phdr->p_filesz), > + phdr->p_memsz - phdr->p_filesz)) > + return -EFAULT; > } > > if (mm) { > @@ -1027,7 +1026,7 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, > struct elf32_fdpic_loadseg *seg; > struct elf32_phdr *phdr; > unsigned long load_addr, delta_vaddr; > - int loop, dvset, ret; > + int loop, dvset; > > load_addr = params->load_addr; > delta_vaddr = 0; > @@ -1127,9 +1126,8 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, > * PT_LOAD */ > if (prot & PROT_WRITE && disp > 0) { > kdebug("clear[%d] ad=%lx sz=%lx", loop, maddr, disp); > - ret = clear_user((void __user *) maddr, disp); > - if (ret) > - return ret; > + if (clear_user((void __user *) maddr, disp)) > + return -EFAULT; > maddr += disp; > } > > @@ -1164,19 +1162,17 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, > if (prot & PROT_WRITE && excess1 > 0) { > kdebug("clear[%d] ad=%lx sz=%lx", > loop, maddr + phdr->p_filesz, excess1); > - ret = clear_user((void __user *) maddr + phdr->p_filesz, > - excess1); > - if (ret) > - return ret; > + if (clear_user((void __user *) maddr + phdr->p_filesz, > + excess1)) > + return -EFAULT; > } > > #else > if (excess > 0) { > kdebug("clear[%d] ad=%lx sz=%lx", > loop, maddr + phdr->p_filesz, excess); > - ret = clear_user((void *) maddr + phdr->p_filesz, excess); > - if (ret) > - return ret; > + if (clear_user((void *) maddr + phdr->p_filesz, excess)) > + return -EFAULT; > } > #endif > > -- Takuya Yoshikawa -- 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/