[PATCH v2 4/4] [RFC] arm/trampfd: Provide support for the trampoline file descriptor

2020-09-16 Thread madvenka
From: "Madhavan T. Venkataraman" - Define architecture specific register names - Architecture specific functions for: - system call init - code descriptor check - data descriptor check - Fill a page with a trampoline table,

[PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-16 Thread madvenka
el was required to execute the trampoline. In version 2, that is not required. So, there are no performance concerns in this approach. libffi == I have implemented my solution for libffi and provided the changes for X86 and ARM, 32-bit and 64-bit. Here is the reference patch: http://linux.mic

[PATCH v2 2/4] [RFC] x86/trampfd: Provide support for the trampoline file descriptor

2020-09-16 Thread madvenka
From: "Madhavan T. Venkataraman" - Define architecture specific register names - Architecture specific functions for: - system call init - code descriptor check - data descriptor check - Fill a page with a trampoline table

[PATCH v2 3/4] [RFC] arm64/trampfd: Provide support for the trampoline file descriptor

2020-09-16 Thread madvenka
From: "Madhavan T. Venkataraman" - Define architecture specific register names - Architecture specific functions for: - system call init - code descriptor check - data descriptor check - Fill a page with a trampoline table

[PATCH v2 1/4] [RFC] fs/trampfd: Implement the trampoline file descriptor API

2020-09-16 Thread madvenka
From: "Madhavan T. Venkataraman" Introduction Dynamic code is used in many different user applications. Dynamic code is often generated at runtime. Dynamic code can also just be a pre-defined sequence of machine instructions in a data buffer. Examples of dynamic code are

[PATCH v2 0/4] [RFC] Implement Trampoline File Descriptor

2020-09-22 Thread madvenka
el was required to execute the trampoline. In version 2, that is not required. So, there are no performance concerns in this approach. libffi == I have implemented my solution for libffi and provided the changes for X86 and ARM, 32-bit and 64-bit. Here is the reference patch: http://linux.mic

[PATCH v2 3/4] [RFC] arm64/trampfd: Provide support for the trampoline file descriptor

2020-09-22 Thread madvenka
From: "Madhavan T. Venkataraman" - Define architecture specific register names - Architecture specific functions for: - system call init - code descriptor check - data descriptor check - Fill a page with a trampoline table

[PATCH v2 1/4] [RFC] fs/trampfd: Implement the trampoline file descriptor API

2020-09-22 Thread madvenka
From: "Madhavan T. Venkataraman" Introduction Dynamic code is used in many different user applications. Dynamic code is often generated at runtime. Dynamic code can also just be a pre-defined sequence of machine instructions in a data buffer. Examples of dynamic code are

[PATCH v2 4/4] [RFC] arm/trampfd: Provide support for the trampoline file descriptor

2020-09-22 Thread madvenka
From: "Madhavan T. Venkataraman" - Define architecture specific register names - Architecture specific functions for: - system call init - code descriptor check - data descriptor check - Fill a page with a trampoline table,

[PATCH v2 2/4] [RFC] x86/trampfd: Provide support for the trampoline file descriptor

2020-09-22 Thread madvenka
From: "Madhavan T. Venkataraman" - Define architecture specific register names - Architecture specific functions for: - system call init - code descriptor check - data descriptor check - Fill a page with a trampoline table

[PATCH v1 0/4] [RFC] Implement Trampoline File Descriptor

2020-07-28 Thread madvenka
- Trampolines can be shared across processes which can give rise to interesting uses in the future. - Trampfd can be used for other purposes to extend the kernel's functionality. libffi -- I have implemented my solution for libffi and provided the changes for X86 and ARM, 32-bit and 64-bit.

[PATCH v1 3/4] [RFC] arm64/trampfd: Provide support for the trampoline file descriptor

2020-07-28 Thread madvenka
From: "Madhavan T. Venkataraman" Implement 64-bit ARM support for the trampoline file descriptor. - Define architecture specific register names - Handle the trampoline invocation page fault - Setup the user register context on trampoline invocation - Setup the

[PATCH v1 4/4] [RFC] arm/trampfd: Provide support for the trampoline file descriptor

2020-07-28 Thread madvenka
From: "Madhavan T. Venkataraman" Implement 32-bit ARM support for the trampoline file descriptor. - Define architecture specific register names - Handle the trampoline invocation page fault - Setup the user register context on trampoline invocation - Setup the

[PATCH v1 1/4] [RFC] fs/trampfd: Implement the trampoline file descriptor API

2020-07-28 Thread madvenka
From: "Madhavan T. Venkataraman" There are many applications that use trampoline code. Trampoline code is usually placed in a data page or a stack page. In order to execute a trampoline, the page that contains the trampoline needs to have execute permissions. Writable pages with execute

[PATCH v1 2/4] [RFC] x86/trampfd: Provide support for the trampoline file descriptor

2020-07-28 Thread madvenka
From: "Madhavan T. Venkataraman" Implement 32-bit and 64-bit X86 support for the trampoline file descriptor. - Define architecture specific register names - Handle the trampoline invocation page fault - Setup the user register context on trampoline invocation -

[RFC PATCH v1 0/1] arm64: Implement stack trace termination record

2021-03-24 Thread madvenka
From: "Madhavan T. Venkataraman" The unwinder needs to be able to reliably tell when it has reached the end of a stack trace. One way to do this is to have the last stack frame at a fixed offset from the base of the task stack. When the unwinder reaches that offset, it knows it is done. All

[RFC PATCH v1 1/1] arm64: Implement stack trace termination record

2021-03-24 Thread madvenka
From: "Madhavan T. Venkataraman" The unwinder needs to be able to reliably tell when it has reached the end of a stack trace. One way to do this is to have the last stack frame at a fixed offset from the base of the task stack. When the unwinder reaches that offset, it knows it is done. Kernel

[RFC PATCH v2 0/1] arm64: Implement stack trace termination record

2021-04-01 Thread madvenka
From: "Madhavan T. Venkataraman" Reliable stacktracing requires that we identify when a stacktrace is terminated early. We can do this by ensuring all tasks have a final frame record at a known location on their task stack, and checking that this is the final frame record in the chain. All

[RFC PATCH v2 1/1] arm64: Implement stack trace termination record

2021-04-01 Thread madvenka
From: "Madhavan T. Venkataraman" Reliable stacktracing requires that we identify when a stacktrace is terminated early. We can do this by ensuring all tasks have a final frame record at a known location on their task stack, and checking that this is the final frame record in the chain. Kernel

[RFC PATCH v2 0/4] arm64: Implement stack trace reliability checks

2021-04-05 Thread madvenka
From: "Madhavan T. Venkataraman" There are a number of places in kernel code where the stack trace is not reliable. Enhance the unwinder to check for those cases and mark the stack trace as unreliable. Once all of the checks are in place, the unwinder can provide a reliable stack trace. But

[RFC PATCH v2 1/4] arm64: Implement infrastructure for stack trace reliability checks

2021-04-05 Thread madvenka
From: "Madhavan T. Venkataraman" Implement a check_reliability() function that will contain checks for the presence of various features and conditions that can render the stack trace unreliable. Introduce the first reliability check - If a return PC encountered in a stack trace is not a valid

[RFC PATCH v2 2/4] arm64: Mark a stack trace unreliable if an EL1 exception frame is detected

2021-04-05 Thread madvenka
From: "Madhavan T. Venkataraman" EL1 exceptions can happen on any instruction including instructions in the frame pointer prolog or epilog. Depending on where exactly they happen, they could render the stack trace unreliable. If an EL1 exception frame is found on the stack, mark the stack trace

[RFC PATCH v2 4/4] arm64: Mark stack trace as unreliable if kretprobed functions are present

2021-04-05 Thread madvenka
From: "Madhavan T. Venkataraman" When a kretprobe is active for a function, the function's return address in its stack frame is modified to point to the kretprobe trampoline. When the function returns, the frame is popped and control is transferred to the trampoline. The trampoline eventually

[RFC PATCH v2 3/4] arm64: Detect FTRACE cases that make the stack trace unreliable

2021-04-05 Thread madvenka
From: "Madhavan T. Venkataraman" When CONFIG_DYNAMIC_FTRACE_WITH_REGS is enabled and tracing is activated for a function, the ftrace infrastructure is called for the function at the very beginning. Ftrace creates two frames: - One for the traced function - One for the caller of

[RFC PATCH v1 0/4] arm64: Implement stack trace reliability checks

2021-03-30 Thread madvenka
From: "Madhavan T. Venkataraman" There are a number of places in kernel code where the stack trace is not reliable. Enhance the unwinder to check for those cases and mark the stack trace as unreliable. Once all of the checks are in place, the unwinder can be used for livepatching. Except for

[RFC PATCH v1 3/4] arm64: Detect FTRACE cases that make the stack trace unreliable

2021-03-30 Thread madvenka
From: "Madhavan T. Venkataraman" When CONFIG_DYNAMIC_FTRACE_WITH_REGS is enabled and tracing is activated for a function, the ftrace infrastructure is called for the function at the very beginning. Ftrace creates two frames: - One for the traced function - One for the caller of

[RFC PATCH v1 2/4] arm64: Mark a stack trace unreliable if an EL1 exception frame is detected

2021-03-30 Thread madvenka
From: "Madhavan T. Venkataraman" EL1 exceptions can happen on any instruction including instructions in the frame pointer prolog or epilog. Depending on where exactly they happen, they could render the stack trace unreliable. If an EL1 exception frame is found on the stack, mark the stack trace

[RFC PATCH v1 4/4] arm64: Mark stack trace as unreliable if kretprobed functions are present

2021-03-30 Thread madvenka
From: "Madhavan T. Venkataraman" When a kretprobe is active for a function, the function's return address in its stack frame is modified to point to the kretprobe trampoline. When the function returns, the frame is popped and control is transferred to the trampoline. The trampoline eventually

[RFC PATCH v1 1/4] arm64: Implement infrastructure for stack trace reliability checks

2021-03-30 Thread madvenka
From: "Madhavan T. Venkataraman" Implement a check_reliability() function that will contain checks for the presence of various features and conditions that can render the stack trace unreliable. Introduce the first reliability check - If a return PC encountered in a stack trace is not a valid

[RFC PATCH v2 4/8] arm64: Detect an EL1 exception frame and mark a stack trace unreliable

2021-03-15 Thread madvenka
From: "Madhavan T. Venkataraman" EL1 exceptions can happen on any instruction including instructions in the frame pointer prolog or epilog. Depending on where exactly they happen, they could render the stack trace unreliable. If an EL1 exception frame is found on the stack, mark the stack trace

[RFC PATCH v2 3/8] arm64: Terminate the stack trace at TASK_FRAME and EL0_FRAME

2021-03-15 Thread madvenka
From: "Madhavan T. Venkataraman" Implement the following checks in the unwinder to detect the terminating frame reliably: - The frame must end in task_pt_regs(task)->stackframe. - The frame type must be either TASK_FRAME or EL0_FRAME. Signed-off-by: Madhavan T. Venkataraman

[RFC PATCH v2 7/8] arm64: Detect kretprobed functions in stack trace

2021-03-15 Thread madvenka
From: "Madhavan T. Venkataraman" When a kretprobe is active for a function, the function's return address in its stack frame is modified to point to the kretprobe trampoline. When the function returns, the frame is popped and control is transferred to the trampoline. The trampoline eventually

[RFC PATCH v2 2/8] arm64: Implement frame types

2021-03-15 Thread madvenka
From: "Madhavan T. Venkataraman" Apart from the task pt_regs, pt_regs is also created on the stack for other other cases: - EL1 exception. A pt_regs is created on the stack to save register state. In addition, pt_regs->stackframe is set up for the interrupted kernel

[RFC PATCH v2 8/8] arm64: Implement arch_stack_walk_reliable()

2021-03-15 Thread madvenka
From: "Madhavan T. Venkataraman" unwind_frame() already sets the reliable flag in the stack frame during a stack walk to indicate whether the stack trace is reliable or not. Implement arch_stack_walk_reliable() like arch_stack_walk() but abort the stack walk as soon as the reliable flag is set

[RFC PATCH v2 0/8] arm64: Implement reliable stack trace

2021-03-15 Thread madvenka
From: "Madhavan T. Venkataraman" I have made an attempt to implement reliable stack trace for arm64 so it can be used for livepatch. Below is the list of changes. I have documented my understanding of the issues and solutions below as well as in the patch descriptions and the code. Please let me

[RFC PATCH v2 1/8] arm64: Implement stack trace termination record

2021-03-15 Thread madvenka
From: "Madhavan T. Venkataraman" The unwinder needs to be able to reliably tell when it has reached the end of a stack trace. One way to do this is to have the last stack frame at a fixed offset from the base of the task stack. When the unwinder reaches that offset, it knows it is done. Kernel

[RFC PATCH v2 5/8] arm64: Detect an FTRACE frame and mark a stack trace unreliable

2021-03-15 Thread madvenka
From: "Madhavan T. Venkataraman" When CONFIG_DYNAMIC_FTRACE_WITH_REGS is enabled and tracing is activated for a function, the ftrace infrastructure is called for the function at the very beginning. Ftrace creates two frames: - One for the traced function - One for the caller of

[RFC PATCH v2 6/8] arm64: Check the return PC of every stack frame

2021-03-15 Thread madvenka
From: "Madhavan T. Venkataraman" If a function encountered in a stack trace is not a valid kernel text address, the stack trace is considered unreliable. Mark the stack trace as not reliable. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/kernel/stacktrace.c | 10 ++ 1 file

[RFC PATCH v1 0/1] arm64: Unwinder enhancements for reliable stack trace

2021-02-23 Thread madvenka
From: "Madhavan T. Venkataraman" I have made an attempt to add some enhancements to the stack trace code so it is a few steps closer to what is required for livepatch. Unwinder changes Termination === Currently, the unwinder terminates when

[RFC PATCH v1 1/1] arm64: Unwinder enhancements for reliable stack trace

2021-02-23 Thread madvenka
From: "Madhavan T. Venkataraman" Unwinder changes Termination === Currently, the unwinder terminates when both the FP (frame pointer) and the PC (return address) of a frame are 0. But a frame could get corrupted and zeroed. There

[PATCH v3 1/1] arm64: Implement stack trace termination record

2021-04-20 Thread madvenka
From: "Madhavan T. Venkataraman" Reliable stacktracing requires that we identify when a stacktrace is terminated early. We can do this by ensuring all tasks have a final frame record at a known location on their task stack, and checking that this is the final frame record in the chain. Kernel

[PATCH v3 0/1] arm64: Implement stack trace termination record

2021-04-20 Thread madvenka
From: "Madhavan T. Venkataraman" Reliable stacktracing requires that we identify when a stacktrace is terminated early. We can do this by ensuring all tasks have a final frame record at a known location on their task stack, and checking that this is the final frame record in the chain. All