execve: Use interp in shebang as is

Fujitsu: POSTK_DEBUG_TEMP_FIX_9
Refs: #995
Change-Id: I09751d13c4fecd68087d47815029c0b65e51f18a
This commit is contained in:
Ken Sato
2018-07-04 14:04:31 +09:00
committed by Masamichi Takagi
parent f1a40a409f
commit b920da5103
7 changed files with 265 additions and 8 deletions

View File

@ -3771,22 +3771,14 @@ fork_err:
goto return_execve1;
}
#ifdef POSTK_DEBUG_TEMP_FIX_9 /* shell-script run via execve arg[0] fix */
if (strlen(shell) >= SHELL_PATH_MAX_LEN) {
#else /* POSTK_DEBUG_TEMP_FIX_9 */
if (strlen(shell_path) >= SHELL_PATH_MAX_LEN) {
#endif /* POSTK_DEBUG_TEMP_FIX_9 */
fprintf(stderr, "execve(): error: shell path too long: %s\n", shell_path);
ret = ENAMETOOLONG;
goto return_execve1;
}
/* Let the LWK know the shell interpreter */
#ifdef POSTK_DEBUG_TEMP_FIX_9 /* shell-script run via execve arg[0] fix */
strcpy(desc->shell_path, shell);
#else /* POSTK_DEBUG_TEMP_FIX_9 */
strcpy(desc->shell_path, shell_path);
#endif /* POSTK_DEBUG_TEMP_FIX_9 */
}
desc->enable_vdso = enable_vdso;

117
test/issues/995/C995.sh Normal file
View File

@ -0,0 +1,117 @@
#!/bin/sh
BIN=
SBIN=
LTP=
BOOTPARAM="-c 1-7,9-15,17-23,25-31 -m 10G@0,10G@1 -r 1-7:0+9-15:8+17-23:16+25-31:24"
if [ -f ../../../config.h ]; then
str=`grep "^#define BINDIR " ../../../config.h | head -1 | sed 's/^#define BINDIR /BINDIR=/'`
eval $str
fi
if [ "x$BINDIR" = x ];then
BINDIR="$BIN"
fi
if [ -f ../../../Makefile ]; then
str=`grep ^SBINDIR ../../../Makefile | head -1 | sed 's/ //g'`
eval $str
fi
if [ "x$SBINDIR" = x ];then
SBINDIR="$SBIN"
fi
if [ -f $HOME/ltp/testcases/bin/execve01 ]; then
LTPDIR=$HOME/ltp/testcases
fi
if [ "x$LTPDIR" = x ]; then
LTPDIR="$LTP/testcases"
fi
if [ ! -x $SBINDIR/mcstop+release.sh ]; then
echo mcstop+release: not found >&2
exit 1
fi
echo -n "mcstop+release.sh ... "
sudo $SBINDIR/mcstop+release.sh
echo "done"
if [ ! -x $SBINDIR/mcreboot.sh ]; then
echo mcreboot: not found >&2
exit 1
fi
echo -n "mcreboot.sh $BOOTPARAM ... "
sudo $SBINDIR/mcreboot.sh $BOOTPARAM
echo "done"
if [ ! -x $BINDIR/mcexec ]; then
echo mcexec: not found >&2
exit 1
fi
tid=001
echo "*** RT_$tid start *******************************"
sudo $BINDIR/mcexec ./call_execve ./test_01.sh | tee ./RT_${tid}.txt
if grep "argv\[0\]: ./syml_put_args" ./RT_${tid}.txt > /dev/null 2>&1 ; then
echo "*** RT_$tid: PASSED"
else
echo "*** RT_$tid: FAILED"
fi
echo ""
tid=002
echo "*** RT_$tid start *******************************"
sudo $BINDIR/mcexec ./call_execve ./test_02.sh | tee ./RT_${tid}.txt
if grep "argv\[0\]: `pwd`/syml_put_args" ./RT_${tid}.txt > /dev/null 2>&1 ; then
echo "*** RT_$tid: PASSED"
else
echo "*** RT_$tid: FAILED"
fi
echo ""
tid=001
echo "*** LT_$tid start *******************************"
sudo PATH=$LTPDIR/bin:${PATH} $BINDIR/mcexec $LTPDIR/bin/execve01 2>&1 | tee ./LT_${tid}.txt
ok=`grep TPASS LT_${tid}.txt | wc -l`
ng=`grep TFAIL LT_${tid}.txt | wc -l`
if [ $ng = 0 ]; then
echo "*** LT_$tid: PASSED (ok:$ok)"
else
echo "*** LT_$tid: FAILED (ok:$ok, ng:$ng)"
fi
echo ""
tid=002
echo "*** LT_$tid start *******************************"
sudo PATH=$LTPDIR/bin:${PATH} $BINDIR/mcexec $LTPDIR/bin/execve02 2>&1 | tee ./LT_${tid}.txt
ok=`grep TPASS LT_${tid}.txt | wc -l`
ng=`grep TFAIL LT_${tid}.txt | wc -l`
if [ $ng = 0 ]; then
echo "*** LT_$tid: PASSED (ok:$ok)"
else
echo "*** LT_$tid: FAILED (ok:$ok, ng:$ng)"
fi
echo ""
tid=003
echo "*** LT_$tid start *******************************"
sudo PATH=$LTPDIR/bin:${PATH} $BINDIR/mcexec $LTPDIR/bin/execve03 2>&1 | tee ./LT_${tid}.txt
ok=`grep TPASS LT_${tid}.txt | wc -l`
ng=`grep TFAIL LT_${tid}.txt | wc -l`
if [ $ng = 0 ]; then
echo "*** LT_$tid: PASSED (ok:$ok)"
else
echo "*** LT_$tid: FAILED (ok:$ok, ng:$ng)"
fi
echo ""
tid=004
echo "*** LT_$tid start *******************************"
sudo PATH=$LTPDIR/bin:${PATH} $BINDIR/mcexec $LTPDIR/bin/execve05 20 $LTPDIR/bin/execve05 $LTPDIR/bin/execve05 4 2>&1 | tee ./LT_${tid}.txt
ok=`grep TPASS LT_${tid}.txt | wc -l`
ng=`grep TFAIL LT_${tid}.txt | wc -l`
if [ $ng = 0 ]; then
echo "*** LT_$tid: PASSED (ok:$ok)"
else
echo "*** LT_$tid: FAILED (ok:$ok, ng:$ng)"
fi
echo ""

23
test/issues/995/Makefile Normal file
View File

@ -0,0 +1,23 @@
CC = gcc
TARGET=put_args call_execve
all: $(TARGET)
put_args: put_args.c
$(CC) -o $@ $^
call_execve: call_execve.c
$(CC) -o $@ $^
test: all
@ln -nfs ./put_args ./syml_put_args
@echo "#!./syml_put_args" > test_01.sh
@echo "#!`pwd`/syml_put_args" > test_02.sh
@chmod +x ./test_01.sh
@chmod +x ./test_02.sh
@sh ./C995.sh
clean:
rm -f $(TARGET) *.o ./syml_put_args ./test_01.sh ./test_02.sh

37
test/issues/995/README Normal file
View File

@ -0,0 +1,37 @@
【Issue#995 動作確認】
□ テスト内容
1. Issueで報告された再現プログラムでの確認
CT_001: interpがシンボリックリンクを含む相対パスの場合
execveで実行されたシェルスクリプトのinterpに渡されるargv[0]が
シンボリックリンク未解決の相対パスとして設定されることを確認
CT_002: interpがシンボリックリンクを含む絶対パスの場合
execveで実行されたシェルスクリプトのinterpに渡されるargv[0]が
シンボリックリンク未解決の絶対パスとして設定されることを確認
2. 既存のexecve機能に影響がないことをLTPを用いて確認
LT_001: ltp-execve01
子プロセスがexecveを実行し、正常に終了することを確認 (TPASS 1件)
LT_002: ltp-execve02
rootのみに実行権限が付与された実行ファイルを、
一般ユーザがexecveした場合に失敗することを確認 (TPASS 1件)
LT_003: ltp-execve03
下記の不正な引数でexecveを実行した場合、返り値と設定されるerrnoが
正しいことを確認 (TPASS 6件)
LT_004: ltp-execve05
execveの標準的な動作を確認 (TPASS 8件)
□ 実行手順
$ make test
実行できない場合は、C995.shの以下の行を適切に書き換えた後に実行。
BIN= mcexec が存在するパス
SBIN= mcreboot.sh が存在するパス
LTP= LTPが存在するパス
□ 実行結果
result.log 参照。
すべての項目をPASSしていることを確認。

View File

@ -0,0 +1,33 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char *command;
char *exargv[128] = {};
char *exenvp[1] = {NULL};
int i, rc;
if (argc < 2) {
printf("Error: too few arguments\n");
return -1;
}
exargv[0] = argv[1];
for (i = 2; i < argc; i++) {
exargv[i - 1] = argv[i];
}
exargv[i - 1] = NULL;
rc = execve(argv[1], exargv, exenvp);
/* Don't reach here */
if (rc == -1) {
perror("Error: failed to execve");
}
return -1;
}

View File

@ -0,0 +1,10 @@
#include <stdio.h>
void main(int argc, char **argv)
{
int i;
for (i = 0; i < argc; i++) {
printf("argv[%d]: %s\n", i, argv[i]);
}
}

View File

@ -0,0 +1,45 @@
*** RT_001 start *******************************
argv[0]: ./syml_put_args
argv[1]: ./test_01.sh
*** RT_001: PASSED
*** RT_002 start *******************************
argv[0]: /home/satoken/mck_srcs/for_tests/mckernel/test/issues/995/syml_put_args
argv[1]: ./test_02.sh
*** RT_002: PASSED
*** LT_001 start *******************************
execl01_child 1 TPASS : execve01_child executed
execve01 0 TINFO : Child process returned TPASS
*** LT_001: PASSED (ok:2)
*** LT_002 start *******************************
Error: Failed to open execve_child
execve(): error loading ELF for file execve_child
execve02 1 TPASS : execve() failed expectedly: TEST_ERRNO=EACCES(13): Permission denied
execve02 0 TINFO : Child process returned TPASS
*** LT_002: PASSED (ok:2)
*** LT_003 start *******************************
Error: /tmp/exehdVdU3/fake.20952 is not an executable?, errno: 13
execve(): error loading ELF for file /tmp/exehdVdU3/fake.20952
Error: file /tmp/exehdVdU3/execve03.20952 is zero length
execve(): error loading ELF for file /tmp/exehdVdU3/execve03.20952
execve03 1 TPASS : execve failed as expected: TEST_ERRNO=ENAMETOOLONG(36): File name too long
execve03 2 TPASS : execve failed as expected: TEST_ERRNO=ENOENT(2): No such file or directory
execve03 3 TPASS : execve failed as expected: TEST_ERRNO=ENOTDIR(20): Not a directory
execve03 4 TPASS : execve failed as expected: TEST_ERRNO=EFAULT(14): Bad address
execve03 5 TPASS : execve failed as expected: TEST_ERRNO=EACCES(13): Permission denied
execve03 6 TPASS : execve failed as expected: TEST_ERRNO=ENOEXEC(8): Exec format error
*** LT_003: PASSED (ok:6)
*** LT_004 start *******************************
execve05 1 TPASS : Test DONE, pid 21022, -- /home/satoken/ltp/testcases/bin/execve05 0 /home/satoken/ltp/testcases/bin/execve05 /home/satoken/ltp/testcases/bin/execve05
execve05 1 TPASS : Test DONE, pid 21052, -- /home/satoken/ltp/testcases/bin/execve05 0 /home/satoken/ltp/testcases/bin/execve05 /home/satoken/ltp/testcases/bin/execve05
execve05 1 TPASS : Test DONE, pid 21082, -- /home/satoken/ltp/testcases/bin/execve05 0 /home/satoken/ltp/testcases/bin/execve05 /home/satoken/ltp/testcases/bin/execve05
execve05 1 TPASS : Test DONE, pid 21112, -- /home/satoken/ltp/testcases/bin/execve05 0 /home/satoken/ltp/testcases/bin/execve05 /home/satoken/ltp/testcases/bin/execve05
execve05 1 TPASS : Test DONE, pid 21142, -- /home/satoken/ltp/testcases/bin/execve05 0 /home/satoken/ltp/testcases/bin/execve05 /home/satoken/ltp/testcases/bin/execve05
execve05 1 TPASS : Test DONE, pid 21172, -- /home/satoken/ltp/testcases/bin/execve05 0 /home/satoken/ltp/testcases/bin/execve05 /home/satoken/ltp/testcases/bin/execve05
execve05 1 TPASS : Test DONE, pid 21202, -- /home/satoken/ltp/testcases/bin/execve05 0 /home/satoken/ltp/testcases/bin/execve05 /home/satoken/ltp/testcases/bin/execve05
execve05 1 TPASS : Test DONE, pid 21232, -- /home/satoken/ltp/testcases/bin/execve05 0 /home/satoken/ltp/testcases/bin/execve05 /home/satoken/ltp/testcases/bin/execve05
*** LT_004: PASSED (ok:8)