Should have specified that:
I'm interested to hack the Linux kernel.
I've done low-level user space hacking in C on Linux. Now wondering how much additional knowledge I need for Linux kernel stuff…
@NerdResa The Linux Device Drivers book is available online under Creative Commons and works for many people as a way to get started:
There are repositories on GitHub with the examples updated to newer kernel versions, e.g.
https://github.com/martinezjavier/ldd3
My advice would be to find some area that interests you or an itch to scratch and read a lot of code. I started with the crypto subsystem (Ripemd algo) and the code got merge surprisingly quickly :p
@Kensan Thanks, I'll take a look at it!
My area is Networking, specifically TCP. (Don't worry, I'm not trying to get this upstream)
@NerdResa @Kensan Unfortunately the Linux Device Drivers book covers very little of the networking stack, because it's focused on things developers need to know to write… well, device drivers. 😅 But the first eight chapters may have good context for Linux kernel hacking in general, and the network drivers chapter should at least cover some of the abstractions that are shared with the higher layers.
@NerdResa @Kensan from the theory side, i suggest https://www.cl.cam.ac.uk/~pes20/Netsem/paper3.pdf and the full label transition system https://www.cl.cam.ac.uk/~pes20/Netsem/alldoc.pdf -- but this doesn't contain anything about kernel programming, just tcp/ip.. ;)
@NerdResa You probably don't need anything more to start hacking. You will see, however, a lot of kernel specific programming patterns and utilities: lists, rcu, offsetof, macros (tons of them) etc. Always look at two implementations of object of the same class like TCP and SCTP to find patterns in the interfacing code.
@steelman That sounds helpful, thanks! :)
@NerdResa if you have an idea of what you want to hack on just jump in and try to make it work. Enjoy the discovery, you can worry about doing-things-the-right-way-TM later...
Ofc things may go horribly wrong, but it's easier to find help with a practical problem later on :)
@NerdResa hm maybe https://mobile.twitter.com/alicegoldfuss can give some advice. Afaik she's starting in the topic as well.
@NerdResa The best introductory/tutorial material I'm aware of for getting started on Linux kernel hacking is the first-patch documentation for Outreachy internship applicants: https://kernelnewbies.org/OutreachyfirstpatchSetup
Most of the Linux kernel is plain C, with some caveats: 1) Linux kernel developers often use obscure corners of the language standard as well as GCC/clang-specific extensions; 2) the standard library is not available, so e.g. there's kmalloc not malloc, etc.
@NerdResa Also you may find https://www.kernel.org/doc/ helpful as reference material. Alternatively you can find a fair amount of the same material in your kernel source tree checkout under the Documentation/ directory. I often use `git grep` on either the Documentation/ or include/ directory when I see a function I don't understand.
@jamey Oooh, I was looking for something like this! Thank you *-*
@NerdResa There's some amount of material you'll need to learn but depending on what you want to do it might not be all that much. A lot of kernel stuff has analogies in userspace, just with different names.
It helps to do some reading about fundamental kernel concepts before diving into code. I have some slightly outdated linux 2.6-ish kernel development books collecting dust on my shelf which I could drop off somewhere at TU for you if you want.
@stsp Yea, I think the thing I'm planning to do isn't actually that much, but I'm not sure yet. Usually I'd read a book but I don't think I've got enough time, I'll just start hacking. :)
Thanks for the offer though, I might get back to it.
@NerdResa Sure, any time. Happy hacking 🙃
@NerdResa you need to know there's no hope