1

I'd like to modify the security module (Specifically security/IMA) of the linux kernel.(This module has to be compiled into the kernel)

I have to use functions from a shared library (an .so file) in this module.

but I don't know how to compile it.

Is there a way to put the shared library file to the Linux kernel?

And if there is no way to do it ,can you tell me the reason?

1 Answer 1

4

You practically cannot do that (linking a shared library into the kernel or some kernel module). The kernel is conceptually a freestanding program (so does not know about low-level standard C functions like malloc or fprintf that your shared library is very likely to use). Kernel modules (*.ko files) are specially built and are loaded by some special kernel code.

Also, user-land code (including libraries) are based upon system calls (listed in syscalls(2)), which are not available in kernel code (since the kernel is providing the system calls to processes running in user mode thru specific machinery).

You might consider having a user-land helper program communicating with the kernel (i.e. your kernel module), e.g. using netlink(7). Perhaps look also into systemd.

You probably should read more about Operating Systems and read Advanced Linux Programming to understand the user-land aspects.

BTW, as a rule of thumb, you should limit the amount of kernel code added to the system (and prefer working in user-land).

3
  • Hi, sorry for late comment but: How does it affect things really if the kernel did allow linking shared libs ? From what I understand it will only affect performance, or user code may be vulnerable but that shouldnt be a concern since kernel code can be buggy as well. And about kernel not understanding malloc() (etcetra), shouldnt be concern as well, since the shared libraries will if the kernel allowed linking .SO's. What i am asking is: Wouldnt it be really advantageous and convient if it did allow it? Or is there something flawed about that ? Or its just the way things are ?
    – oops
    Commented May 1, 2021 at 7:25
  • shared libraries for the Linux kernel are called modules and they are *.ko files, not *.so files Commented May 1, 2021 at 9:51
  • True, but I meant ask about linking user space .so libs with LKM's. It might have appeared otherwise, Sorry about that. To reword my question:IMO it shouldnt be a concern that kernel doesnt understnd funcs like malloc()(for ex.), because the shared lib will, provided kernel allows linking. It seems like such a convenience for .so linking, and yet kernel doesnt allow it. I was wondering if there is a tech reason behind it, or just the way it is. It also cant be because of security because kernel code can be buggy as well, and whats more is that userland code provides virtual mem protection.
    – oops
    Commented May 1, 2021 at 10:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .