[Patch 7/9] fs/exec.c: fix wrong return value of prepare_binprm()

WANG Cong
2008-05-08T13:57:49Z

All prepare_binprm()'s callers assume that prepare_binprm() fails
when it returns negative. However, prepare_binprm() most probably returns
the return value of kernel_read(), which may return positive on failure!

Thus this should be fixed.

Signed-off-by: WANG Cong <wangcong@zeuux.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>

---
diff --git a/fs/exec.c b/fs/exec.c
index aeaa979..0237541 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1063,7 +1063,11 @@ int prepare_binprm(struct linux_binprm *bprm)
return retval;

memset(bprm->buf,0,BINPRM_BUF_SIZE);
- return kernel_read(bprm->file,0,bprm->buf,BINPRM_BUF_SIZE);
+ retval = kernel_read(bprm->file, 0, bprm->buf, BINPRM_BUF_SIZE);
+ if (retval < 0)
+ return retval;
+ if (retval != BINPRM_BUF_SIZE && retval != inode->i_size)
+ return -EIO;
+ return 0;
}

EXPORT_SYMBOL(prepare_binprm);