From: Al Viro <v...@zeniv.linux.org.uk>

... and check the return value

Signed-off-by: Al Viro <v...@zeniv.linux.org.uk>
---
 fs/binfmt_flat.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index 831a2b25ba79..7b663ed5247b 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -138,35 +138,40 @@ static int create_flat_tables(struct linux_binprm *bprm, 
unsigned long arg_start
        current->mm->start_stack = (unsigned long)sp & -FLAT_STACK_ALIGN;
        sp = (unsigned long __user *)current->mm->start_stack;
 
-       __put_user(bprm->argc, sp++);
+       if (put_user(bprm->argc, sp++))
+               return -EFAULT;
        if (IS_ENABLED(CONFIG_BINFMT_FLAT_ARGVP_ENVP_ON_STACK)) {
                unsigned long argv, envp;
                argv = (unsigned long)(sp + 2);
                envp = (unsigned long)(sp + 2 + bprm->argc + 1);
-               __put_user(argv, sp++);
-               __put_user(envp, sp++);
+               if (put_user(argv, sp++) || put_user(envp, sp++))
+                       return -EFAULT;
        }
 
        current->mm->arg_start = (unsigned long)p;
        for (i = bprm->argc; i > 0; i--) {
-               __put_user((unsigned long)p, sp++);
+               if (put_user((unsigned long)p, sp++))
+                       return -EFAULT;
                len = strnlen_user(p, MAX_ARG_STRLEN);
                if (!len || len > MAX_ARG_STRLEN)
                        return -EINVAL;
                p += len;
        }
-       __put_user(0, sp++);
+       if (put_user(0, sp++))
+               return -EFAULT;
        current->mm->arg_end = (unsigned long)p;
 
        current->mm->env_start = (unsigned long) p;
        for (i = bprm->envc; i > 0; i--) {
-               __put_user((unsigned long)p, sp++);
+               if (put_user((unsigned long)p, sp++))
+                       return -EFAULT;
                len = strnlen_user(p, MAX_ARG_STRLEN);
                if (!len || len > MAX_ARG_STRLEN)
                        return -EINVAL;
                p += len;
        }
-       __put_user(0, sp++);
+       if (put_user(0, sp++))
+               return -EFAULT;
        current->mm->env_end = (unsigned long)p;
 
        return 0;
@@ -998,7 +1003,8 @@ static int load_flat_binary(struct linux_binprm *bprm)
                        unsigned long __user *sp;
                        current->mm->start_stack -= sizeof(unsigned long);
                        sp = (unsigned long __user *)current->mm->start_stack;
-                       __put_user(start_addr, sp);
+                       if (put_user(start_addr, sp))
+                               return -EFAULT;
                        start_addr = libinfo.lib_list[i].entry;
                }
        }
-- 
2.11.0

Reply via email to