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?

goose999
  • 73
  • 1
  • 5
  • 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. – terdon Mar 20 '14 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. – goose999 Mar 20 '14 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? – terdon Mar 20 '14 at 14:29
  • Will do now. I also came up with this, but I would have preferred having only 1 parameter for the code. – goose999 Mar 20 '14 at 14:38
  • 1
    You might want to obtain the argument in some other way, e.g. through `/sys` after loading the module. – Gilles 'SO- stop being evil' Mar 20 '14 at 23:56
  • Maybe you should look into handing it a file descriptor instead. – mikeserv Mar 21 '14 at 00:04

1 Answers1

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.

cuonglm
  • 2,766
  • 1
  • 22
  • 33