Reputation: 6176
Is it possible to override one of the linux kernel functions using LD_PRELOAD
?
For instance, I want to change the cookie_hash
function in Linux/net/ipv4/syncookie.c
for the listening socket for my program fooserver
. Can I do it using LD_PRELOAD, or I need to recompile the kernel for that?
Are there any other options?
Thanks,
Upvotes: 0
Views: 833
Reputation: 560
You can do something similar in Linux Kernel. It isn't a trivial operation but what you should do is the next:
There are many hidden traps and potential crashes, though. But generally, this approach works.
Upvotes: 0
Reputation: 529
You have to use kprobes or systemtap to override kernel functions. It isn't necessary to recompile.
Upvotes: 0
Reputation: 58848
No, it is not possible to use LD_PRELOAD to replace a function in the kernel.
You will need to either recompile the kernel.
If the function is in a kernel module, then you may be able to unload, recompile and reload the module without needing to restart the kernel.
If this is something you will be doing frequently, then you will want to use a second computer, or a virtual machine, so you won't have to keep restarting the computer you're programming on.
Upvotes: 3