Skip to content

Commit 2c87e2c

Browse files
Andi KleenLinus Torvalds
authored andcommitted
[PATCH] x86_64: Fix access check in ptrace compat
We can't safely directly access an compat_alloc_user_space() pointer with the siginfo copy functions. Bounce it through the stack. Noticed by Al Viro using sparse [ This was only added post 2.6.17, not in any released kernel ] Cc: Al Viro <viro@ftp.linux.org.uk> Signed-off-by: Andi Kleen <ak@suse.de> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 1cfcea1 commit 2c87e2c

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎arch/x86_64/ia32/ptrace32.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,24 @@ static long ptrace32_siginfo(unsigned request, u32 pid, u32 addr, u32 data)
202202
{
203203
int ret;
204204
compat_siginfo_t *si32 = (compat_siginfo_t *)compat_ptr(data);
205+
siginfo_t ssi;
205206
siginfo_t *si = compat_alloc_user_space(sizeof(siginfo_t));
206207
if (request == PTRACE_SETSIGINFO) {
207-
ret = copy_siginfo_from_user32(si, si32);
208+
memset(&ssi, 0, sizeof(siginfo_t));
209+
ret = copy_siginfo_from_user32(&ssi, si32);
208210
if (ret)
209211
return ret;
212+
if (copy_to_user(si, &ssi, sizeof(siginfo_t)))
213+
return -EFAULT;
210214
}
211215
ret = sys_ptrace(request, pid, addr, (unsigned long)si);
212216
if (ret)
213217
return ret;
214-
if (request == PTRACE_GETSIGINFO)
215-
ret = copy_siginfo_to_user32(si32, si);
218+
if (request == PTRACE_GETSIGINFO) {
219+
if (copy_from_user(&ssi, si, sizeof(siginfo_t)))
220+
return -EFAULT;
221+
ret = copy_siginfo_to_user32(si32, &ssi);
222+
}
216223
return ret;
217224
}
218225

0 commit comments

Comments
 (0)