From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S946648AbcKAHPb (ORCPT ); Tue, 1 Nov 2016 03:15:31 -0400 Received: from terminus.zytor.com ([198.137.202.10]:45692 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S945502AbcKAHP3 (ORCPT ); Tue, 1 Nov 2016 03:15:29 -0400 Date: Tue, 1 Nov 2016 00:12:50 -0700 From: tip-bot for Andy Lutomirski Message-ID: Cc: brgerst@gmail.com, peterz@infradead.org, torvalds@linux-foundation.org, luto@kernel.org, bp@alien8.de, linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org, jpoimboe@redhat.com, tglx@linutronix.de, dvlasenk@redhat.com, oleg@redhat.com Reply-To: mingo@kernel.org, jpoimboe@redhat.com, hpa@zytor.com, dvlasenk@redhat.com, oleg@redhat.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, bp@alien8.de, luto@kernel.org, brgerst@gmail.com, peterz@infradead.org In-Reply-To: References: To: linux-tip-commits@vger.kernel.org Subject: [tip:core/urgent] fork: Add task stack refcounting sanity check and prevent premature task stack freeing Git-Commit-ID: 405c0759712f57b680f66aee9c55cd06ad1cbdef 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: 405c0759712f57b680f66aee9c55cd06ad1cbdef Gitweb: http://git.kernel.org/tip/405c0759712f57b680f66aee9c55cd06ad1cbdef Author: Andy Lutomirski AuthorDate: Mon, 31 Oct 2016 08:11:43 -0700 Committer: Ingo Molnar CommitDate: Tue, 1 Nov 2016 07:39:17 +0100 fork: Add task stack refcounting sanity check and prevent premature task stack freeing If something goes wrong with task stack refcounting and a stack refcount hits zero too early, warn and leak it rather than potentially freeing it early (and silently). 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: Oleg Nesterov Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/f29119c783a9680a4b4656e751b6123917ace94b.1477926663.git.luto@kernel.org Signed-off-by: Ingo Molnar --- kernel/fork.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/fork.c b/kernel/fork.c index 623259f..997ac1d 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -315,6 +315,9 @@ static void account_kernel_stack(struct task_struct *tsk, int account) static void release_task_stack(struct task_struct *tsk) { + if (WARN_ON(tsk->state != TASK_DEAD)) + return; /* Better to leak the stack than to free prematurely */ + account_kernel_stack(tsk, -1); arch_release_thread_stack(tsk->stack); free_thread_stack(tsk); @@ -1862,6 +1865,7 @@ bad_fork_cleanup_count: atomic_dec(&p->cred->user->processes); exit_creds(p); bad_fork_free: + p->state = TASK_DEAD; put_task_stack(p); free_task(p); fork_out: