Skip to contentSkip to conversation

tracing: Fix crash on lseek of recursed_functions file in WRONLY mode

PATCH New Steven Rostedt 1 participant 1 message Nov 25 Tracing

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 tracing: Fix crash on lseek of recursed_functions file in WRONLY mode

From: Steven Rostedt <[email protected]>

The lseek method for the "recursed_functions" file only handles seq_lseek() which is for when the file is opened for reading. If the file is opened for WRONLY, it will cause a NULL pointer dereferenced:

Oops: general protection fault, probably for non-canonical address 0xdffffc0000000012: 0000 [#1] SMP KASAN PTI
 KASAN: null-ptr-deref in range [0x0000000000000090-0x0000000000000097]
 CPU: 5 UID: 0 PID: 1100 Comm: lseek Not tainted 7.4.0-rc4-test-00006-g4dca8a8ee893 #36 PREEMPT(lazy)
 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.17.0-debian-1.17.0-1 04/01/2014
 RIP: 0010:__mutex_lock+0x162/0x2550
 Code: 08 84 d2 0f 85 a1 1c 00 00 44 8b 0d 38 cb df 03 45 85 c9 75 29 48 b8 00 00 00 00 00 fc ff df 48 8d 7b 58 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 a6 1c 00 00 48 3b 5b 58 0f 85 3f 0e 00 00 bf 01
 RSP: 0018:ffff8881211afd10 EFLAGS: 00010206
 RAX: dffffc0000000000 RBX: 0000000000000038 RCX: 8000000000000000
 RDX: 0000000000000012 RSI: ffffffff8588bdfb RDI: 0000000000000090
 RBP: ffff8881211afe70 R08: 0000000000000001 R09: 0000000000000000
 R10: ffff8881083f8000 R11: ffffed10247ebc54 R12: 0000000000000000
 R13: 0000000000000000 R14: dffffc0000000000 R15: 1ffff11024235fac
 FS:  00007fb27d236780(0000) GS:ffff8882b4581000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: 000055fb6eb6e008 CR3: 000000011d26e006 CR4: 0000000000172ef0
 Call Trace:
  <TASK>
  ? seq_lseek+0x60/0x3d0
  ? kmem_cache_free+0x14b/0x610
  ? __pfx___mutex_lock+0x10/0x10
  ? do_sys_openat2+0xd8/0x180
  ? seq_lseek+0x60/0x3d0
  seq_lseek+0x60/0x3d0
  ? __pfx___x64_sys_openat+0x10/0x10
  ksys_lseek+0x3c/0xb0
  do_syscall_64+0xcd/0x6f0
  entry_SYSCALL_64_after_hwframe+0x76/0x7e
 RIP: 0033:0x7fb27d33fa17
 Code: 8b 05 fd 03 0e 00 64 c7 00 0d 00 00 00 eb b2 e8 ef 98 01 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 b8 08 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 01 c3 48 8b 15 c9 03 0e 00 f7 d8 64 89 02 48
 RSP: 002b:00007ffd486d0258 EFLAGS: 00000202 ORIG_RAX: 0000000000000008
 RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fb27d33fa17
 RDX: 0000000000000002 RSI: 0000000000000000 RDI: 0000000000000003
 RBP: 00007ffd486d0280 R08: 0000000000000000 R09: 0000000000000000
 R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000002
 R13: 00007fb27d482000 R14: 00007ffd486d03b0 R15: 000055fb6eb6cdd8
  </TASK>
 Modules linked in:
 ---[ end trace 0000000000000000 ]---

A helper function "tracing_lseek()" already exists for this use case. Have the file_operations for the recursed_functions file use that.

---
 kernel/trace/trace_recursion_record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_recursion_record.c +1 -1
index 4f63bec052fc..0452c9c4c558 100644
@@ -217,7 +217,7 @@ static const struct file_operations recursed_functions_fops = {
 	.open           = recursed_function_open,
 	.write		= recursed_function_write,
 	.read           = seq_read,
-	.llseek         = seq_lseek,
+	.llseek         = tracing_lseek,
 	.release        = recursed_function_release,
 };
 
Signature · 1 line
2.53.0