]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
modinfo: rework parm string length validation
authorEmil Velikov <emil.l.velikov@gmail.com>
Sun, 2 Aug 2026 12:26:13 +0000 (13:26 +0100)
committerLucas De Marchi <demarchi@kernel.org>
Mon, 10 Aug 2026 13:49:47 +0000 (08:49 -0500)
Currently, we if we fail to find a name, description or type in the
value token we emit an error and continue.

At the same time, if the name is longer than INT_MAX we error out.
Move the validation (overall strlen(value), which includes namelen)
further up the call stack and make it a non-fatal.

This allows us to garbage collect the no longer reachable error paths
around {add,process}_param().

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/451
Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
tools/modinfo.c

index bae282f72a04f5409b91bb7f6ba1b4365f624031..02d8121cc9c618c5d7801f6dbd7f5d83cab099a3 100644 (file)
@@ -39,18 +39,15 @@ enum parm_info {
        parm_type,
 };
 
-static int add_param(const char *name, size_t namelen, enum parm_info parm_info,
-                    const char *value, struct param *params, unsigned int params_count)
+static void add_param(const char *name, int namelen, enum parm_info parm_info,
+                     const char *value, struct param *params, unsigned int params_count)
 {
-       if (namelen > INT_MAX)
-               return -EINVAL;
-
        /* We are guaranteed to have a match, or at least one empty entry */
        for (unsigned int i = 0; i < params_count; i++) {
                struct param *it = &params[i];
 
-               if (it->name != NULL && (it->namelen != (int)namelen ||
-                                        memcmp(it->name, name, namelen) != 0)) {
+               if (it->name != NULL &&
+                   (it->namelen != namelen || memcmp(it->name, name, namelen) != 0)) {
                        continue;
                }
 
@@ -67,37 +64,28 @@ static int add_param(const char *name, size_t namelen, enum parm_info parm_info,
                }
                break;
        }
-
-       return 0;
 }
 
-static int process_parm(enum parm_info parm_info, const char *value, struct param *params,
-                       unsigned int params_count)
+static void process_parm(enum parm_info parm_info, const char *value,
+                        struct param *params, unsigned int params_count)
 {
        const char *name;
-       size_t namelen;
+       int namelen;
        const char *colon = strchr(value, ':');
-       int ret;
 
        if (colon == NULL) {
                ERR("Missing ':' in value \"%s\"\n", value);
-               return 0;
+               return;
        }
 
        if (colon == value) {
                ERR("Missing param name in value \"%s\"\n", value);
-               return 0;
+               return;
        }
 
        name = value;
-       namelen = colon - value;
-       ret = add_param(name, namelen, parm_info, colon + 1, params, params_count);
-       if (ret < 0) {
-               ERR("Unable to add parameter: %s\n", strerror(-ret));
-               return -ENOMEM;
-       }
-
-       return 0;
+       namelen = (int)(colon - value);
+       add_param(name, namelen, parm_info, colon + 1, params, params_count);
 }
 
 static void print_line(const char *key, const char *value)
@@ -234,9 +222,12 @@ static int modinfo_do(struct kmod_module *mod)
                        continue;
                }
 
-               err = process_parm(parm_info, value, params, params_count);
-               if (err < 0)
-                       goto end;
+               if (strlen(value) > INT_MAX) {
+                       ERR("%s's value is longer than INT_MAX\n",
+                           parm_info == parm_desc ? "parm" : "parmtype");
+                       continue;
+               }
+               process_parm(parm_info, value, params, params_count);
        }
 
        for (unsigned int i = 0; i < params_count; i++) {