I tried to convert the kprobe as loadable kernel module.
I am able to run the samples available in samples/kprobes/
folder from
kernel tree.
If we configure kprobes in kernel(CONFIG_KPROBES
), then svc_entry
macro will be expanded with 64 bytes in __und_svc()
handler.
Reference : http://lxr.free-electrons.com/source/arch/arm/kernel/entry-armv.S?a=arm#L245
My aim is without touching kernel side, make kprobe as kernel module.
so kernel is compiled without enabling CONFIG_KPROBES. so svc_entry macro will be expanded with 0 in __und_svc()
I would like to get cleared from these doubts.
If kprobe is handled undefined instruction exception(bcos kprobe only created), then why
__und_svc()
is invoked. what is the role of__und_svc()
handler with respect to kprobes??If 64 bytes memory is compulsory, then how to allocate without compiling the kernel. i.e How to do it dynamically.??
Please share your knowledge.
You may not get responses as your understanding of things is not very good and it will take some time for anyone on the linux-arm-kernel list to respond. Read kprobes.txt and study the ARM architecture in detail.
On the ARM, mode
0b11011
is the undefined instruction mode. The flow when an undefined instruction happens is,The main vector table of step four is located at
__vectors_start
and this just branches tovector_und
. The code is a macro calledvector_stub
, which makes a descision to call either__und_svc
or__und_usr
. The stack is the 4/8k page that is reserved per process. It is the kernel page which contains both the task structure and the kernel stack.kprobe works by placing undefined instructions at code addresses that you wish to probe. Ie, it involves the undefined instruction handler. This should be pretty obvious. It calls two routines,
call_fpe
ordo_undefinstr()
. You are interested in the 2nd case, which gets the opcode and callscall_undef_hook()
. Add a hook with register_undef_hook(); which you can seearch_init_kprobes()
. The main callbackkprobe_handler
is called with astruct pt_regs *regs
, which happens to be the extra memory reserved in__und_svc
. Notice for instance,kretprobe_trampoline()
, which is playing tricks with the stack that it is currently executing with.No it is not. You can use a different mechanism, but you may have to modify the kprobes code. Most likely you will have to limit functionality. It is also possible to completely re-write the stack frame and reserve the extra 64bytes after the fact. It is not an allocation as in
kmalloc()
. It is just adding/subtracting a number from the supervisor stack pointer. I would guess that the code re-writes the return address from the undefined handler to execute in the context (ISR, bottom half/thread IRQ, work_queue, kernel task) of the kprobed address. But there are probably additional issues you haven't yet encountered. Ifarch_init_kprobes()
is never called, then you can just always do the reservation in__und_svc
; it just eats 64 bytes of stack which will make it more likely that the kernel stack will overflow. Ie, change,arch_init_kprobes()
is what actually installs the feature.