String length limit for a kernel module parameter

2019-07-20 17:58发布

I am passing a string as parameter when loading a kernel module. When the string is > 1024 chars, modprobe results in an error:

FATAL: Error inserting mymodule (/lib/modules..): No space left on device

dmesg output:

mystr: string parameter too long

Are module parameters limited to 1024 char strings?

1条回答
beautiful°
2楼-- · 2019-07-20 18:27

I think not only module but also all linux command kernel parameters are limited to 1024 char. From linux source code, file kernel/params.c:

int param_set_charp(const char *val, const struct kernel_param *kp)
{
    if (strlen(val) > 1024) {
        pr_err("%s: string parameter too long\n", kp->name);
        return -ENOSPC;
    }

    maybe_kfree_parameter(*(char **)kp->arg);

    /* This is a hack.  We can't kmalloc in early boot, and we
     * don't need to; this mangled commandline is preserved. */
    if (slab_is_available()) {
        *(char **)kp->arg = kmalloc_parameter(strlen(val)+1);
        if (!*(char **)kp->arg)
            return -ENOMEM;
        strcpy(*(char **)kp->arg, val);
    } else
        *(const char **)kp->arg = val;

    return 0;
}

So the answer, you can not pass parameter which bigger than 1024 chars.

查看更多
登录 后发表回答