Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1573097

[for-next][PATCH 4/8] ftrace: Reset fgd->hash in ftrace_graph_write()

From Steven Rostedt <rostedt@goodmis.org>
Newsgroups linux.kernel
Subject [for-next][PATCH 4/8] ftrace: Reset fgd->hash in ftrace_graph_write()
Date 2017-02-03 14:50 +0100
Message-ID <t6Mps-2cV-27@gated-at.bofh.it> (permalink)
References <t6Mpr-2cV-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

fgd->hash is saved and then freed, but is never reset to either
ftrace_graph_hash nor ftrace_graph_notrace_hash. But if multiple reads are
performed, then the freed hash could be accessed again.

 # cd /sys/kernel/debug/tracing
 # head -1000 available_filter_functions > /tmp/funcs
 # cat /tmp/funcs > set_graph_function

Causes:

 general protection fault: 0000 [#1] SMP DEBUG_PAGEALLOC
 Modules linked in:  [...]
 CPU: 2 PID: 1337 Comm: cat Not tainted 4.10.0-rc2-test-00010-g6b052e9 #32
 Hardware name: Hewlett-Packard HP Compaq Pro 6300 SFF/339A, BIOS K01 v02.05 05/07/2012
 task: ffff880113a12200 task.stack: ffffc90001940000
 RIP: 0010:free_ftrace_hash+0x7c/0x160
 RSP: 0018:ffffc90001943db0 EFLAGS: 00010246
 RAX: 6b6b6b6b6b6b6b6b RBX: 6b6b6b6b6b6b6b6b RCX: 6b6b6b6b6b6b6b6b
 RDX: 0000000000000002 RSI: 0000000000000001 RDI: ffff8800ce1e1d40
 RBP: ffff8800ce1e1d50 R08: 0000000000000000 R09: 0000000000006400
 R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
 R13: ffff8800ce1e1d40 R14: 0000000000004000 R15: 0000000000000001
 FS:  00007f9408a07740(0000) GS:ffff88011e500000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: 0000000000aee1f0 CR3: 0000000116bb4000 CR4: 00000000001406e0
 Call Trace:
  ? ftrace_graph_write+0x150/0x190
  ? __vfs_write+0x1f6/0x210
  ? __audit_syscall_entry+0x17f/0x200
  ? rw_verify_area+0xdb/0x210
  ? _cond_resched+0x2b/0x50
  ? __sb_start_write+0xb4/0x130
  ? vfs_write+0x1c8/0x330
  ? SyS_write+0x62/0xf0
  ? do_syscall_64+0xa3/0x1b0
  ? entry_SYSCALL64_slow_path+0x25/0x25
 Code: 01 48 85 db 0f 84 92 00 00 00 b8 01 00 00 00 d3 e0 85 c0 7e 3f 83 e8 01 48 8d 6f 10 45 31 e4 4c 8d 34 c5 08 00 00 00 49 8b 45 08 <4a> 8b 34 20 48 85 f6 74 13 48 8b 1e 48 89 ef e8 20 fa ff ff 48
 RIP: free_ftrace_hash+0x7c/0x160 RSP: ffffc90001943db0
 ---[ end trace 999b48216bf4b393 ]---

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/ftrace.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index a9cfc8713198..b7df0dcf8652 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -4858,10 +4858,13 @@ ftrace_graph_write(struct file *file, const char __user *ubuf,
 		if (!new_hash)
 			ret = -ENOMEM;
 
-		if (fgd->type == GRAPH_FILTER_FUNCTION)
+		if (fgd->type == GRAPH_FILTER_FUNCTION) {
 			rcu_assign_pointer(ftrace_graph_hash, new_hash);
-		else
+			fgd->hash = ftrace_graph_hash;
+		} else {
 			rcu_assign_pointer(ftrace_graph_notrace_hash, new_hash);
+			fgd->hash = ftrace_graph_notrace_hash;
+		}
 
 		mutex_unlock(&graph_lock);
 
-- 
2.10.2

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[for-next][PATCH 0/8] tracing: Clean up hash logic for set_graph_function Steven Rostedt <rostedt@goodmis.org> - 2017-02-03 14:50 +0100
  [for-next][PATCH 1/8] tracing: Add ftrace_hash_key() helper function Steven Rostedt <rostedt@goodmis.org> - 2017-02-03 14:50 +0100
  [for-next][PATCH 3/8] ftrace: Replace (void *)1 with a meaningful macro name  FTRACE_GRAPH_EMPTY Steven Rostedt <rostedt@goodmis.org> - 2017-02-03 14:50 +0100
  [for-next][PATCH 7/8] ftrace: Do not hold references of ftrace_graph_{notrace_}hash out of  graph_lock Steven Rostedt <rostedt@goodmis.org> - 2017-02-03 14:50 +0100
  [for-next][PATCH 8/8] ftrace: Have set_graph_function handle multiple functions in one  write Steven Rostedt <rostedt@goodmis.org> - 2017-02-03 14:50 +0100
  [for-next][PATCH 4/8] ftrace: Reset fgd->hash in ftrace_graph_write() Steven Rostedt <rostedt@goodmis.org> - 2017-02-03 14:50 +0100
    Re: [for-next][PATCH 4/8] ftrace: Reset fgd->hash in ftrace_graph_write() Namhyung Kim <namhyung@kernel.org> - 2017-02-03 16:00 +0100
      Re: [for-next][PATCH 4/8] ftrace: Reset fgd->hash in  ftrace_graph_write() Steven Rostedt <rostedt@goodmis.org> - 2017-02-03 16:00 +0100
  [for-next][PATCH 2/8] ftrace: Create a slight optimization on searching the ftrace_hash Steven Rostedt <rostedt@goodmis.org> - 2017-02-03 14:50 +0100
    Re: [for-next][PATCH 2/8] ftrace: Create a slight optimization on  searching the ftrace_hash Namhyung Kim <namhyung@kernel.org> - 2017-02-03 15:30 +0100
      Re: [for-next][PATCH 2/8] ftrace: Create a slight optimization on  searching the ftrace_hash Steven Rostedt <rostedt@goodmis.org> - 2017-02-03 16:00 +0100
  [for-next][PATCH 6/8] tracing: Reset parser->buffer to allow multiple "puts" Steven Rostedt <rostedt@goodmis.org> - 2017-02-03 14:50 +0100
  [for-next][PATCH 5/8] ftrace: Have set_graph_functions handle write with RDWR Steven Rostedt <rostedt@goodmis.org> - 2017-02-03 14:50 +0100
  Re: [for-next][PATCH 0/8] tracing: Clean up hash logic for set_graph_function Namhyung Kim <namhyung@kernel.org> - 2017-02-03 16:20 +0100

csiph-web