Blame SOURCES/CVE-2021-4034.patch

c51dd0
commit a2bf5c9c83b6ae46cbd5c779d3055bff81ded683
c51dd0
Author: Jan Rybar <jrybar@redhat.com>
c51dd0
Date:   Tue Jan 25 17:21:46 2022 +0000
c51dd0
c51dd0
    pkexec: local privilege escalation (CVE-2021-4034)
c51dd0
c51dd0
diff --git a/src/programs/pkcheck.c b/src/programs/pkcheck.c
c51dd0
index f1bb4e1..768525c 100644
c51dd0
--- a/src/programs/pkcheck.c
c51dd0
+++ b/src/programs/pkcheck.c
c51dd0
@@ -363,6 +363,11 @@ main (int argc, char *argv[])
c51dd0
   local_agent_handle = NULL;
c51dd0
   ret = 126;
c51dd0
 
c51dd0
+  if (argc < 1)
c51dd0
+    {
c51dd0
+      exit(126);
c51dd0
+    }
c51dd0
+
c51dd0
   /* Disable remote file access from GIO. */
c51dd0
   setenv ("GIO_USE_VFS", "local", 1);
c51dd0
 
c51dd0
diff --git a/src/programs/pkexec.c b/src/programs/pkexec.c
c51dd0
index 7698c5c..84e5ef6 100644
c51dd0
--- a/src/programs/pkexec.c
c51dd0
+++ b/src/programs/pkexec.c
c51dd0
@@ -488,6 +488,15 @@ main (int argc, char *argv[])
c51dd0
   pid_t pid_of_caller;
c51dd0
   gpointer local_agent_handle;
c51dd0
 
c51dd0
+
c51dd0
+  /*
c51dd0
+   * If 'pkexec' is called THIS wrong, someone's probably evil-doing. Don't be nice, just bail out.
c51dd0
+   */
c51dd0
+  if (argc<1)
c51dd0
+    {
c51dd0
+      exit(127);
c51dd0
+    }
c51dd0
+
c51dd0
   ret = 127;
c51dd0
   authority = NULL;
c51dd0
   subject = NULL;
c51dd0
@@ -614,10 +623,10 @@ main (int argc, char *argv[])
c51dd0
 
c51dd0
       path = g_strdup (pwstruct.pw_shell);
c51dd0
       if (!path)
c51dd0
-	{
c51dd0
+        {
c51dd0
           g_printerr ("No shell configured or error retrieving pw_shell\n");
c51dd0
           goto out;
c51dd0
-	}
c51dd0
+        }
c51dd0
       /* If you change this, be sure to change the if (!command_line)
c51dd0
 	 case below too */
c51dd0
       command_line = g_strdup (path);
c51dd0
@@ -636,7 +645,15 @@ main (int argc, char *argv[])
c51dd0
           goto out;
c51dd0
         }
c51dd0
       g_free (path);
c51dd0
-      argv[n] = path = s;
c51dd0
+      path = s;
c51dd0
+
c51dd0
+      /* argc<2 and pkexec runs just shell, argv is guaranteed to be null-terminated.
c51dd0
+       * /-less shell shouldn't happen, but let's be defensive and don't write to null-termination
c51dd0
+       */
c51dd0
+      if (argv[n] != NULL)
c51dd0
+      {
c51dd0
+        argv[n] = path;
c51dd0
+      }
c51dd0
     }
c51dd0
   if (access (path, F_OK) != 0)
c51dd0
     {