From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751914AbcF0Nyy (ORCPT ); Mon, 27 Jun 2016 09:54:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:48274 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751745AbcF0Nyw (ORCPT ); Mon, 27 Jun 2016 09:54:52 -0400 From: Petr Mladek To: Steven Rostedt , Ingo Molnar Cc: Frederic Weisbecker , Masami Hiramatsu , Jiri Kosina , linux-kernel@vger.kernel.org, x86@kernel.org, Petr Mladek Subject: [PATCH 2/4] ftrace/x86: Do not crash when reading wrong ftrace func Date: Mon, 27 Jun 2016 15:54:35 +0200 Message-Id: <1467035677-12193-3-git-send-email-pmladek@suse.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1467035677-12193-1-git-send-email-pmladek@suse.com> References: <1467035677-12193-1-git-send-email-pmladek@suse.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ftrace modifies the code on many locations. It is paranoid and avoid a kernel crash using probe_kernel_read() and probe_kernel_write(). The only exception is update_ftrace_func() where where we read the old code using memcpy(). It is true that this function is used only to modify well defined functions that are part of the ftrace API. But it might still make sense to be paranoid and be consistent with the writing side. Signed-off-by: Petr Mladek --- arch/x86/kernel/ftrace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 42ea69d35dfd..8305c6792ad2 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -233,7 +233,8 @@ static int update_ftrace_func(unsigned long ip, void *new) unsigned char old[MCOUNT_INSN_SIZE]; int ret; - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE); + if (probe_kernel_read(old, (void *)ip, MCOUNT_INSN_SIZE)) + return -EFAULT; /* * Make sure that we replace 5-byte instruction that -- 1.8.5.6