1

In my linux header files folder on my Kali kernal 5.7.0 headers included in include directory /usr/src/linux-headers-5.7.0-kali1-common/include. Inside this folders I have header files contained in sub-folders like asm-generic,linux,uapi,acpi,crypto,etc.. But inside header files, i.e. inside linux/module.h there there is one header file reference included like

    #include <asm/module.h>  // top of linux/module.h

But Actually I don't have asm folder that got included with my header files when I installed them. So one solution that came to mind is. Probably solution: Change the references from asm/* to asm-generic/* as in from asm/module.h to asm-generic/module.h inside linux/module.h and other files which I may use. I like to know is asm and asm-generic are same? meaning they contains same files and structure or is there any difference i can cause problem

If I correct the directory name in include reference than Does it make sense, or I will get into problems when I compile the module if I change headers sub directories names in include list of header files from asm to asm-generic? If I dont do this the header files will be missing

user786
  • 3,902
  • 4
  • 40
  • 72
  • 1
    I do not know kali-linux. I think it includes the headers also in an other place (arch specific). Linux kernel link `asm` to the relevant architecture (so you may need it, but also with the kernel configuration you are using). `asm-generic` are templates which new architectures could use (if they do not want to implement all) -- in My Debian kernel have headers are in /usr/include/asm and /usr/include/linux – Giacomo Catenazzi Jan 06 '21 at 12:13
  • @GiacomoCatenazzi what if I create asm folder in include/ and copied to it everything from asm-generic. It may compile if names were really wrong (I doubt this). Or not compile if asm-generic is really something exists and is separate from asm and internal to kernal (since there is asm directory but I think its in some other folder like uapi or etc. in include/). I will try both. Wish I could get any specific info. is there any forum that talks about kali kernal internals or where I can get info on is asm-generic same as asm. which version of kernal u are using. is it ubantu? – user786 Jan 06 '21 at 13:22
  • If you want to compile a module, you need the exact same headers has the kernel used (and with complete configuration of the kernel). generic has not all files, and you need architecture specific data. I would check a package which build external modules, and I would look that package on how to get correct headers and compiler flags. – Giacomo Catenazzi Jan 06 '21 at 15:23
  • If you think you need to edit the kernel header files to change asm/ to asm-generic/, you must be doing something wrong. `#include ` should actually include the file /usr/src/linux-headers-5.7.0-kali1-common/arch/x86/include/asm/module.h on your system (assuming your system architecture is x86). – Ian Abbott Jan 06 '21 at 15:45
  • These header files are only needed for building external kernel modules using the kbuild system. They should never be needed for building code that runs in user-space. – Ian Abbott Jan 06 '21 at 16:25
  • You have to get precompiled kernel source. Some of distributions may have built-in kernel source. Eg: Ubuntu. If you found nothing, checkout kali's kernel source and use `make modules_prepare` for preparing a out of tree build. – Louis Go Jan 07 '21 at 13:45
  • Found [this post](https://computingforgeeks.com/how-to-install-linux-kernel-headers-on-kali-linux-2-0-kali-sana/) should help. If you need more info, `kernel source` and `module` might help. – Louis Go Jan 07 '21 at 13:49
  • `sudo apt-get install linux-headers-$(uname -r)` might be enough. – Louis Go Jan 07 '21 at 13:57

2 Answers2

2

Short answer

They are not the same.

kernel developer might include asm-generic headers in a asm header while asm headers are the headers required for kernel modules.

You may get more info from following post

Take this question in another way.

It seems you're trying to make a kernel module.

To build a kernel module you need kernel-headers or compiled kernel source code. However I don't know kali linux, so I just provide generic suggestions here.

Where to get them

  • Some of distributions, like Ubuntu, have prebuilt linux-headers.

    • Eg: Ubuntu has it in /usr/src/linux-headers-$(uname -r)/include
  • Download it by sudo apt-get install linux-headers-$(uname -r)

    • It seems kali linux 2.0 might need more operations. Found this post might help.
  • Build it yourself

    1. Checkout linux kernel code of your desired distro.
    2. Set up kernel config with make menuconfig ( You might get stumbled here a while.. many packages might be required )
    3. Compile kernel with make modules_prepare to compile essential Module.symvers for drivers. It take significant less time than compiling a full kernel.

I presume you already found a kernel module build example. If not, you may consult offical kernel module documentation. It helps a lot if you take a while to read first two chapters.

Or another example

Louis Go
  • 2,213
  • 2
  • 16
  • 29
  • Thanks. I dont need to include asm in headers but asm-generic. Since my linux headers installed on kali 5.7 does not have asm directory in include. Thank you very much. but can u please confirm that I dont not need to have asm in headers in my kernel modules that I am making and modules that I download like e1000e from other places, instead I can have asm-generic in header. – user786 Jan 14 '21 at 08:47
  • @Alex You SHOULD find a way to get kernel headers with asm directory. That's the way to compile a kernel module. Since I don't know much about kali, I hope [this post](https://computingforgeeks.com/how-to-install-linux-kernel-headers-on-kali-linux-2-0-kali-sana/) helps. My suggestion is to checkout your kali kernel source code, where there should be asm directory for kernel module. [Recompiling the Kali Linux Kernel](https://www.kali.org/docs/development/recompiling-the-kali-linux-kernel/) might help as well. – Louis Go Jan 14 '21 at 08:57
  • @Alex Note that kernel module should be portable in some way, so you should find headers with the same name across different distribution of kernels. That's why I presume kali should have `asm\module.h`. – Louis Go Jan 14 '21 at 08:59
  • Can u please take a look at this question. Its on this page question https://stackoverflow.com/questions/65719389/linux-headers-makefile-checking-empty-variable-and-so-not-able-to-include-header – user786 Jan 14 '21 at 12:57
  • @Alex It's been removed. You may edit your current question if it's related. – Louis Go Jan 15 '21 at 00:16
1

I found my asm directory at

/usr/src/{headers}/arch/{myArch}/include/asm

and

/usr/include/{myarch}/asm

Maybe you can find there too (I hope).

joshua
  • 458
  • 5
  • 18