mirror of
https://github.com/clearlinux/graphene.git
synced 2026-09-06 05:41:37 +00:00
[LibOS] Do not try to send signal 0 in kill()/tkill()
Previously, Graphene didn't handle special case of kill()/tkill() with signal equal to zero. This signal is used to check for existence of processes and threads. However, Graphene tried to send/append it which led to segfaults. This commit correctly handles signal equal to zero and improves LibOS tests to verify this fix.
This commit is contained in:
@@ -245,6 +245,13 @@ static int _signal_one_thread(struct shim_thread* thread, void* _arg) {
|
||||
BUG();
|
||||
}
|
||||
|
||||
if (!arg->sig) {
|
||||
/* special case of sig == 0: don't really send signal but simply report success */
|
||||
arg->sent = true;
|
||||
ret = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Appending the signal to the whole process. */
|
||||
if (!arg->sent) {
|
||||
siginfo_t info = {
|
||||
@@ -393,6 +400,13 @@ int do_kill_thread(IDTYPE sender, IDTYPE tgid, IDTYPE tid, int sig, bool use_ipc
|
||||
|
||||
if (thread->in_vm) {
|
||||
if (!tgid || thread->tgid == tgid) {
|
||||
if (!sig) {
|
||||
/* special case of sig == 0: don't really send signal but report success */
|
||||
unlock(&thread->lock);
|
||||
put_thread(thread);
|
||||
return 0;
|
||||
}
|
||||
|
||||
siginfo_t info = {
|
||||
.si_signo = sig,
|
||||
.si_pid = sender,
|
||||
|
||||
@@ -80,6 +80,12 @@ int main() {
|
||||
|
||||
printf("parent tid: %d\n", tid);
|
||||
|
||||
/* the below dummy tkill (no signal is sent) is for sanity */
|
||||
if (tkill(tid, /*sig=*/0)) {
|
||||
fprintf(stderr, "tkill(sig=0) failed: %m\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (tkill(tid, SIGTERM)) {
|
||||
fprintf(stderr, "tkill failed: %m\n");
|
||||
return 1;
|
||||
|
||||
@@ -51,6 +51,12 @@ int main() {
|
||||
|
||||
wait_for(1);
|
||||
|
||||
/* the below dummy kill (no signal is sent) is for sanity */
|
||||
if (kill(getpid(), /*sig=*/0)) {
|
||||
fprintf(stderr, "kill(sig=0) failed: %m\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (kill(getpid(), SIGTERM)) {
|
||||
fprintf(stderr, "kill failed: %m\n");
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user