内核KABI兼容性验证结论

内核源文件移动 moved kabi 影响验证

实验步骤

  1. 尝试 crc32test.c [ crc32test.ko ] 在 openEuler 上编译模块。在 UOS 内核上 insmod -f crc32test.ko(该模块内核源码自带)。
  2. 根据 crc32test.ko 代码理解无错误输出即为无问题。

结论

实验结果:

uos 内核 insmod crc32test.ko && rmmod crc32test

[11025.956259] crc32: CRC_LE_BITS = 64, CRC_BE BITS = 64
[11025.960066] crc32: self tests passed, processed 225944 bytes in 419474 nsec
[11025.965444] crc32c: CRC_LE_BITS = 64
[11025.968079] crc32c: self tests passed, processed 225944 bytes in 203589 nsec
[11026.004074] crc32_combine: 8373 self tests passed
[11026.037699] crc32c_combine: 8373 self tests passed

openeuler 内核 insmod crc32test.ko && rmmod crc32test

[   67.293765] crc32test: loading out-of-tree module taints kernel.
[   67.298554] crc32test: module verification failed: signature and/or required key missing - tainting kernel
[   67.307587] crc32: CRC_LE_BITS = 64, CRC_BE BITS = 64
[   67.310631] crc32: self tests passed, processed 225944 bytes in 370844 nsec
[   67.315164] crc32c: CRC_LE_BITS = 64
[   67.317342] crc32c: self tests passed, processed 225944 bytes in 187327 nsec
[   67.347615] crc32_combine: 8373 self tests passed
[   67.373687] crc32c_combine: 8373 self tests passed

前已验证 KABI 文件路径的变动不会对模块产生影响。证实以下检查可忽略:

*** WARNING - ABI SYMBOLS MOVED ***
The following symbols moved (typically caused by moving a symbol from being
provided by the kernel vmlinux out to a loadable module):
new kabi:
0xb15b4109	crc32c	vmlinux	EXPORT_SYMBOL
old kabi
0xb15b4109	crc32c	lib/libcrc32c	EXPORT_SYMBOL

HashID changed kabi 影响验证

实验步骤

  1. 找到 HashID 变动的 KABI 函数,crypto_alloc_shash,创建模块源码文件在 UOS 内核中直接编译模块。
#include 
#include 
#include 
#include 

struct sdesc {
    struct shash_desc shash;
    char ctx[];
};

static struct sdesc *init_sdesc(struct crypto_shash *alg)
{
    struct sdesc *sdesc;
    int size;

    size = sizeof(struct shash_desc) + crypto_shash_descsize(alg);
    sdesc = kmalloc(size, GFP_KERNEL);
    if (!sdesc)
        return ERR_PTR(-ENOMEM);
    sdesc->shash.tfm = alg;
    sdesc->shash.flags = 0x0;
    return sdesc;
}

static int calc_hash(struct crypto_shash *alg,
             const unsigned char *data, unsigned int datalen,
             unsigned char *digest)
{
    struct sdesc *sdesc;
    int ret;

    sdesc = init_sdesc(alg);
    if (IS_ERR(sdesc)) {
        pr_info("can't alloc sdesc\n");
        return PTR_ERR(sdesc);
    }

    ret = crypto_shash_digest(&sdesc->shash, data, datalen, digest);
    kfree(sdesc);
    return ret;
}

/*
测试函数,data是进行hash的数据,datalen为数据长度,digest为sha1结果(是一个 out变量)
*/
static int test_hash(const unsigned char *data, unsigned int datalen,
             unsigned char *digest)
{
    struct crypto_shash *alg;
    char *hash_alg_name = "sha1";
    int ret;

    alg = crypto_alloc_shash(hash_alg_name, 0, 0);
    if (IS_ERR(alg)) {
            pr_info("can't alloc alg %s\n", hash_alg_name);
            return PTR_ERR(alg);
    }
    ret = calc_hash(alg, data, datalen, digest);
    crypto_free_shash(alg);
    return ret;
}

static int __init crypto_alloc_shash_init(void)
{
    const char *data = "hello world";
    char res[128];
    memset(&res, 0, 128);
    test_hash(data, strlen(data), res);
    pr_info("src: %s\n", data);
    pr_info("res: %s\n", res);
    return 0;
}

static void __exit crypto_alloc_shash_exit(void)
{
}

module_init(crypto_alloc_shash_init);
module_exit(crypto_alloc_shash_exit);

MODULE_AUTHOR("Matt Domsch ");
MODULE_DESCRIPTION("crypto alloc test");
MODULE_LICENSE("GPL");
  1. 确认输出信息和是否存在runtime abort

实验结果

openeuler 内核 dmesg

[  647.153652] src: hello world
[  647.155974] res: *\xael5\xc9Oϴ\x15\xdb\xe9_@\x8b\x9c\xe9\x1e\xe8F\xed

uos 内核 dmesg

[   76.571874] src: hello world
[   76.573740] res: *\xael5\xc9Oϴ\x15\xdb\xe9_@\x8b\x9c\xe9\x1e\xe8F\xed

结论

证实HashID地址,部分对内核兼容无影响。具体问题涉及语法分析:

  1. 关于 modified 类型的语法修饰符也会造成HashID的变化(如 __attribute__ unused,需要查询语法自行判断)。
  2. 变量或函数长度变化(关于 params 类型的语法修饰符会导致参数传递上的错误,影响较大,极易 crashed )。
  3. 对于弱类型兼容,例如 int 类型变更到 long(无影响)。
0xe9b2762b	crypto_alloc_shash	vmlinux	EXPORT_SYMBOL_GPL
0x92cf6f0f	crypto_alloc_shash	vmlinux	EXPORT_SYMBOL_GPL

你可能感兴趣的:(linux)