Skip to content

Commit 8861fd5

Browse files
author
Al Viro
committed
binfmt_flat: don't use __put_user()
... and check the return value Signed-off-by: Al Viro <[email protected]>
1 parent 0abb013 commit 8861fd5

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

fs/binfmt_flat.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,35 +138,40 @@ static int create_flat_tables(struct linux_binprm *bprm, unsigned long arg_start
138138
current->mm->start_stack = (unsigned long)sp & -FLAT_STACK_ALIGN;
139139
sp = (unsigned long __user *)current->mm->start_stack;
140140

141-
__put_user(bprm->argc, sp++);
141+
if (put_user(bprm->argc, sp++))
142+
return -EFAULT;
142143
if (IS_ENABLED(CONFIG_BINFMT_FLAT_ARGVP_ENVP_ON_STACK)) {
143144
unsigned long argv, envp;
144145
argv = (unsigned long)(sp + 2);
145146
envp = (unsigned long)(sp + 2 + bprm->argc + 1);
146-
__put_user(argv, sp++);
147-
__put_user(envp, sp++);
147+
if (put_user(argv, sp++) || put_user(envp, sp++))
148+
return -EFAULT;
148149
}
149150

150151
current->mm->arg_start = (unsigned long)p;
151152
for (i = bprm->argc; i > 0; i--) {
152-
__put_user((unsigned long)p, sp++);
153+
if (put_user((unsigned long)p, sp++))
154+
return -EFAULT;
153155
len = strnlen_user(p, MAX_ARG_STRLEN);
154156
if (!len || len > MAX_ARG_STRLEN)
155157
return -EINVAL;
156158
p += len;
157159
}
158-
__put_user(0, sp++);
160+
if (put_user(0, sp++))
161+
return -EFAULT;
159162
current->mm->arg_end = (unsigned long)p;
160163

161164
current->mm->env_start = (unsigned long) p;
162165
for (i = bprm->envc; i > 0; i--) {
163-
__put_user((unsigned long)p, sp++);
166+
if (put_user((unsigned long)p, sp++))
167+
return -EFAULT;
164168
len = strnlen_user(p, MAX_ARG_STRLEN);
165169
if (!len || len > MAX_ARG_STRLEN)
166170
return -EINVAL;
167171
p += len;
168172
}
169-
__put_user(0, sp++);
173+
if (put_user(0, sp++))
174+
return -EFAULT;
170175
current->mm->env_end = (unsigned long)p;
171176

172177
return 0;
@@ -998,7 +1003,8 @@ static int load_flat_binary(struct linux_binprm *bprm)
9981003
unsigned long __user *sp;
9991004
current->mm->start_stack -= sizeof(unsigned long);
10001005
sp = (unsigned long __user *)current->mm->start_stack;
1001-
__put_user(start_addr, sp);
1006+
if (put_user(start_addr, sp))
1007+
return -EFAULT;
10021008
start_addr = libinfo.lib_list[i].entry;
10031009
}
10041010
}

0 commit comments

Comments
 (0)