|
10 | 10 | # Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr |
11 | 11 | # |
12 | 12 | # Description: Testuite testsequence |
13 | | -# Command: avail, load, unload, ml, use, unuse, restore |
| 13 | +# Command: avail, load, unload, ml, use, unuse, restore, switch |
14 | 14 | # Sub-Command: |
15 | 15 | # |
16 | 16 | # Comment: %C{ |
|
26 | 26 | # 'ml' Tab-completion proposes is checked against the |
27 | 27 | # ground truth fetched from 'module help' (see |
28 | 28 | # 007-module_help.exp) and 'module config' (see |
29 | | -# 008-module_config.exp) -- neither less nor more |
| 29 | +# 008-module_config.exp) -- neither less nor more, and |
| 30 | +# completion candidate words built from untrusted text |
| 31 | +# (module names read off disk, LOADEDMODULES, |
| 32 | +# MODULEPATH) cannot reach a shell expansion step -- a |
| 33 | +# candidate embedding shell code must be listed as an |
| 34 | +# inert string, never executed |
30 | 35 | # }C% |
31 | 36 | # |
32 | 37 | ############################################################################## |
@@ -480,6 +485,75 @@ completion_bash_close |
480 | 485 | unsetenv_loaded_module |
481 | 486 |
|
482 | 487 |
|
| 488 | +# |
| 489 | +# candidate words built from untrusted text cannot reach a shell expansion |
| 490 | +# step (see security fix for the bash-completion command injection) |
| 491 | +# |
| 492 | + |
| 493 | +set marker "$env(TESTSUITEDIR)/completion-injection-marker" |
| 494 | +file delete -force $marker |
| 495 | + |
| 496 | +# module/spider avail: malicious module name read off disk |
| 497 | + |
| 498 | +# the marker path is passed through as an env var rather than embedded |
| 499 | +# directly in the filename, since a filename cannot itself contain '/' |
| 500 | +setenv_var INJMARKER $marker |
| 501 | +set evilname {evil$(touch>$INJMARKER)} |
| 502 | +file mkdir $injectdir |
| 503 | +set fd [open "$injectdir/$evilname" w] |
| 504 | +puts $fd {#%Module1.0} |
| 505 | +close $fd |
| 506 | + |
| 507 | +setenv_path_var MODULEPATH $injectdir |
| 508 | + |
| 509 | +completion_bash_start |
| 510 | + |
| 511 | +set got [completion_bash_list {module load }] |
| 512 | +completion_assert_no_exec $marker |
| 513 | +completion_assert_contains $got [list $evilname] |
| 514 | + |
| 515 | +completion_bash_close |
| 516 | +unsetenv_path_var MODULEPATH |
| 517 | +unsetenv_var INJMARKER |
| 518 | +file delete -force $injectdir |
| 519 | + |
| 520 | +# LOADEDMODULES: malicious already-loaded module name |
| 521 | + |
| 522 | +set evilmod [string map [list MARKERPATH $marker] {python$(touch>MARKERPATH)}] |
| 523 | +# _LMFILES_ is set consistently alongside LOADEDMODULES (matching entry |
| 524 | +# count) purely to avoid an unrelated "inconsistent state" warning; its |
| 525 | +# content is not used by the completion script |
| 526 | +setenv_loaded_module [list gcc $evilmod] [list /fake/gcc /fake/evilmod] |
| 527 | + |
| 528 | +completion_bash_start |
| 529 | + |
| 530 | +set got [completion_bash_list {module unload }] |
| 531 | +completion_assert_no_exec $marker |
| 532 | +completion_assert_contains $got [list $evilmod] |
| 533 | + |
| 534 | +completion_bash_close |
| 535 | +unsetenv_loaded_module |
| 536 | + |
| 537 | +# MODULEPATH: malicious path entry (module unuse) |
| 538 | + |
| 539 | +set evilpath [string map [list MARKERPATH $marker] {/opt$(touch>MARKERPATH)}] |
| 540 | +setenv_path_var MODULEPATH /tmp $evilpath |
| 541 | + |
| 542 | +completion_bash_start |
| 543 | + |
| 544 | +## both entries share a leading '/', so type it explicitly: otherwise |
| 545 | +## readline auto-inserts that common prefix on the first Tab and the |
| 546 | +## double-Tab below would only ring the bell instead of listing |
| 547 | +set got [completion_bash_list {module unuse /}] |
| 548 | +completion_assert_no_exec $marker |
| 549 | +completion_assert_contains $got [list $evilpath] |
| 550 | + |
| 551 | +completion_bash_close |
| 552 | +unsetenv_path_var MODULEPATH |
| 553 | + |
| 554 | +file delete -force $marker |
| 555 | + |
| 556 | + |
483 | 557 | # |
484 | 558 | # Cleanup |
485 | 559 | # |
|
0 commit comments