tgkill: Fix argument validatation

Formerly, if tgid is specified as -1, tgkill() was equivalent to tkill().
Now it is treated as an error EINVAL.

Change-Id: I47bc75d439662a36dc6167c4446a5277422de507
Refs: 1380
This commit is contained in:
Ken Sato
2020-07-02 10:56:26 +09:00
committed by Masamichi Takagi
parent 58106d791a
commit ebc91cea0e
6 changed files with 136 additions and 6 deletions

View File

@ -3240,7 +3240,6 @@ SYSCALL_DECLARE(kill)
return error;
}
// see linux-2.6.34.13/kernel/signal.c
SYSCALL_DECLARE(tgkill)
{
int tgid = ihk_mc_syscall_arg0(ctx);
@ -3249,16 +3248,15 @@ SYSCALL_DECLARE(tgkill)
struct thread *thread = cpu_local_var(current);
struct siginfo info;
if (tgid <= 0 || tid <= 0) {
return -EINVAL;
}
memset(&info, '\0', sizeof info);
info.si_signo = sig;
info.si_code = SI_TKILL;
info._sifields._kill.si_pid = thread->proc->pid;
if(tid <= 0)
return -EINVAL;
if(tgid <= 0 && tgid != -1)
return -EINVAL;
return do_kill(thread, tgid, tid, sig, &info, 0);
}

26
test/issues/1380/C1380.sh Executable file
View File

@ -0,0 +1,26 @@
#/bin/sh
USELTP=1
USEOSTEST=0
. ../../common.sh
issue="1380"
tid=01
for tp in tgkill03 tgkill01 tkill01 tkill02
do
tname=`printf "C${issue}T%02d" ${tid}`
echo "*** ${tname} start *******************************"
sudo $MCEXEC $LTPBIN/$tp 2>&1 | tee $tp.txt
ok=`grep PASS $tp.txt | wc -l`
ng=`grep FAIL $tp.txt | wc -l`
if [ $ng = 0 ]; then
echo "*** ${tname} PASSED ($ok)"
else
echo "*** ${tname} FAILED (ok=$ok ng=$ng)"
fi
let tid++
echo ""
done

11
test/issues/1380/Makefile Normal file
View File

@ -0,0 +1,11 @@
CFLAGS=-g
LDFLAGS=
TARGET=
all: $(TARGET)
test: all
./C1380.sh
clean:
rm -f $(TARGET) *.o *.txt

21
test/issues/1380/README Normal file
View File

@ -0,0 +1,21 @@
【Issue#1324 動作確認】
□ テスト内容
1. 以下のLTPを用いてIssueで報告された症状が発生しないことを確認
- tgkill03
3. 以下のLTPを用いて既存機能に影響が無いことを確認
- tgkill01
- tkill01
- tkill02
□ 実行手順
$ make test
McKernelのインストール先や、OSTEST, LTPの配置場所は、
$HOME/.mck_test_config を参照している
.mck_test_config は、McKernelをビルドした際に生成されるmck_test_config.sample ファイルを
$HOMEにコピーし、適宜編集する
□ 実行結果
x86_64_result.log aarch64_result.log 参照。
すべての項目をPASSしていることを確認。

View File

@ -0,0 +1,37 @@
*** C1380T01 start *******************************
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s
tgkill03.c:92: PASS: Invalid tgid failed as expected: EINVAL
tgkill03.c:92: PASS: Invalid tid failed as expected: EINVAL
tgkill03.c:92: PASS: Invalid signal failed as expected: EINVAL
tgkill03.c:92: PASS: Defunct tid failed as expected: ESRCH
tgkill03.c:92: PASS: Defunct tgid failed as expected: ESRCH
tgkill03.c:99: PASS: Valid tgkill call succeeded
Summary:
passed 6
failed 0
skipped 0
warnings 0
*** C1380T01 PASSED (6)
*** C1380T02 start *******************************
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s
tgkill01.c:99: PASS: SIGUSR1 delivered to correct threads
Summary:
passed 1
failed 0
skipped 0
warnings 0
*** C1380T02 PASSED (1)
*** C1380T03 start *******************************
tkill01 1 TPASS : tkill call succeeded
tkill01 2 TPASS : tkill call succeeded
*** C1380T03 PASSED (2)
*** C1380T04 start *******************************
tkill02 1 TPASS : tkill(-1, SIGUSR1) failed as expected: TEST_ERRNO=EINVAL(22): Invalid argument
tkill02 2 TPASS : tkill(29822, SIGUSR1) failed as expected: TEST_ERRNO=ESRCH(3): No such process
*** C1380T04 PASSED (2)

View File

@ -0,0 +1,37 @@
*** C1380T01 start *******************************
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s
tgkill03.c:92: PASS: Invalid tgid failed as expected: EINVAL
tgkill03.c:92: PASS: Invalid tid failed as expected: EINVAL
tgkill03.c:92: PASS: Invalid signal failed as expected: EINVAL
tgkill03.c:92: PASS: Defunct tid failed as expected: ESRCH
tgkill03.c:92: PASS: Defunct tgid failed as expected: ESRCH
tgkill03.c:99: PASS: Valid tgkill call succeeded
Summary:
passed 6
failed 0
skipped 0
warnings 0
*** C1380T01 PASSED (6)
*** C1380T02 start *******************************
tst_test.c:1096: INFO: Timeout per run is 0h 05m 00s
tgkill01.c:99: PASS: SIGUSR1 delivered to correct threads
Summary:
passed 1
failed 0
skipped 0
warnings 0
*** C1380T02 PASSED (1)
*** C1380T03 start *******************************
tkill01 1 TPASS : tkill call succeeded
tkill01 2 TPASS : tkill call succeeded
*** C1380T03 PASSED (2)
*** C1380T04 start *******************************
tkill02 1 TPASS : tkill(-1, SIGUSR1) failed as expected: TEST_ERRNO=EINVAL(22): Invalid argument
tkill02 2 TPASS : tkill(32768, SIGUSR1) failed as expected: TEST_ERRNO=ESRCH(3): No such process
*** C1380T04 PASSED (2)