内核模块 许可证声明

内核模块遵循GPL兼容许可权的申明(linux/module.h)
模块不声明 LICENSE,内核会有(kernel tainted)警告,内核状态此时是受污染的(dirty)

--------------------
MODULE_LICENSE("Dual BSD/GPL"); 
    GPL:`GNU General Public License`,免费使用,可修改代码,但要开源
    GPL v2:为GPL的第二版本。
    GPL and additional rights:
    Dual BSD/GPL:BSD/GPL 双 LICENSE(V2.4/V2.6 常用),代码修改后不用开源,可销售、但不能借用作者名头宣传。
    Dual MIT/GPL:比BSD更宽泛,只要注明作者版权,其他无限制
    Dual MPL/GPL:MPL/GPL 双 LICENSE。类似GPL,但允许核心代码以库的形式发布,接口API以MPL协议发布
    Proprietary:私有模

以常见的Android为例:

 AOSP:Android内核使用了kernel,采用GPL协议
  驱动:放在HAL层或以KO形式动态加载(如GPU)
  HAL层、 Google应用:采用Apache协议,不开源
  Bionic libc:采用BSD协议

内核污染:dirty

在源码内编译不会受到污染。通过模块形式才有可能会污染。内核受污染后,一些调试、打印功能可能会失效。
一些调试功能、输出失效,一些API系统调用失效。社区一般不会处理tainted kernel下的bug。
内核污染常见的原因如下:

    加载一些不开源、跟GPL不兼容的驱动
    staging内核模块
    一些out-of-tree模块的加载运行
    内核编译时依赖的内核版本和运行版本不一致
    支持SMP的内核在早期不支持多核的单核CPU上运行
    BIOS或UEFI中的一些bug
    内核启动时的一些机器检查或OOPS

内核污染定位

查看污染:显示结果为返回值。原因见下说明。
cat /proc/sys/kernel/tainted
内核文档说明:documentation/aadmin-guide/tainted-kernels.rst

    Bit Log Number Reason that got the kernel tainted
    === === ====== ========================================================
    0 G/P 1 proprietary module was loaded
    1 _/F 2 module was force loaded
    2 _/S 4 SMP kernel oops on an officially SMP incapable processor
    3 _/R 8 module was force unloaded
    4 _/M 16 processor reported a Machine Check Exception (MCE)
    5 _/B 32 bad page referenced or some unexpected page flags
    6 _/U 64 taint requested by userspace application
    7 _/D 128 kernel died recently, i.e. there was an OOPS or BUG
    8 _/A 256 ACPI table overridden by user
    9 _/W 512 kernel issued warning
    10 _/C 1024 staging driver was loaded
    11 _/I 2048 workaround for bug in platform firmware applied
    12 _/O 4096 externally-built ("out-of-tree") module was loaded。即不依赖内核源码编译的模块。
    13 _/E 8192 unsigned module was loaded
    14 _/L 16384 soft lockup occurred
    15 _/K 32768 kernel has been live patched
    16 _/X 65536 auxiliary taint, defined for and used by distros
    17 _/T 131072 kernel was built with the struct randomization plugin
Linux内核模块编译、加载、运行机制分析、版本控制、许可声明、内核污染、模块传参、模块签名机制、out-of-tree动态模块编译及Makefile模板编写,尽在《Linux内核编程》,详情点击:王利涛老师个人淘宝店:Linux内核编程