Package: release.debian.org
Severity: normal
Tags: trixie
X-Debbugs-Cc: [email protected]
Control: affects -1 + src:sudo
User: [email protected]
Usertags: pu

This upload fixe a segfault regression introduced by the 13.8 point 
release. This probably warrants a fasttrack-update via trixie-updates 
and a corresponding advisory. If you disagree, please consider this 
upload for 13.9. Same reasons.

[ Reason ]
sudo 1.9.16p2-3+deb13u5 has a regression bug and segfaults if the 
environment is empty. reproducer: env -i sudo id.

[ Impact ]
sudo segfaults if called with empty environment. emptying the 
environment is a common idiom in security-aware scripts.

A segfault in an suid binary is almost always a bad news. However, 
upstream agrees with the Debian security team that this doesnt warrant a 
security release.

[ Tests ]
This update includes a new autopkgtest part that checks sudo with empty 
environment. It is verified to fail in sudo 1.9.16p2-3+deb13u5 and to 
pass with this patch.

[ Risks ]
The patch could be buggy as welll.

[ Checklist ]
  [x] *all* changes are documented in the d/changelog
  [x] I reviewed all changes and I approve them
  [x] attach debdiff against the package in (old)stable
  [x] the issue is verified as fixed in unstable

[ Changes ]
Add patch to fix the issue
Add autopkgtest that checks for the issue.
diff -Nru sudo-1.9.16p2/debian/changelog sudo-1.9.16p2/debian/changelog
--- sudo-1.9.16p2/debian/changelog      2026-09-29 16:02:29.000000000 +0200
+++ sudo-1.9.16p2/debian/changelog      2026-11-25 07:26:49.000000000 +0100
@@ -1,3 +1,11 @@
+sudo (1.9.16p2-3+deb13u6) trixie; urgency=medium
+
+  * add autopkgtest to test sudo with empty environment
+  * add upstream patch: always copy envp, even when it is empty.
+    Thanks to Michael Kriese (Closes: #1154725)
+
+ -- Marc Haber <[email protected]>  Wed, 25 Nov 2026 07:26:49 
+0100
+
 sudo (1.9.16p2-3+deb13u5) trixie; urgency=medium
 
   * bump version number to allow git-debpush to work again
diff -Nru 
sudo-1.9.16p2/debian/patches/0014-os_init_common-always-copy-envp-even-when-it-is-empt.patch
 
sudo-1.9.16p2/debian/patches/0014-os_init_common-always-copy-envp-even-when-it-is-empt.patch
--- 
sudo-1.9.16p2/debian/patches/0014-os_init_common-always-copy-envp-even-when-it-is-empt.patch
        1970-01-01 01:00:00.000000000 +0100
+++ 
sudo-1.9.16p2/debian/patches/0014-os_init_common-always-copy-envp-even-when-it-is-empt.patch
        2026-11-25 07:26:33.000000000 +0100
@@ -0,0 +1,48 @@
+From: Michael Kriese <[email protected]>
+Date: Mon, 23 Nov 2026 13:16:34 +0100
+Subject: os_init_common: always copy envp, even when it is empty
+
+Since 194042b, submit_envp is only allocated when the environment
+is not empty.  With an empty environment (e.g. "env -i sudo true")
+it stays NULL and the plugins get a NULL envp, which makes sudoers.so
+crash with a NULL pointer dereference.  Allocate the copy
+unconditionally so plugins always get a NULL-terminated array.
+
+Co-Authored-By: Claude Opus 5.5 <[email protected]>
+---
+ src/sudo.c | 18 +++++++++---------
+ 1 file changed, 9 insertions(+), 9 deletions(-)
+
+diff --git a/src/sudo.c b/src/sudo.c
+index de7e809..93a3c50 100644
+--- a/src/sudo.c
++++ b/src/sudo.c
+@@ -375,19 +375,19 @@ os_init_common(int argc, char *argv[], char *envp[])
+      * Make a shallow copy of envp[] and store in submit_envp[].
+      * This allows us to remove variables from sudo's environment
+      * while still providing the original envp to the plugins.
++     * The copy is made even for an empty environment since the
++     * plugins expect a non-NULL envp.
+      */
+     for (envc = 0; envp[envc] != NULL; envc++)
+       continue;
+-    if (envc != 0) {
+-      submit_envp = reallocarray(NULL, sizeof(char *), envc + 1);
+-      if (submit_envp == NULL || !gc_add(GC_PTR, submit_envp)) {
+-          sudo_fatalx_nodebug(U_("%s: %s"), __func__,
+-              U_("unable to allocate memory"));
+-      }
+-      for (envc = 0; envp[envc] != NULL; envc++)
+-          submit_envp[envc] = envp[envc];
+-      submit_envp[envc] = NULL;
++    submit_envp = reallocarray(NULL, sizeof(char *), envc + 1);
++    if (submit_envp == NULL || !gc_add(GC_PTR, submit_envp)) {
++      sudo_fatalx_nodebug(U_("%s: %s"), __func__,
++          U_("unable to allocate memory"));
+     }
++    for (envc = 0; envp[envc] != NULL; envc++)
++      submit_envp[envc] = envp[envc];
++    submit_envp[envc] = NULL;
+ 
+     return 0;
+ }
diff -Nru sudo-1.9.16p2/debian/patches/series 
sudo-1.9.16p2/debian/patches/series
--- sudo-1.9.16p2/debian/patches/series 2026-09-29 16:02:29.000000000 +0200
+++ sudo-1.9.16p2/debian/patches/series 2026-11-25 07:26:33.000000000 +0100
@@ -11,3 +11,4 @@
 0011-sudo-ignore-user-specified-TZ-environment-variable.patch
 0012-Remove-TZ-from-sudo-s-working-environment-without-mo.patch
 0013-Copy-envp-submit_envp-instead-of-replacing-the-envir.patch
+0014-os_init_common-always-copy-envp-even-when-it-is-empt.patch
diff -Nru sudo-1.9.16p2/debian/tests/01-getroot 
sudo-1.9.16p2/debian/tests/01-getroot
--- sudo-1.9.16p2/debian/tests/01-getroot       2026-09-29 16:02:29.000000000 
+0200
+++ sudo-1.9.16p2/debian/tests/01-getroot       2026-11-25 07:26:33.000000000 
+0100
@@ -96,5 +96,21 @@
   fi
 done
 
-printf "test series sucessful, exit 0\n"
+printf "========= test %s\.4: account group member, empty sudo environment\n" 
"${TESTNR}"
+rm -f "${HOMEDIRA}/std*"
+RET=0
+printf "trying %s with empty sudo environment\n" "${ACCTA}"
+su - "${ACCTA}" -c "ASUSER_EMPTY_ENV=1 ${COMMONDIR}/asuser ${PASSWD}" || RET=$?
+printf "%s with empty sudo environment, return value %s\n" "${ACCTA}" "${RET}"
+if [ "$(cat ${HOMEDIRA}/stdout)" != "0" ]; then
+  echo >&2 "id -u did not give 0"
+  printf >&2 "stdout:\n"
+  cat >&2 "${HOMEDIRA}/stdout"
+  printf >&2 "stderr:\n"
+  cat >&2 "${HOMEDIRA}/stderr"
+  printf >&2 "exit code %s\n" "${RET}"
+  exit 1
+fi
+
+printf "test series successful, exit 0\n"
 exit 0
diff -Nru sudo-1.9.16p2/debian/tests/common/asuser 
sudo-1.9.16p2/debian/tests/common/asuser
--- sudo-1.9.16p2/debian/tests/common/asuser    2026-09-29 16:02:29.000000000 
+0200
+++ sudo-1.9.16p2/debian/tests/common/asuser    2026-11-25 07:26:33.000000000 
+0100
@@ -2,6 +2,9 @@
 
 set -e
 
-echo "${1:-}" | sudo -u "${2:-root}" --stdin id -u > "${3:-stdout}" 2> 
"${4:-stderr}"
-
+ENVI=""
+if [[ "${ASUSER_EMPTY_ENV:-}" = 1 ]]; then
+  ENVI="env -i"
+fi
 
+echo "${1:-}" | ${ENVI} /usr/bin/sudo -u "${2:-root}" --stdin id -u > 
"${3:-stdout}" 2> "${4:-stderr}"

Reply via email to