From patchwork Wed May 15 12:01:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Amann X-Patchwork-Id: 1099966 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 453tSj4n4jz9s3q for ; Wed, 15 May 2019 22:01:41 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 583D6294AD5 for ; Wed, 15 May 2019 14:01:31 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 9900E294AB2 for ; Wed, 15 May 2019 14:01:28 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 5EFCA201488 for ; Wed, 15 May 2019 14:01:26 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 809BCABF4 for ; Wed, 15 May 2019 12:01:26 +0000 (UTC) From: Christian Amann To: ltp@lists.linux.it Date: Wed, 15 May 2019 14:01:13 +0200 Message-Id: <20190515120116.11589-1-camann@suse.com> X-Mailer: git-send-email 2.16.4 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v1 1/4] Add Syscall numbers for pidfd_send_signal X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Christian Amann Reviewed-by: Petr Vorel --- include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + 13 files changed, 13 insertions(+) diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in index 177dd0115..ce6080894 100644 --- a/include/lapi/syscalls/aarch64.in +++ b/include/lapi/syscalls/aarch64.in @@ -265,4 +265,5 @@ mlock2 284 copy_file_range 285 preadv2 286 pwritev2 287 +pidfd_send_signal 424 _sysctl 1078 diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in index f4adedb2c..33168889f 100644 --- a/include/lapi/syscalls/arm.in +++ b/include/lapi/syscalls/arm.in @@ -350,3 +350,4 @@ copy_file_range (__NR_SYSCALL_BASE+391) preadv2 (__NR_SYSCALL_BASE+392) pwritev2 (__NR_SYSCALL_BASE+393) statx (__NR_SYSCALL_BASE+397) +pidfd_send_signal (__NR_SYSCALL_BASE+424) diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in index a0dd2307f..4cdd109fb 100644 --- a/include/lapi/syscalls/hppa.in +++ b/include/lapi/syscalls/hppa.in @@ -25,3 +25,4 @@ mlock2 345 copy_file_range 346 preadv2 347 pwritev2 348 +pidfd_send_signal 424 diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in index af5254f77..3355b9127 100644 --- a/include/lapi/syscalls/i386.in +++ b/include/lapi/syscalls/i386.in @@ -348,3 +348,4 @@ copy_file_range 377 preadv2 378 pwritev2 379 statx 383 +pidfd_send_signal 424 diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in index c0aeed08b..9ac81e91e 100644 --- a/include/lapi/syscalls/ia64.in +++ b/include/lapi/syscalls/ia64.in @@ -305,3 +305,4 @@ mlock2 1346 copy_file_range 1347 preadv2 1348 pwritev2 1349 +pidfd_send_signal 1448 diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in index 6b6be58a7..488d6dfa9 100644 --- a/include/lapi/syscalls/powerpc.in +++ b/include/lapi/syscalls/powerpc.in @@ -355,3 +355,4 @@ copy_file_range 379 preadv2 380 pwritev2 381 statx 383 +pidfd_send_signal 424 diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in index 6b6be58a7..488d6dfa9 100644 --- a/include/lapi/syscalls/powerpc64.in +++ b/include/lapi/syscalls/powerpc64.in @@ -355,3 +355,4 @@ copy_file_range 379 preadv2 380 pwritev2 381 statx 383 +pidfd_send_signal 424 diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in index 2a2ffe223..69b49eac0 100644 --- a/include/lapi/syscalls/s390.in +++ b/include/lapi/syscalls/s390.in @@ -338,3 +338,4 @@ mlock2 374 copy_file_range 375 preadv2 376 pwritev2 377 +pidfd_send_signal 424 diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in index 4c36ce17c..685c16f68 100644 --- a/include/lapi/syscalls/s390x.in +++ b/include/lapi/syscalls/s390x.in @@ -337,3 +337,4 @@ mlock2 374 copy_file_range 375 preadv2 376 pwritev2 377 +pidfd_send_signal 424 diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in index a942fb506..132492922 100644 --- a/include/lapi/syscalls/sh.in +++ b/include/lapi/syscalls/sh.in @@ -369,3 +369,4 @@ mlock2 390 copy_file_range 391 preadv2 392 pwritev2 393 +pidfd_send_signal 424 diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in index 20dc37b01..e74b48170 100644 --- a/include/lapi/syscalls/sparc.in +++ b/include/lapi/syscalls/sparc.in @@ -343,3 +343,4 @@ mlock2 356 copy_file_range 357 preadv2 358 pwritev2 359 +pidfd_send_signal 424 diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in index c100b8e3e..577aa9b35 100644 --- a/include/lapi/syscalls/sparc64.in +++ b/include/lapi/syscalls/sparc64.in @@ -319,3 +319,4 @@ mlock2 356 copy_file_range 357 preadv2 358 pwritev2 359 +pidfd_send_signal 424 diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in index 87849e5c0..99d387277 100644 --- a/include/lapi/syscalls/x86_64.in +++ b/include/lapi/syscalls/x86_64.in @@ -315,3 +315,4 @@ copy_file_range 326 preadv2 327 pwritev2 328 statx 332 +pidfd_send_signal 424 From patchwork Wed May 15 12:01:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Amann X-Patchwork-Id: 1099965 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 453tSf2fLvz9sBb for ; Wed, 15 May 2019 22:01:38 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DFD4E294B20 for ; Wed, 15 May 2019 14:01:35 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) by picard.linux.it (Postfix) with ESMTP id 5C109294AB2 for ; Wed, 15 May 2019 14:01:30 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id B6C0A1A01DE0 for ; Wed, 15 May 2019 14:01:29 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E8B9CABF4 for ; Wed, 15 May 2019 12:01:28 +0000 (UTC) From: Christian Amann To: ltp@lists.linux.it Date: Wed, 15 May 2019 14:01:14 +0200 Message-Id: <20190515120116.11589-2-camann@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190515120116.11589-1-camann@suse.com> References: <20190515120116.11589-1-camann@suse.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v1 2/4] syscalls/pidfd_send_signal01 X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Add testcase to check if pidfd_send_signal() can provide the same functionality as rt_sigqueueinfo(). Signed-off-by: Christian Amann --- runtest/syscalls | 2 + .../kernel/syscalls/pidfd_send_signal/.gitignore | 1 + .../kernel/syscalls/pidfd_send_signal/Makefile | 14 +++ .../syscalls/pidfd_send_signal/pidfd_send_signal.h | 20 ++++ .../pidfd_send_signal/pidfd_send_signal01.c | 110 +++++++++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 testcases/kernel/syscalls/pidfd_send_signal/.gitignore create mode 100644 testcases/kernel/syscalls/pidfd_send_signal/Makefile create mode 100644 testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal.h create mode 100644 testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c diff --git a/runtest/syscalls b/runtest/syscalls index 2b8ca719b..c719b77b2 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -838,6 +838,8 @@ pause03 pause03 personality01 personality01 personality02 personality02 +pidfd_send_signal01 pidfd_send_signal01 + pipe01 pipe01 pipe02 pipe02 pipe03 pipe03 diff --git a/testcases/kernel/syscalls/pidfd_send_signal/.gitignore b/testcases/kernel/syscalls/pidfd_send_signal/.gitignore new file mode 100644 index 000000000..7ccbf2d80 --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_send_signal/.gitignore @@ -0,0 +1 @@ +/pidfd_send_signal01 diff --git a/testcases/kernel/syscalls/pidfd_send_signal/Makefile b/testcases/kernel/syscalls/pidfd_send_signal/Makefile new file mode 100644 index 000000000..23e4ec478 --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_send_signal/Makefile @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (c) 2019 SUSE LLC +# +# Author: Christian Amann +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk + +pidfd_send_signal01: CFLAGS += -pthread diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal.h b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal.h new file mode 100644 index 000000000..3553c5464 --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 SUSE LLC + * Author: Christian Amann + */ + +#ifndef __PIDFD_SEND_SIGNAL_H__ +#define __PIDFD_SEND_SIGNAL_H__ + +#include "tst_test.h" +#include "lapi/syscalls.h" + +static int tst_pidfd_send_signal(int pidfd, int sig, siginfo_t *info, + unsigned int flags) +{ + return tst_syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags); +} + + +#endif /* __PIDFD_SEND_SIGNAL_H__ */ diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c new file mode 100644 index 000000000..9ab1971bf --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 SUSE LLC + * Author: Christian Amann + */ +/* + * Tests if the pidfd_send_signal systemcall behaves + * like rt_sigqueueinfo when a pointer to a siginfo_t + * struct is passed. + */ + +#define _GNU_SOURCE + +#include +#include +#include "tst_safe_pthread.h" +#include "pidfd_send_signal.h" + +#define SIGNAL SIGUSR1 +#define DATA 777 + +static struct sigaction *sig_action; +static int sig_rec; +static siginfo_t *uinfo; +static int pidfd; + +static void received_signal(int sig, siginfo_t *info, void *ucontext) +{ + if (info && ucontext) { + if (sig == SIGNAL && uinfo->si_value.sival_int == DATA) { + tst_res(TPASS, "Received correct signal and data!"); + sig_rec = 1; + } else + tst_res(TFAIL, "Received wrong signal and/or data!"); + } else + tst_res(TFAIL, "Signal handling went wrong!"); +} + +static void *handle_thread(void *arg LTP_ATTRIBUTE_UNUSED) +{ + int ret; + + ret = sigaction(SIGNAL, sig_action, NULL); + if (ret) + tst_brk(TBROK | TTERRNO, "Failed to set sigaction"); + + TST_CHECKPOINT_WAKE(0); + TST_CHECKPOINT_WAIT(1); + return arg; +} + +static void verify_pidfd_send_signal(void) +{ + pthread_t thr; + + SAFE_PTHREAD_CREATE(&thr, NULL, handle_thread, NULL); + + TST_CHECKPOINT_WAIT(0); + + TEST(tst_pidfd_send_signal(pidfd, SIGNAL, uinfo, 0)); + if (TST_RET != 0) { + tst_res(TFAIL | TTERRNO, "pidfd_send_signal() failed"); + return; + } + + TST_CHECKPOINT_WAKE(1); + SAFE_PTHREAD_JOIN(thr, NULL); + + if (sig_rec) + tst_res(TPASS, + "pidfd_send_signal() behaved like rt_sigqueueinfo()"); +} + +static void setup(void) +{ + pidfd = SAFE_OPEN("/proc/self", O_DIRECTORY | O_CLOEXEC); + + sig_action = SAFE_MALLOC(sizeof(struct sigaction)); + + memset(sig_action, 0, sizeof(*sig_action)); + sig_action->sa_sigaction = received_signal; + sig_action->sa_flags = SA_SIGINFO; + + uinfo = SAFE_MALLOC(sizeof(siginfo_t)); + + memset(uinfo, 0, sizeof(*uinfo)); + uinfo->si_signo = SIGNAL; + uinfo->si_code = SI_QUEUE; + uinfo->si_pid = getpid(); + uinfo->si_uid = getuid(); + uinfo->si_value.sival_int = DATA; + + sig_rec = 0; +} + +static void cleanup(void) +{ + free(uinfo); + free(sig_action); + if (pidfd > 0) + SAFE_CLOSE(pidfd); +} + +static struct tst_test test = { + .test_all = verify_pidfd_send_signal, + .setup = setup, + .cleanup = cleanup, + .needs_checkpoints = 1, + .timeout = 20, +}; From patchwork Wed May 15 12:01:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Amann X-Patchwork-Id: 1099967 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 453tSk5R3Xz9sBV for ; Wed, 15 May 2019 22:01:42 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2DCB7294B5F for ; Wed, 15 May 2019 14:01:40 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id D8AB3294B04 for ; Wed, 15 May 2019 14:01:32 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 7C1F0141CFA5 for ; Wed, 15 May 2019 14:01:32 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C9E8AAD03 for ; Wed, 15 May 2019 12:01:31 +0000 (UTC) From: Christian Amann To: ltp@lists.linux.it Date: Wed, 15 May 2019 14:01:15 +0200 Message-Id: <20190515120116.11589-3-camann@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190515120116.11589-1-camann@suse.com> References: <20190515120116.11589-1-camann@suse.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v1 3/4] syscalls/pidfd_send_signal02 X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Add test to check basic error handling of the syscall. Signed-off-by: Christian Amann --- runtest/syscalls | 1 + .../kernel/syscalls/pidfd_send_signal/.gitignore | 1 + .../pidfd_send_signal/pidfd_send_signal02.c | 104 +++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c diff --git a/runtest/syscalls b/runtest/syscalls index c719b77b2..fd57e2ee7 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -839,6 +839,7 @@ personality01 personality01 personality02 personality02 pidfd_send_signal01 pidfd_send_signal01 +pidfd_send_signal02 pidfd_send_signal02 pipe01 pipe01 pipe02 pipe02 diff --git a/testcases/kernel/syscalls/pidfd_send_signal/.gitignore b/testcases/kernel/syscalls/pidfd_send_signal/.gitignore index 7ccbf2d80..6ea6401a8 100644 --- a/testcases/kernel/syscalls/pidfd_send_signal/.gitignore +++ b/testcases/kernel/syscalls/pidfd_send_signal/.gitignore @@ -1 +1,2 @@ /pidfd_send_signal01 +/pidfd_send_signal02 diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c new file mode 100644 index 000000000..25e66a214 --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c @@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 SUSE LLC + * Author: Christian Amann + */ +/* + * Tests basic error handling of the pidfd_send_signal + * system call. + * + * 1) Pass invalid flag value to syscall (value chosen + * to be unlikely to collide with future extensions) + * -> EINVAL + * 2) Pass a file descriptor that is corresponding to a + * regular file instead of a pid directory + * -> EBADF + * 3) Pass a signal that is different from the one used + * to initialize the siginfo_t struct + * -> EINVAL + * 4) Try to send signal to other process (init) with + * missing privileges + * -> EPERM + */ + +#define _GNU_SOURCE + +#include +#include "pwd.h" +#include "tst_safe_pthread.h" +#include "pidfd_send_signal.h" + +#define CORRECT_SIGNAL SIGUSR1 +#define DIFFERENT_SIGNAL SIGUSR2 + +static siginfo_t info; +static int pidfd; +static int init_pidfd; +static int dummyfd; + +static struct tcase { + int *fd; + siginfo_t *siginf; + int signal; + int flags; + int exp_err; +} tcases[] = { + {&pidfd, &info, CORRECT_SIGNAL, 99999, EINVAL}, + {&dummyfd, &info, CORRECT_SIGNAL, 0, EBADF}, + {&pidfd, &info, DIFFERENT_SIGNAL, 0, EINVAL}, + {&init_pidfd, &info, CORRECT_SIGNAL, 0, EPERM}, +}; + +static void verify_pidfd_send_signal(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + + TEST(tst_pidfd_send_signal(*tc->fd, tc->signal, tc->siginf, tc->flags)); + if (tc->exp_err != TST_ERR) { + tst_res(TFAIL | TTERRNO, + "pidfd_send_signal() did not fail with %s but", + tst_strerrno(tc->exp_err)); + return; + } + + tst_res(TPASS, + "pidfd_send_signal() failed as expected!"); +} + +static void setup(void) +{ + struct passwd *pw; + + pidfd = SAFE_OPEN("/proc/self", O_DIRECTORY | O_CLOEXEC); + init_pidfd = SAFE_OPEN("/proc/1", O_DIRECTORY | O_CLOEXEC); + dummyfd = SAFE_OPEN("dummy_file", O_RDWR | O_CREAT, 0664); + + if (getuid() == 0) { + pw = SAFE_GETPWNAM("nobody"); + SAFE_SETUID(pw->pw_uid); + } + + memset(&info, 0, sizeof(info)); + info.si_signo = CORRECT_SIGNAL; + info.si_code = SI_QUEUE; + info.si_pid = getpid(); + info.si_uid = getuid(); +} + +static void cleanup(void) +{ + if (dummyfd > 0) + SAFE_CLOSE(dummyfd); + if (init_pidfd > 0) + SAFE_CLOSE(init_pidfd); + if (pidfd > 0) + SAFE_CLOSE(pidfd); +} + +static struct tst_test test = { + .test = verify_pidfd_send_signal, + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, +}; From patchwork Wed May 15 12:01:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Amann X-Patchwork-Id: 1099968 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 453tSr1f7cz9s3q for ; Wed, 15 May 2019 22:01:48 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5F245294BB0 for ; Wed, 15 May 2019 14:01:43 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id 1231C294B23 for ; Wed, 15 May 2019 14:01:36 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id A2F5620149F for ; Wed, 15 May 2019 14:01:35 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 01498AC4E for ; Wed, 15 May 2019 12:01:35 +0000 (UTC) From: Christian Amann To: ltp@lists.linux.it Date: Wed, 15 May 2019 14:01:16 +0200 Message-Id: <20190515120116.11589-4-camann@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190515120116.11589-1-camann@suse.com> References: <20190515120116.11589-1-camann@suse.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v1 4/4] syscalls/pidfd_send_signal03 X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Add testcase to check if the syscall will send a signal to a process with the same PID as the targeted process. Signed-off-by: Christian Amann --- runtest/syscalls | 1 + .../kernel/syscalls/pidfd_send_signal/.gitignore | 1 + .../pidfd_send_signal/pidfd_send_signal03.c | 118 +++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c diff --git a/runtest/syscalls b/runtest/syscalls index fd57e2ee7..a534a663b 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -840,6 +840,7 @@ personality02 personality02 pidfd_send_signal01 pidfd_send_signal01 pidfd_send_signal02 pidfd_send_signal02 +pidfd_send_signal03 pidfd_send_signal03 pipe01 pipe01 pipe02 pipe02 diff --git a/testcases/kernel/syscalls/pidfd_send_signal/.gitignore b/testcases/kernel/syscalls/pidfd_send_signal/.gitignore index 6ea6401a8..cba7d50a4 100644 --- a/testcases/kernel/syscalls/pidfd_send_signal/.gitignore +++ b/testcases/kernel/syscalls/pidfd_send_signal/.gitignore @@ -1,2 +1,3 @@ /pidfd_send_signal01 /pidfd_send_signal02 +/pidfd_send_signal03 diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c new file mode 100644 index 000000000..ee17e714e --- /dev/null +++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c @@ -0,0 +1,118 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 SUSE LLC + * Author: Christian Amann + */ +/* + * This test checks if the pidfd_send_signal syscall wrongfully sends + * a signal to a new process which inherited the PID of the actual + * target process. + * In order to do so it is necessary to start a process with a pre- + * determined PID. This is accomplished by writing to the + * /proc/sys/kernel/ns_last_pid file. + * By utilizing this, this test forks two children with the same PID. + * It is then checked, if the syscall will send a signal to the second + * child using the pidfd of the first one. + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include "pidfd_send_signal.h" +#include "tst_safe_pthread.h" + +#define PIDTRIES 3 + +static char *last_pid_file; +static int pidfd, last_pidfd; + +static void verify_pidfd_send_signal(void) +{ + pid_t pid, new_pid; + char pid_filename[32]; + char pid_str[16]; + int i, fail; + + fail = 1; + for (i = 1; i <= PIDTRIES; i++) { + pid = SAFE_FORK(); + if (pid == 0) { + TST_CHECKPOINT_WAIT(0); + return; + } + + sprintf(pid_filename, "/proc/%d", pid); + pidfd = SAFE_OPEN(pid_filename, O_DIRECTORY | O_CLOEXEC); + + TST_CHECKPOINT_WAKE(0); + tst_reap_children(); + + /* Manipulate PID for next process */ + sprintf(pid_str, "%d", pid - 1); + SAFE_LSEEK(last_pidfd, 0, SEEK_SET); + SAFE_WRITE(1, last_pidfd, pid_str, strlen(pid_str)); + + new_pid = SAFE_FORK(); + if (new_pid == 0) { + TST_CHECKPOINT_WAIT(i); + return; + } else if (new_pid == pid) { + fail = 0; + break; + } + + if (i < PIDTRIES) + tst_res(TINFO, + "Failed to set correct PID, trying again..."); + SAFE_CLOSE(pidfd); + TST_CHECKPOINT_WAKE(i); + tst_reap_children(); + } + if (fail) + tst_brk(TBROK, + "Could not set new child to same PID as the old one!"); + + TEST(tst_pidfd_send_signal(pidfd, SIGUSR1, NULL, 0)); + if (TST_RET == -1 && TST_ERR == ESRCH) { + tst_res(TPASS, + "Did not send signal to wrong process with same PID!"); + } else + tst_res(TFAIL | TTERRNO, + "pidf_send_signal() ended unexpectedly - return value: %ld, error", + TST_RET); + + TST_CHECKPOINT_WAKE(i); + tst_reap_children(); + + SAFE_CLOSE(pidfd); +} + +static void setup(void) +{ + last_pid_file = "/proc/sys/kernel/ns_last_pid"; + if (access(last_pid_file, F_OK) == -1) + tst_brk(TCONF, "%s does not exist, cannot set PIDs", + last_pid_file); + last_pidfd = SAFE_OPEN(last_pid_file, O_RDWR); +} + +static void cleanup(void) +{ + tst_reap_children(); + if (pidfd > 0) + SAFE_CLOSE(pidfd); + if (last_pidfd > 0) + SAFE_CLOSE(last_pidfd); +} + +static struct tst_test test = { + .test_all = verify_pidfd_send_signal, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, + .needs_checkpoints = 1, + .forks_child = 1, + .timeout = 20, +};