dyndbg: fix use before null check
authorJim Cromie <jim.cromie@gmail.com>
Wed, 9 Dec 2020 18:36:25 +0000 (11:36 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 9 Dec 2020 19:10:12 +0000 (20:10 +0100)
In commit a2d375eda771 ("dyndbg: refine export, rename to
dynamic_debug_exec_queries()"), a string is copied before checking it
isn't NULL.  Fix this, report a usage/interface error, and return the
proper error code.

Fixes: a2d375eda771 ("dyndbg: refine export, rename to dynamic_debug_exec_queries()")
Cc: stable@vger.kernel.org
--
-v2 drop comment tweak, improve commit message

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Link: https://lore.kernel.org/r/20201209183625.2432329-1-jim.cromie@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
lib/dynamic_debug.c

index bd7b3aaa93c380fe29519ca70ae640dea409d814..c70d6347afa2b4ba2900752a3704bab879880ce3 100644 (file)
@@ -561,9 +561,14 @@ static int ddebug_exec_queries(char *query, const char *modname)
 int dynamic_debug_exec_queries(const char *query, const char *modname)
 {
        int rc;
-       char *qry = kstrndup(query, PAGE_SIZE, GFP_KERNEL);
+       char *qry; /* writable copy of query */
 
-       if (!query)
+       if (!query) {
+               pr_err("non-null query/command string expected\n");
+               return -EINVAL;
+       }
+       qry = kstrndup(query, PAGE_SIZE, GFP_KERNEL);
+       if (!qry)
                return -ENOMEM;
 
        rc = ddebug_exec_queries(qry, modname);