8

I'm currently trying to run a kernel module. This module seems to work fine on various Linux machines, however, when I attempt to run it on a specific machine (namely, CentOS with a kernel version of 2.6), the module fails to start, claiming that I haven't set a module license, and, as a result, not allowing me to use various necessary kernel APIs.

I have set MODULE_LICENSE("GPL") in the bottom of my main source file (the one that contains module_init and module_exit), and as far as all the examples I could find say, that's enough. I should note that my project has multiple files.

I'm kind of stumped, so any help would be appreciated.

Ori Osherov
  • 484
  • 1
  • 6
  • 15

3 Answers3

6

For a start, verify that the license info is present in your module object file.

objdump -sj.modinfo yourModule.ko

Armali
  • 18,255
  • 14
  • 57
  • 171
5

I just encountered the same issue, which was fixed only after I wrote MODULE_LICENSE("GPL") at the beginning (after the includes) of every c file which the module's makefile is referring to.

Yoav Feuerstein
  • 1,925
  • 2
  • 22
  • 53
  • 1
    Thanks. This was my problem too. (I think a lot of people build "1 file" modules and don't see this.) – PatchyFog Apr 05 '18 at 20:14
3

Okay, I've figured out what I did wrong. I attempted to enable the -Werror flag for my module's compilation. In doing this, I added the following line to the makefile:

CFLAGS_MODULE=-Werror

I assume that this messed up something about the kernel's module licensing. Removing this line made the module work again. If you're having this sort of problem, make sure that you're not messing around with environment variables in your makefile.

Ori Osherov
  • 484
  • 1
  • 6
  • 15