On Linux execve() can be called with a NULL argv, which results in argc being set to zero and an empty list for argv. Doing so causes the polkit applications to misbehave, for example: $ python >>> import os >>> os.execve("/usr/bin/pkexec", [], {"FOO":"aaaaaaaaa"}) Cannot run program FOO=aaaaaaaaa: No such file or directory While this doesn't appear to have an further impact, setuid binaries should be hardened against any possible misuse. Add an explicit check for argc == 0 to all of the polkit applications. Signed-off-by: Ryan Mallon --- src/programs/pkaction.c | 10 ++++++++++ src/programs/pkcheck.c | 10 ++++++++++ src/programs/pkexec.c | 10 ++++++++++ src/programs/pkttyagent.c | 10 ++++++++++ 4 files changed, 40 insertions(+) diff --git a/src/programs/pkaction.c b/src/programs/pkaction.c index f17a7dc..1034a82 100644 --- a/src/programs/pkaction.c +++ b/src/programs/pkaction.c @@ -121,6 +121,16 @@ main (int argc, char *argv[]) actions = NULL; ret = 1; + /* + * Linux allows an empty list to be passed for argv. This is a non-standard + * (mis)feature, so don't allow it. + */ + if (argc == 0) + { + g_printerr("Refusing to accept empty argv\n"); + goto out; + } + g_type_init (); opt_show_version = FALSE; diff --git a/src/programs/pkcheck.c b/src/programs/pkcheck.c index 5781893..c2352e3 100644 --- a/src/programs/pkcheck.c +++ b/src/programs/pkcheck.c @@ -362,6 +362,16 @@ main (int argc, char *argv[]) local_agent_handle = NULL; ret = 126; + /* + * Linux allows an empty list to be passed for argv. This is a non-standard + * (mis)feature, so don't allow it. + */ + if (argc == 0) + { + g_printerr("Refusing to accept empty argv\n"); + goto out; + } + g_type_init (); details = polkit_details_new (); diff --git a/src/programs/pkexec.c b/src/programs/pkexec.c index a7ca8e0..88363c0 100644 --- a/src/programs/pkexec.c +++ b/src/programs/pkexec.c @@ -502,6 +502,16 @@ main (int argc, char *argv[]) opt_user = NULL; local_agent_handle = NULL; + /* + * Linux allows an empty list to be passed for argv. This is a non-standard + * (mis)feature, so don't allow it. + */ + if (argc == 0) + { + g_printerr("Refusing to accept empty argv\n"); + goto out; + } + /* check for correct invocation */ if (geteuid () != 0) { diff --git a/src/programs/pkttyagent.c b/src/programs/pkttyagent.c index 423b728..ed3caa5 100644 --- a/src/programs/pkttyagent.c +++ b/src/programs/pkttyagent.c @@ -74,6 +74,16 @@ main (int argc, char *argv[]) guint ret = 126; GVariantBuilder builder; + /* + * Linux allows an empty list to be passed for argv. This is a non-standard + * (mis)feature, so don't allow it. + */ + if (argc == 0) + { + g_printerr("Refusing to accept empty argv\n"); + goto out; + } + g_type_init (); error = NULL; -- 1.7.9.7