LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions
User Name
Password
Linux - Distributions This forum is for Distribution specific questions.
Red Hat, Slackware, Debian, Novell, LFS, Mandriva, Ubuntu, Fedora - the list goes on and on... Note: An (*) indicates there is no official participation from that distribution here at LQ.

Notices


Reply
  Search this Thread
Old 06-06-2022, 11:23 PM   #1
z3r0_1993
LQ Newbie
 
Registered: Jun 2022
Posts: 4

Rep: Reputation: 0
Compile Linux Kernel Module - Cannot build simple kernel module


I'm trying to compile a kernel module driver but I get the following errors: (the operation generate some files, but not a ".ko" file)



Code:
make -C /lib/modules/5.16.0-kali7-amd64/build M=/home/z3r0/Scrivania/kernel_modules/start_stop modules
    make[1]: ingresso nella directory «/usr/src/linux-headers-5.16.0-kali7-amd64»
    /bin/sh: 1: /usr/src/linux-headers-5.16.0-kali7-common/scripts/pahole-flags.sh: not found
    
      ERROR: Kernel configuration is invalid.
             include/generated/autoconf.h or include/config/auto.conf are missing.
             Run 'make oldconfig && make prepare' on kernel src to fix it.
    
    make[1]: *** [/usr/src/linux-headers-5.16.0-kali7-common/Makefile:751: include/config/auto.conf] Errore 1
    make[1]: uscita dalla directory «/usr/src/linux-headers-5.16.0-kali7-amd64»
    make: *** [Makefile:3: all] Errore 2
When I try to execute "make oldconfig && make prepare" (in the directory /usr/src/linux-headers-5.16.0-kali7-amd64) I get the following error:

Code:
/bin/sh: 1: /usr/src/linux-headers-5.16.0-kali7-common/scripts/pahole-flags.sh: not found
      GEN     Makefile
    /bin/sh: 1: /usr/src/linux-headers-5.16.0-kali7-common/scripts/pahole-flags.sh: not found
    /usr/src/linux-headers-5.16.0-kali7-common/scripts/Makefile.build:44: /usr/src/linux-headers-5.16.0-kali7-common/scripts/basic/Makefile: File o directory non esistente
    make[1]: ***  Nessuna regola per generare l'obiettivo «/usr/src/linux-headers-5.16.0-kali7-common/scripts/basic/Makefile».  Arresto.
    make: *** [/usr/src/linux-headers-5.16.0-kali7-common/Makefile:566: scripts_basic] Errore 2
If I try in my computer and not in the Virtual Machine I get the following error (but it generate some files, but not the .ko file):
Code:
make -C /lib/modules/5.16.0-kali7-amd64/build M=/home/z3r0/Scrivania/All/Programming/C++/Exercises_Linux/kernel_modules/hello_world modules
make[1]: ingresso nella directory «/usr/src/linux-headers-5.16.0-kali7-amd64»
/bin/sh: 1: /usr/src/linux-headers-5.16.0-kali7-common/scripts/pahole-flags.sh: not found
/bin/sh: 1: /usr/src/linux-headers-5.16.0-kali7-common/scripts/pahole-flags.sh: not found
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: gcc-11 (Debian 11.2.0-19) 11.2.0
  You are using:           gcc-11 (Debian 11.3.0-3) 11.3.0
/bin/sh: 1: /usr/src/linux-headers-5.16.0-kali7-common/scripts/pahole-flags.sh: not found
  CC [M]  /home/z3r0/Scrivania/All/Programming/C++/Exercises_Linux/kernel_modules/hello_world/hello_world.o
/bin/sh: 1: /usr/src/linux-headers-5.16.0-kali7-common/scripts/pahole-flags.sh: not found
/bin/sh: 1: /usr/src/linux-headers-5.16.0-kali7-common/scripts/pahole-flags.sh: not found
  MODPOST /home/z3r0/Scrivania/All/Programming/C++/Exercises_Linux/kernel_modules/hello_world/Module.symvers
ERROR: modpost: missing MODULE_LICENSE() in /home/z3r0/Scrivania/All/Programming/C++/Exercises_Linux/kernel_modules/hello_world/hello_world.o
make[2]: *** [/usr/src/linux-headers-5.16.0-kali7-common/scripts/Makefile.modpost:134: /home/z3r0/Scrivania/All/Programming/C++/Exercises_Linux/kernel_modules/hello_world/Module.symvers] Errore 1
make[2]: *** Eliminazione del file «/home/z3r0/Scrivania/All/Programming/C++/Exercises_Linux/kernel_modules/hello_world/Module.symvers»
make[1]: *** [/usr/src/linux-headers-5.16.0-kali7-common/Makefile:1785: modules] Errore 2
make[1]: uscita dalla directory «/usr/src/linux-headers-5.16.0-kali7-amd64»
make: *** [Makefile:3: all] Errore 2


The file is really simple (hello_world.c):

Code:
    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/init.h>
    
    static int __init hello_start(void)
    {
    	printk(KERN_INFO "Loading hello module...\n");
    	printk(KERN_INFO "Hello world\n");
    	return 0;
    }
    
    static void __exit hello_end(void)
    {
    	printk(KERN_INFO "Goodbye Mr.\n");
    }
    
    module_init(hello_start);
    module_exit(hello_end);
makefile:

Code:
    obj-m = foo.o
    KVERSION = $(shell uname -r)
    all:
    	make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
    clean:
    	make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
Can someone explain where is the error? Thank you

Last edited by z3r0_1993; 06-06-2022 at 11:30 PM.
 
Old 06-07-2022, 12:17 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,784

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
probably:
Code:
      ERROR: Kernel configuration is invalid.
             include/generated/autoconf.h or include/config/auto.conf are missing.
             Run 'make oldconfig && make prepare' on kernel src to fix it.
 
Old 06-07-2022, 02:01 AM   #3
z3r0_1993
LQ Newbie
 
Registered: Jun 2022
Posts: 4

Original Poster
Rep: Reputation: 0
Already Tryed

Quote:
Originally Posted by pan64 View Post
probably:
Code:
      ERROR: Kernel configuration is invalid.
             include/generated/autoconf.h or include/config/auto.conf are missing.
             Run 'make oldconfig && make prepare' on kernel src to fix it.


Hello, Thank you for ur answer
but as I said in my request I already tryed these commands and I get the error I wrote on the question above :/

Code:
When I try to execute "make oldconfig && make prepare" (in the directory /usr/src/linux-headers-5.16.0-kali7-amd64) I get the following error:

/bin/sh: 1: /usr/src/linux-headers-5.16.0-kali7-common/scripts/pahole-flags.sh: not found
      GEN     Makefile
    /bin/sh: 1: /usr/src/linux-headers-5.16.0-kali7-common/scripts/pahole-flags.sh: not found
    /usr/src/linux-headers-5.16.0-kali7-common/scripts/Makefile.build:44: /usr/src/linux-headers-5.16.0-kali7-common/scripts/basic/Makefile: File o directory non esistente
    make[1]: ***  Nessuna regola per generare l'obiettivo «/usr/src/linux-headers-5.16.0-kali7-common/scripts/basic/Makefile».  Arresto.
    make: *** [/usr/src/linux-headers-5.16.0-kali7-common/Makefile:566: scripts_basic] Errore 2

Last edited by z3r0_1993; 06-07-2022 at 02:09 AM.
 
Old 06-07-2022, 02:24 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,784

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
So make oldconfig failed. I guess your kernel source tree is either incomplete or corrupted.
How did you create it?
 
1 members found this post helpful.
Old 06-07-2022, 02:33 AM   #5
z3r0_1993
LQ Newbie
 
Registered: Jun 2022
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pan64 View Post
So make oldconfig failed. I guess your kernel source tree is either incomplete or corrupted.
How did you create it?
Mh sorry created what? xD
 
Old 06-07-2022, 02:46 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,784

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
So you use kali, which is recommended only for advanced users
you want to build a kernel module, which is again not really suggested for beginners.
and finally I guess you have a guide or a set of instructions to explain how do you need to prepare your environment (if you want to build kernel modules).
I guess you missed a step or just failed something during that preparation.
What is in /usr/src/linux-headers-5.16.0-kali7-common ? And how was this directory created?
 
Old 06-07-2022, 03:02 AM   #7
z3r0_1993
LQ Newbie
 
Registered: Jun 2022
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pan64 View Post
So you use kali, which is recommended only for advanced users
you want to build a kernel module, which is again not really suggested for beginners.
and finally I guess you have a guide or a set of instructions to explain how do you need to prepare your environment (if you want to build kernel modules).
I guess you missed a step or just failed something during that preparation.
What is in /usr/src/linux-headers-5.16.0-kali7-common ? And how was this directory created?
Mh in the guide I was following I didn't see any instructions to set up the environment. I will search for it, thanks.
I though the environment was already set xD

Anyway but is normal that the commands "sudo make oldconfig && sudo make prepare" don't work? I though it wasn't,
Later I'll try on my Ubuntu machine to see if I get the same error.

I think everyone can do anything if they apply intensively, so despite being raccomended for advaced users I'll learn it (:
Obviously I'm not good as you are, but I will learn
I want to learn to hook syscalls and I want to analyze (disassembly and debugging) the program that hook the syscalls.


"linux-headers-5.16.0-kali7-common" I think it's about linux headers, it contains some tools and some scripts and also headers for different kind of processor.
It was already installed, I didn't need to get the linux-header package or upgrade it ^^
 
Old 06-07-2022, 04:15 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,784

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
Quote:
Originally Posted by z3r0_1993 View Post
I think everyone can do anything if they apply intensively, so despite being raccomended for advaced users I'll learn it (:
I don't think so. As it was mentioned several times: learn to walk first, then run.
Quote:
Originally Posted by z3r0_1993 View Post
Obviously I'm not good as you are, but I will learn
I am not good at everything but what I have learned already.

Quote:
Originally Posted by z3r0_1993 View Post
I want to learn to hook syscalls and I want to analyze (disassembly and debugging) the program that hook the syscalls.
That is great, but first you need to be able to compile simple programs and debug them, not the kernel itself (or kernel modules).
 
Old 06-07-2022, 09:07 AM   #9
uteck
Senior Member
 
Registered: Oct 2003
Location: Elgin,IL,USA
Distribution: Ubuntu based stuff for the most part
Posts: 1,172

Rep: Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501
Kali is heavily customized and not intended for doing development work, you will have better results and learn more/faster using a normal disto.
Using a distro specialized at penetration testing to learn disassembly and debugging is like using a PlayStation to learn Excel.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] GCC makefile give me an error: configure: error: cannot compute suffix of object files: cannot compile - LFS build George528 Linux From Scratch 10 05-11-2021 08:32 AM
[SOLVED] Linux 4.4 seems to refuse to build IPv6 for the 64-bit build - 32-bit build works fine GameCodingNinja Linux From Scratch 2 02-07-2016 06:40 PM
Simple Slackware vs simple Arch vs simple Frugalware punchy71 Linux - Distributions 2 08-28-2012 02:30 PM
Cannot compile a simple driver module Pouyaaa Linux - Software 1 12-04-2011 12:15 PM
LXer: Build 'em Right, Build 'em Strong, Build 'em Linux LXer Syndicated Linux News 0 10-01-2007 09:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions

All times are GMT -5. The time now is 10:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration