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

From: WANG Cong
Date: Thu May 08 2008 - 09:57:51 EST


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@xxxxxxxxx>
Cc: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx>

---
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);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/