]> granicus.if.org Git - sudo/commitdiff
Instead of hard-coding a check for bash functions in env_should_delete(),
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 3 Jun 2017 14:43:32 +0000 (08:43 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 3 Jun 2017 14:43:32 +0000 (08:43 -0600)
use a "*=()* " pattern in initial_badenv_table[] to match them instead.
This allows the user to remove the check via env_delete.

doc/sudoers.cat
doc/sudoers.man.in
doc/sudoers.mdoc.in
plugins/sudoers/env.c

index 990b33e7dacd4d9479946562f67413fd32209b65..e6ddd2db954163364c8cc26074e15604fb1b5677 100644 (file)
@@ -130,16 +130,16 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
      _\be_\bn_\bv_\b__\bc_\bh_\be_\bc_\bk and _\be_\bn_\bv_\b__\bk_\be_\be_\bp options.  This is effectively a whitelist for
      environment variables.  Environment variables with a value beginning with
      () are removed unless both the name and value parts are matched by
-     _\be_\bn_\bv_\b__\bk_\be_\be_\bp or _\be_\bn_\bv_\b__\bc_\bh_\be_\bc_\bk, as they will be interpreted as functions by older
-     versions of the b\bba\bas\bsh\bh shell.  Prior to version 1.8.11, such variables were
-     always removed.
+     _\be_\bn_\bv_\b__\bk_\be_\be_\bp or _\be_\bn_\bv_\b__\bc_\bh_\be_\bc_\bk, as they may be interpreted as functions by the
+     b\bba\bas\bsh\bh shell.  Prior to version 1.8.11, such variables were always removed.
 
      If, however, the _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt option is disabled, any variables not
      explicitly denied by the _\be_\bn_\bv_\b__\bc_\bh_\be_\bc_\bk and _\be_\bn_\bv_\b__\bd_\be_\bl_\be_\bt_\be options are inherited
      from the invoking process.  In this case, _\be_\bn_\bv_\b__\bc_\bh_\be_\bc_\bk and _\be_\bn_\bv_\b__\bd_\be_\bl_\be_\bt_\be behave
-     like a blacklist.  Environment variables with a value beginning with ()
-     are always removed, even if they do not match one of the blacklists.
-     Since it is not possible to blacklist all potentially dangerous
+     like a blacklist.  Prior to version 1.8.21, environment variables with a
+     value beginning with () were always removed.  Beginning with version
+     1.8.21, a pattern in _\be_\bn_\bv_\b__\bd_\be_\bl_\be_\bt_\be is used to match b\bba\bas\bsh\bh shell functions
+     instead.  Since it is not possible to blacklist all potentially dangerous
      environment variables, use of the default _\be_\bn_\bv_\b__\br_\be_\bs_\be_\bt behavior is
      encouraged.
 
@@ -149,13 +149,13 @@ D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
 
      By default, environment variables are matched by name.  However, if the
      pattern includes an equal sign (`='), both the variables name and value
-     must match.  For example, an old-style (pre-shellshock) b\bba\bas\bsh\bh shell
-     function could be matched as follows:
+     must match.  For example, a b\bba\bas\bsh\bh shell function could be matched as
+     follows:
 
-         env_keep += "my_func=()*"
+         env_keep += "BASH_FUNC_my_func%%=()*"
 
-     Without the "=()*" suffix, this would not match, as old-style b\bba\bas\bsh\bh shell
-     functions are not preserved by default.
+     Without the "=()*" suffix, this would not match, as b\bba\bas\bsh\bh shell functions
+     are not preserved by default.
 
      The complete list of environment variables that s\bsu\bud\bdo\bo allows or denies is
      contained in the output of "sudo -V" when run as root.  Please note that
@@ -2817,4 +2817,4 @@ D\bDI\bIS\bSC\bCL\bLA\bAI\bIM\bME\bER\bR
      file distributed with s\bsu\bud\bdo\bo or https://www.sudo.ws/license.html for
      complete details.
 
-Sudo 1.8.21                      June 2, 2017                      Sudo 1.8.21
+Sudo 1.8.21                      June 3, 2017                      Sudo 1.8.21
index 3f097f2eeed76d7ce829fcbb062ecbb8b3fb12ac..76d7401638faed9d7d62fe4867ca14bc23a5076e 100644 (file)
@@ -21,7 +21,7 @@
 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\"
-.TH "SUDOERS" "5" "June 2, 2017" "Sudo @PACKAGE_VERSION@" "File Formats Manual"
+.TH "SUDOERS" "5" "June 3, 2017" "Sudo @PACKAGE_VERSION@" "File Formats Manual"
 .nh
 .if n .ad l
 .SH "NAME"
@@ -326,7 +326,7 @@ are removed unless both the name and value parts are matched by
 \fIenv_keep\fR
 or
 \fIenv_check\fR,
-as they will be interpreted as functions by older versions of the
+as they may be interpreted as functions by the
 \fBbash\fR
 shell.
 Prior to version 1.8.11, such variables were always removed.
@@ -345,9 +345,14 @@ In this case,
 and
 \fIenv_delete\fR
 behave like a blacklist.
-Environment variables with a value beginning with
+Prior to version 1.8.21, environment variables with a value beginning with
 \fR()\fR
-are always removed, even if they do not match one of the blacklists.
+were always removed.
+Beginning with version 1.8.21, a pattern in
+\fIenv_delete\fR
+is used to match
+\fBbash\fR
+shell functions instead.
 Since it is not possible
 to blacklist all potentially dangerous environment variables, use
 of the default
@@ -368,19 +373,19 @@ By default, environment variables are matched by name.
 However, if the pattern includes an equal sign
 (\(oq=\&\(cq),
 both the variables name and value must match.
-For example, an old-style (pre-shellshock)
+For example, a
 \fBbash\fR
 shell function could be matched as follows:
 .nf
 .sp
 .RS 4n
-env_keep += "my_func=()*"
+env_keep += "BASH_FUNC_my_func%%=()*"
 .RE
 .fi
 .PP
 Without the
 \(Lq\fR=()*\fR\(Rq
-suffix, this would not match, as old-style
+suffix, this would not match, as
 \fBbash\fR
 shell functions are not preserved by default.
 .PP
index d3245e2eb70da98b30602df184f30d328ab57821..c47ce4d9ed3b2975ac9b72d3382282846da7f5f2 100644 (file)
@@ -19,7 +19,7 @@
 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\"
-.Dd June 2, 2017
+.Dd June 3, 2017
 .Dt SUDOERS @mansectform@
 .Os Sudo @PACKAGE_VERSION@
 .Sh NAME
@@ -315,7 +315,7 @@ are removed unless both the name and value parts are matched by
 .Em env_keep
 or
 .Em env_check ,
-as they will be interpreted as functions by older versions of the
+as they may be interpreted as functions by the
 .Sy bash
 shell.
 Prior to version 1.8.11, such variables were always removed.
@@ -334,9 +334,14 @@ In this case,
 and
 .Em env_delete
 behave like a blacklist.
-Environment variables with a value beginning with
+Prior to version 1.8.21, environment variables with a value beginning with
 .Li ()
-are always removed, even if they do not match one of the blacklists.
+were always removed.
+Beginning with version 1.8.21, a pattern in
+.Em env_delete
+is used to match
+.Sy bash
+shell functions instead.
 Since it is not possible
 to blacklist all potentially dangerous environment variables, use
 of the default
@@ -357,16 +362,16 @@ By default, environment variables are matched by name.
 However, if the pattern includes an equal sign
 .Pq Ql =\& ,
 both the variables name and value must match.
-For example, an old-style (pre-shellshock)
+For example, a
 .Sy bash
 shell function could be matched as follows:
 .Bd -literal -offset 4n
-env_keep += "my_func=()*"
+env_keep += "BASH_FUNC_my_func%%=()*"
 .Ed
 .Pp
 Without the
 .Dq Li =()*
-suffix, this would not match, as old-style
+suffix, this would not match, as
 .Sy bash
 shell functions are not preserved by default.
 .Pp
index 547639e06f97803cdb36157583486119825ec4b2..c23706660413bf15e4f859e150ba5f2032c5731c 100644 (file)
@@ -164,8 +164,7 @@ static const char *initial_badenv_table[] = {
     "PYTHONUSERBASE",          /* python, per user site-packages directory */
     "RUBYLIB",                 /* ruby, library load path */
     "RUBYOPT",                 /* ruby, extra command line options */
-    "BASH_FUNC_*",             /* new-style bash functions */
-    "__BASH_FUNC<*",           /* new-style bash functions (Apple) */
+    "*=()*",                   /* bash functions */
     NULL
 };
 
@@ -692,24 +691,14 @@ matches_env_keep(const char *var, bool *full_match)
 static bool
 env_should_delete(const char *var)
 {
-    const char *cp;
     int delete_it;
     bool full_match = false;
     debug_decl(env_should_delete, SUDOERS_DEBUG_ENV);
 
-    /* Skip variables with values beginning with () (bash functions) */
-    if ((cp = strchr(var, '=')) != NULL) {
-       if (strncmp(cp, "=() ", 4) == 0) {
-           delete_it = true;
-           goto done;
-       }
-    }
-
     delete_it = matches_env_delete(var);
     if (!delete_it)
        delete_it = matches_env_check(var, &full_match) == false;
 
-done:
     sudo_debug_printf(SUDO_DEBUG_INFO, "delete %s: %s",
        var, delete_it ? "YES" : "NO");
     debug_return_bool(delete_it);