From patchwork Thu Nov 9 17:33:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 10051515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 66058603FA for ; Thu, 9 Nov 2017 17:35:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EAE82B00E for ; Thu, 9 Nov 2017 17:35:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43A082B047; Thu, 9 Nov 2017 17:35:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECCF32B00E for ; Thu, 9 Nov 2017 17:35:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754798AbdKIReD (ORCPT ); Thu, 9 Nov 2017 12:34:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33138 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754692AbdKIRd6 (ORCPT ); Thu, 9 Nov 2017 12:33:58 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71D21A7E5; Thu, 9 Nov 2017 17:33:58 +0000 (UTC) Received: from warthog.procyon.org.uk.com (ovpn-121-14.rdu2.redhat.com [10.10.121.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 07E0360C80; Thu, 9 Nov 2017 17:33:56 +0000 (UTC) From: David Howells To: linux-security-module@vger.kernel.org Cc: gnomes@lxorguk.ukuu.org.uk, linux-efi@vger.kernel.org, dhowells@redhat.com, linux-kernel@vger.kernel.org, jforbes@redhat.com Subject: [PATCH 26/30] Lock down ftrace Date: Thu, 9 Nov 2017 17:33:56 +0000 Message-Id: <151024883613.28329.14808632296386937974.stgit@warthog.procyon.org.uk> Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 In-Reply-To: <151024863544.28329.2436580122759221600.stgit@warthog.procyon.org.uk> References: <151024863544.28329.2436580122759221600.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 09 Nov 2017 17:33:58 +0000 (UTC) Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Disallow the use of ftrace when the kernel is locked down. This patch turns off ftrace_enabled late in the kernel boot so that the selftest can still be potentially be run. The sysctl that controls ftrace_enables is also disallowed when the kernel is locked down. If the lockdown is lifted, then the sysctl can be used to reenable ftrace - if ftrace was compiled with CONFIG_DYNAMIC_FTRACE, that is; if it wasn't then it won't be possible to reenable it. This prevents crypto data theft by analysis of execution patterns, and, if in future ftrace also logs the register contents at the time, will prevent data theft by that mechanism also. Reported-by: Alexei Starovoitov Signed-off-by: David Howells --- kernel/trace/ftrace.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 6abfafd7f173..9c7135963d80 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -6508,6 +6508,9 @@ ftrace_enable_sysctl(struct ctl_table *table, int write, { int ret = -ENODEV; + if (kernel_is_locked_down("Use of ftrace")) + return -EPERM; + mutex_lock(&ftrace_lock); if (unlikely(ftrace_disabled)) @@ -6896,3 +6899,22 @@ void ftrace_graph_exit_task(struct task_struct *t) kfree(ret_stack); } #endif + +#ifdef CONFIG_LOCK_DOWN_KERNEL +static int __init ftrace_lock_down(void) +{ + mutex_lock(&ftrace_lock); + + if (!ftrace_disabled && ftrace_enabled && + kernel_is_locked_down("Use of ftrace")) { + ftrace_enabled = false; + last_ftrace_enabled = false; + ftrace_trace_function = ftrace_stub; + ftrace_shutdown_sysctl(); + } + + mutex_unlock(&ftrace_lock); + return 0; +} +late_initcall(ftrace_lock_down); +#endif