]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
exec: move warning of null argv to be next to the relevant code
authornir@lichtman.org <nir@lichtman.org>
Sat, 2 Nov 2024 12:01:22 +0000 (14:01 +0200)
committerKees Cook <kees@kernel.org>
Sat, 30 Nov 2024 03:35:58 +0000 (19:35 -0800)
Problem: The warning is currently printed where it is detected that the
arg count is zero but the action is only taken place later in the flow
even though the warning is written as if the action is taken place in
the time of print

This could be problematic since there could be a failure between the
print and the code that takes action which would deem this warning
misleading

Solution: Move the warning print after the action of adding an empty
string as the first argument is successful

Signed-off-by: Nir Lichtman <nir@lichtman.org>
Link: https://lore.kernel.org/r/ZyYUgiPc8A8i_3FH@nirs-laptop.
Signed-off-by: Kees Cook <kees@kernel.org>
fs/exec.c

index 6c53920795c2e70c18c2f220b2a1ea15cf028373..4057b8c3e23391ead12a025b566c867d9a085d4c 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1907,9 +1907,6 @@ static int do_execveat_common(int fd, struct filename *filename,
        }
 
        retval = count(argv, MAX_ARG_STRINGS);
-       if (retval == 0)
-               pr_warn_once("process '%s' launched '%s' with NULL argv: empty string added\n",
-                            current->comm, bprm->filename);
        if (retval < 0)
                goto out_free;
        bprm->argc = retval;
@@ -1947,6 +1944,9 @@ static int do_execveat_common(int fd, struct filename *filename,
                if (retval < 0)
                        goto out_free;
                bprm->argc = 1;
+
+               pr_warn_once("process '%s' launched '%s' with NULL argv: empty string added\n",
+                            current->comm, bprm->filename);
        }
 
        retval = bprm_execve(bprm);