From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753813AbdKIQmS convert rfc822-to-8bit (ORCPT ); Thu, 9 Nov 2017 11:42:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43366 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752873AbdKIQmQ (ORCPT ); Thu, 9 Nov 2017 11:42:16 -0500 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 From: David Howells To: rostedt@goodmis.org cc: dhowells@redhat.com, mingo@redhat.com, alexei.starovoitov@gmail.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC][PATCH] Lock down ftrace MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11099.1510245732.1@warthog.procyon.org.uk> Content-Transfer-Encoding: 8BIT Date: Thu, 09 Nov 2017 16:42:12 +0000 Message-ID: <11100.1510245732@warthog.procyon.org.uk> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 09 Nov 2017 16:42:16 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, I (may) need to lock down ftrace under secure boot conditions as part of the patch series that can be found here: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=efi-lock-down Can you tell me that if the attached patch is sufficient to the cause? Thanks, David --- commit 3fb4590c0ad0a751b2090c489df79193510e6aaa Author: David Howells Date: Wed Nov 8 15:41:02 2017 +0000 Lock down ftrace 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 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