CVE-2021-4034.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. From a2bf5c9c83b6ae46cbd5c779d3055bff81ded683 Mon Sep 17 00:00:00 2001
  2. From: Jan Rybar <jrybar@redhat.com>
  3. Date: Tue, 25 Jan 2022 17:21:46 +0000
  4. Subject: [PATCH] pkexec: local privilege escalation (CVE-2021-4034)
  5. ---
  6. src/programs/pkcheck.c | 5 +++++
  7. src/programs/pkexec.c | 23 ++++++++++++++++++++---
  8. 2 files changed, 25 insertions(+), 3 deletions(-)
  9. diff --git a/src/programs/pkcheck.c b/src/programs/pkcheck.c
  10. index f1bb4e1..768525c 100644
  11. --- a/src/programs/pkcheck.c
  12. +++ b/src/programs/pkcheck.c
  13. @@ -363,6 +363,11 @@ main (int argc, char *argv[])
  14. local_agent_handle = NULL;
  15. ret = 126;
  16. + if (argc < 1)
  17. + {
  18. + exit(126);
  19. + }
  20. +
  21. /* Disable remote file access from GIO. */
  22. setenv ("GIO_USE_VFS", "local", 1);
  23. diff --git a/src/programs/pkexec.c b/src/programs/pkexec.c
  24. index 7698c5c..84e5ef6 100644
  25. --- a/src/programs/pkexec.c
  26. +++ b/src/programs/pkexec.c
  27. @@ -488,6 +488,15 @@ main (int argc, char *argv[])
  28. pid_t pid_of_caller;
  29. gpointer local_agent_handle;
  30. +
  31. + /*
  32. + * If 'pkexec' is called THIS wrong, someone's probably evil-doing. Don't be nice, just bail out.
  33. + */
  34. + if (argc<1)
  35. + {
  36. + exit(127);
  37. + }
  38. +
  39. ret = 127;
  40. authority = NULL;
  41. subject = NULL;
  42. @@ -614,10 +623,10 @@ main (int argc, char *argv[])
  43. path = g_strdup (pwstruct.pw_shell);
  44. if (!path)
  45. - {
  46. + {
  47. g_printerr ("No shell configured or error retrieving pw_shell\n");
  48. goto out;
  49. - }
  50. + }
  51. /* If you change this, be sure to change the if (!command_line)
  52. case below too */
  53. command_line = g_strdup (path);
  54. @@ -636,7 +645,15 @@ main (int argc, char *argv[])
  55. goto out;
  56. }
  57. g_free (path);
  58. - argv[n] = path = s;
  59. + path = s;
  60. +
  61. + /* argc<2 and pkexec runs just shell, argv is guaranteed to be null-terminated.
  62. + * /-less shell shouldn't happen, but let's be defensive and don't write to null-termination
  63. + */
  64. + if (argv[n] != NULL)
  65. + {
  66. + argv[n] = path;
  67. + }
  68. }
  69. if (access (path, F_OK) != 0)
  70. {
  71. --
  72. GitLab