From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760356AbcIPJTt (ORCPT ); Fri, 16 Sep 2016 05:19:49 -0400 Received: from terminus.zytor.com ([198.137.202.10]:37192 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753910AbcIPJTl (ORCPT ); Fri, 16 Sep 2016 05:19:41 -0400 Date: Fri, 16 Sep 2016 02:18:38 -0700 From: tip-bot for Andy Lutomirski Message-ID: Cc: hpa@zytor.com, bp@alien8.de, brgerst@gmail.com, peterz@infradead.org, jann@thejh.net, dvlasenk@redhat.com, torvalds@linux-foundation.org, jpoimboe@redhat.com, luto@kernel.org, mingo@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org Reply-To: jann@thejh.net, peterz@infradead.org, brgerst@gmail.com, bp@alien8.de, hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@kernel.org, jpoimboe@redhat.com, luto@kernel.org, torvalds@linux-foundation.org, dvlasenk@redhat.com In-Reply-To: <0bfd8e6d4729c97745d3781a29610a33d0a8091d.1474003868.git.luto@kernel.org> References: <0bfd8e6d4729c97745d3781a29610a33d0a8091d.1474003868.git.luto@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/asm] lib/syscall: Pin the task stack in collect_syscall() Git-Commit-ID: aa1f1a639621672b68f654dc815a7d8298ff396f X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: aa1f1a639621672b68f654dc815a7d8298ff396f Gitweb: http://git.kernel.org/tip/aa1f1a639621672b68f654dc815a7d8298ff396f Author: Andy Lutomirski AuthorDate: Thu, 15 Sep 2016 22:45:47 -0700 Committer: Ingo Molnar CommitDate: Fri, 16 Sep 2016 09:18:53 +0200 lib/syscall: Pin the task stack in collect_syscall() This will avoid a potential read-after-free if collect_syscall() (e.g. /proc/PID/syscall) is called on an exiting task. Reported-by: Jann Horn Signed-off-by: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/0bfd8e6d4729c97745d3781a29610a33d0a8091d.1474003868.git.luto@kernel.org Signed-off-by: Ingo Molnar --- lib/syscall.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/syscall.c b/lib/syscall.c index e30e039..63239e0 100644 --- a/lib/syscall.c +++ b/lib/syscall.c @@ -7,9 +7,19 @@ static int collect_syscall(struct task_struct *target, long *callno, unsigned long args[6], unsigned int maxargs, unsigned long *sp, unsigned long *pc) { - struct pt_regs *regs = task_pt_regs(target); - if (unlikely(!regs)) + struct pt_regs *regs; + + if (!try_get_task_stack(target)) { + /* Task has no stack, so the task isn't in a syscall. */ + *callno = -1; + return 0; + } + + regs = task_pt_regs(target); + if (unlikely(!regs)) { + put_task_stack(target); return -EAGAIN; + } *sp = user_stack_pointer(regs); *pc = instruction_pointer(regs); @@ -18,6 +28,7 @@ static int collect_syscall(struct task_struct *target, long *callno, if (*callno != -1L && maxargs > 0) syscall_get_arguments(target, regs, 0, maxargs, args); + put_task_stack(target); return 0; }