4

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?

6
  • 1
    A better question might be "Is there a better solution than passing a 1024 char string as a parameter", or then again maybe not. Could you explain why this is necessary? There may well be better approaches. Commented Mar 20, 2014 at 14:01
  • The string represents a binary code, which I use for computations in my module. A string seems to be the best solution regarding input convenience and later computations. Commented Mar 20, 2014 at 14:28
  • 1
    Why don't you split it into two, pass each part as a separate parameter and join it in your code? Commented Mar 20, 2014 at 14:29
  • Will do now. I also came up with this, but I would have preferred having only 1 parameter for the code. Commented Mar 20, 2014 at 14:38
  • 1
    You might want to obtain the argument in some other way, e.g. through /sys after loading the module. Commented Mar 20, 2014 at 23:56

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

You can definitely have more than 1024 bytes in a noormal command argument. Consider the following - /bin/echo $(tr -dc [:alnum:] </dev/urandom | head -c 1025) - here we have a 1025 byte argument
Yeap, my mistypo. I means kernel paramaters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.