From d401b76a863386f9064637c71b66837805f82881 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Thu, 13 Aug 2026 08:35:31 +0000 Subject: [PATCH 1/2] init: fix command injection in bash Tab completion (compgen -W expansion) _module_comgen_words_and_files() fed untrusted text (module names read off disk, LOADEDMODULES, MODULEPATH) straight into `compgen -W`, which performs a full unquoted-word expansion on its wordlist -- including command substitution -- as a normal, documented part of its behavior. A module name, loaded-module entry, or MODULEPATH component containing e.g. `$(...)` therefore ran arbitrary shell code the moment a user pressed Tab. Fix: never hand candidate text to `compgen -W`. The new _module_comgen_words() splits the candidate list with `read -r -d ''` (pure IFS word-splitting, no expansion of any kind) and does the prefix match itself; _module_comgen_words_and_files() now layers the nospace-for-directory-entries behavior on top of it. Every call site that previously built a compgen -W wordlist from LOADEDMODULES, MODULEPATH, or a stash/save collection name now goes through one of these two functions instead. Fixes CVE-2026-85013 Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Xavier Delaruelle --- .hunspell.en.dic | 5 ++++ init/bash_completion.in | 51 ++++++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/.hunspell.en.dic b/.hunspell.en.dic index 583cbd839..c3e234de4 100644 --- a/.hunspell.en.dic +++ b/.hunspell.en.dic @@ -284,6 +284,7 @@ chemappB chempappB chgrp chmod +claude cleanupAndExit cmake cmd @@ -319,11 +320,13 @@ cmdstring codecov codespell collectModuleTag +comgen commandexp commandname compA compB compat +compgen compilerTag compopt config @@ -639,6 +642,7 @@ nonpersist noop nop noparse +nospace notavail nothreads notuasked @@ -873,6 +877,7 @@ unsetState unsetenv unsets unsetting +untrusted unuse unusing updateInstead diff --git a/init/bash_completion.in b/init/bash_completion.in index 9cef0eacd..94dd7c496 100644 --- a/init/bash_completion.in +++ b/init/bash_completion.in @@ -2,17 +2,30 @@ # # Bash commandline completion # +_module_comgen_words() { + local -a words + local val + # split candidate list on IFS without triggering shell expansion (command + # substitution, arithmetic, ...): candidate words may come from module + # names read off disk, which must never be treated as executable code + IFS=$' \t\n' read -r -d '' -a words <<<"$1" + for val in "${words[@]}"; do + case "$val" in + "$2"*) COMPREPLY[${#COMPREPLY[@]}]="$val" ;; + esac + done +} + _module_comgen_words_and_files() { - local k=0 - local setnospace=1 + local start=${#COMPREPLY[@]} i + _module_comgen_words "$1" "$2" # do not append space to word completed if it is a directory (ends with /) - for val in $(compgen -W "$1" -- "$2"); do - if [ $setnospace -eq 1 ] && [ "${val: -1:1}" = '/' ]; then + for ((i = start; i < ${#COMPREPLY[@]}; i++)); do + if [ "${COMPREPLY[i]: -1:1}" = '/' ]; then # Bash >=4.0 is required for compopt type compopt &>/dev/null && compopt -o nospace - setnospace=0 + break fi - COMPREPLY[k++]="$val" done } @@ -64,7 +77,7 @@ _module_long_arg_list() { _module_comgen_words_and_files "$(_module_not_yet_loaded "$cur")" "$cur" break;; rm|del|remove|unload|switch|swap) - COMPREPLY=( $(IFS=: compgen -W "${LOADEDMODULES}" -- "$cur") ) + _module_comgen_words "${LOADEDMODULES//:/ }" "$cur" break;; esac done @@ -85,14 +98,14 @@ _module() { list|savelist) COMPREPLY=( $(compgen -W "@comp_list_opts@" -- "$cur") );; stashlist) COMPREPLY=( $(compgen -W "@comp_stashlist_opts@" -- "$cur") );; stashpop|stashshow|stashrm) - COMPREPLY=( $(compgen -W "$(_module_stashlist)" -- "$cur") );; + _module_comgen_words "$(_module_stashlist)" "$cur";; clear) COMPREPLY=( $(compgen -W "@comp_clear_opts@" -- "$cur") );; restore|save|saveshow|describe|saverm|disable|is-saved) - COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") );; + _module_comgen_words "$(_module_savelist)" "$cur";; rm|del|remove|unload) - COMPREPLY=( $(compgen -W "@comp_unload_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );; - switch|swap) COMPREPLY=( $(compgen -W "@comp_load_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );; - unuse|is-used) COMPREPLY=( $(IFS=: compgen -W "${MODULEPATH}" -- "$cur") );; + _module_comgen_words "@comp_unload_opts@ ${LOADEDMODULES//:/ }" "$cur";; + switch|swap) _module_comgen_words "@comp_load_opts@ ${LOADEDMODULES//:/ }" "$cur";; + unuse|is-used) _module_comgen_words "${MODULEPATH//:/ }" "$cur";; use|-a|--append|cachebuild) ;; # let readline handle the completion display|help|show|test|path|paths|is-loaded|info-loaded) _module_comgen_words_and_files "@comp_mfile_opts@ $(_module_avail "$cur")" "$cur";; @@ -148,14 +161,14 @@ if type -t ml >/dev/null; then list|savelist) COMPREPLY=( $(compgen -W "@comp_list_opts@" -- "$cur") );; stashlist) COMPREPLY=( $(compgen -W "@comp_stashlist_opts@" -- "$cur") );; stashpop|stashshow|stashrm) - COMPREPLY=( $(compgen -W "$(_module_stashlist)" -- "$cur") );; + _module_comgen_words "$(_module_stashlist)" "$cur";; clear) COMPREPLY=( $(compgen -W "@comp_clear_opts@" -- "$cur") );; restore|save|saveshow|describe|saverm|disable|is-saved) - COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") );; + _module_comgen_words "$(_module_savelist)" "$cur";; rm|del|remove|unload) - COMPREPLY=( $(compgen -W "@comp_unload_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );; - switch|swap) COMPREPLY=( $(compgen -W "@comp_load_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );; - unuse|is-used) COMPREPLY=( $(IFS=: compgen -W "${MODULEPATH}" -- "$cur") );; + _module_comgen_words "@comp_unload_opts@ ${LOADEDMODULES//:/ }" "$cur";; + switch|swap) _module_comgen_words "@comp_load_opts@ ${LOADEDMODULES//:/ }" "$cur";; + unuse|is-used) _module_comgen_words "${MODULEPATH//:/ }" "$cur";; use|-a|--append|cachebuild) ;; # let readline handle the completion display|help|show|test|path|paths|is-loaded|info-loaded) _module_comgen_words_and_files "@comp_mfile_opts@ $(_module_avail "$cur")" "$cur";; @@ -192,14 +205,14 @@ if type -t ml >/dev/null; then for i in ${LOADEDMODULES//:/ }; do loaded_modules+="-${i} " done - COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_load_opts@ $loaded_modules" -- "$cur") );; + _module_comgen_words "@comp_load_opts@ $loaded_modules" "$cur";; *) _module_comgen_words_and_files "@comp_load_opts@ $(_module_not_yet_loaded "$cur")" "$cur" COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur") ) loaded_modules="" for i in ${LOADEDMODULES//:/ }; do loaded_modules+="-${i} " done - COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_load_opts@ $loaded_modules" -- "$cur") );; + _module_comgen_words "@comp_load_opts@ $loaded_modules" "$cur";; esac fi;; esac From 0acf5326e7de643611af5365fa2cf65b6a6f01c5 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Mon, 7 Sep 2026 06:49:48 +0200 Subject: [PATCH 2/2] Release of version 5.6.2 Signed-off-by: Xavier Delaruelle --- .hunspell.en.dic | 1 + NEWS.rst | 11 +++++++++++ doc/source/conf.py | 2 +- share/rpm/environment-modules.spec.in | 5 ++++- version.inc.in | 2 +- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.hunspell.en.dic b/.hunspell.en.dic index c3e234de4..254d21713 100644 --- a/.hunspell.en.dic +++ b/.hunspell.en.dic @@ -1307,3 +1307,4 @@ Reproducibility rebase reproducibility latexpdf +CVE diff --git a/NEWS.rst b/NEWS.rst index 00f305692..9b657f57e 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -8,6 +8,17 @@ documents those changes that are of interest to users and admins. .. _5.6 release notes: +Modules 5.6.2 (2026-09-07) +-------------------------- + +* Init: fix command injection in Bash completion when module names contain + shell meta-characters. Completion candidates were passed to ``compgen -W`` + which evaluates command substitution syntax. (fix `CVE-2026-85013`_ found + by AISLE in partnership with Red Hat) + +.. _CVE-2026-85013: https://github.com/envmodules/modules/security/advisories/GHSA-8hrw-p88g-qhmg + + Modules 5.6.1 (2025-11-25) -------------------------- diff --git a/doc/source/conf.py b/doc/source/conf.py index 72582a655..6dbafa5f8 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -79,7 +79,7 @@ def get_version_release_from_git(): else: return version, version + '+' + branch + '-' + tags else: - return '5.6.1', '' + return '5.6.2', '' # The short X.Y version. # The full version, including alpha/beta/rc tags. diff --git a/share/rpm/environment-modules.spec.in b/share/rpm/environment-modules.spec.in index f2ba72492..100510980 100644 --- a/share/rpm/environment-modules.spec.in +++ b/share/rpm/environment-modules.spec.in @@ -6,7 +6,7 @@ %endif Name: environment-modules -Version: 5.6.1 +Version: 5.6.2 Release: @MODULES_RPM_RELEASE@%{?dist} Summary: Provides dynamic modification of a user's environment @@ -266,6 +266,9 @@ fi %changelog +* Mon Sep 07 2026 Xavier Delaruelle - 5.6.2-1 +- Update to 5.6.2 (fix CVE-2026-85013) + * Tue Nov 25 2025 Xavier Delaruelle - 5.6.1-1 - Update to 5.6.1 - Update-alternatives is now available from _bindir diff --git a/version.inc.in b/version.inc.in index 99570462d..bb6ff2e97 100644 --- a/version.inc.in +++ b/version.inc.in @@ -1,7 +1,7 @@ # Release definitions shared across the Makefiles of this project # run make to generate version.inc -MODULES_RELEASE := 5.6.1 +MODULES_RELEASE := 5.6.2 MODULES_BUILD_HASH := $Format:%h$ MODULES_BUILD_REFS := $Format:%D$ MODULES_BUILD_FDATE := $Format:%ci$