From patchwork Tue Sep 25 08:18:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinhui Huang X-Patchwork-Id: 974291 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=cn.fujitsu.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 42KDWC1dcsz9s4V for ; Tue, 25 Sep 2018 18:19:17 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 915711A960A for ; Tue, 25 Sep 2018 10:19:12 +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 B7D163E689B for ; Tue, 25 Sep 2018 10:19:10 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id 9CB3E1A00F4F for ; Tue, 25 Sep 2018 10:19:07 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="45322659" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 25 Sep 2018 16:19:02 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id B19944B6ED40 for ; Tue, 25 Sep 2018 16:19:02 +0800 (CST) Received: from localhost.localdomain.localdomain (10.167.220.196) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 25 Sep 2018 16:19:06 +0800 From: Jinhui huang To: Date: Tue, 25 Sep 2018 16:18:54 +0800 Message-ID: <1537863535-25744-1-git-send-email-huangjh.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.196] X-yoursite-MailScanner-ID: B19944B6ED40.AF473 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: huangjh.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=none autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH 1/2] lapi/syscalls: Add syscall numbers for execveat 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Jinhui huang --- include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.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 + 9 files changed, 9 insertions(+) diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in index 9ac7f99..b39a923 100644 --- a/include/lapi/syscalls/aarch64.in +++ b/include/lapi/syscalls/aarch64.in @@ -256,6 +256,7 @@ sendmmsg 269 kcmp 272 getrandom 278 memfd_create 279 +execveat 281 mlock2 284 copy_file_range 285 _sysctl 1078 diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in index 3db9780..f90fe1b 100644 --- a/include/lapi/syscalls/hppa.in +++ b/include/lapi/syscalls/hppa.in @@ -17,5 +17,6 @@ splice 291 tee 293 vmsplice 294 memfd_create 340 +execveat 342 mlock2 345 copy_file_range 346 diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in index 2788193..b239643 100644 --- a/include/lapi/syscalls/ia64.in +++ b/include/lapi/syscalls/ia64.in @@ -296,5 +296,6 @@ prlimit64 1325 renameat2 1338 getrandom 1339 memfd_create 1340 +execveat 1342 mlock2 1346 copy_file_range 1347 diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in index c0b4226..588e152 100644 --- a/include/lapi/syscalls/powerpc.in +++ b/include/lapi/syscalls/powerpc.in @@ -347,6 +347,7 @@ sched_getattr 356 renameat2 357 getrandom 359 memfd_create 360 +execveat 362 mlock2 378 copy_file_range 379 statx 383 diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in index c0b4226..588e152 100644 --- a/include/lapi/syscalls/powerpc64.in +++ b/include/lapi/syscalls/powerpc64.in @@ -347,6 +347,7 @@ sched_getattr 356 renameat2 357 getrandom 359 memfd_create 360 +execveat 362 mlock2 378 copy_file_range 379 statx 383 diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in index 83732ff..47a04de 100644 --- a/include/lapi/syscalls/s390x.in +++ b/include/lapi/syscalls/s390x.in @@ -331,5 +331,6 @@ sched_getattr 346 renameat2 347 getrandom 349 memfd_create 350 +execveat 354 mlock2 374 copy_file_range 375 diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in index 407be7a..e3db4f0 100644 --- a/include/lapi/syscalls/sh.in +++ b/include/lapi/syscalls/sh.in @@ -364,5 +364,6 @@ fanotify_mark 368 prlimit64 369 kcmp 378 memfd_create 385 +execveat 387 mlock2 390 copy_file_range 391 diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in index 2b06a79..4c094ef 100644 --- a/include/lapi/syscalls/sparc.in +++ b/include/lapi/syscalls/sparc.in @@ -336,5 +336,6 @@ kcmp 341 renameat2 345 getrandom 347 memfd_create 348 +execveat 350 mlock2 356 copy_file_range 357 diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in index 8c8a866..b94f442 100644 --- a/include/lapi/syscalls/sparc64.in +++ b/include/lapi/syscalls/sparc64.in @@ -312,5 +312,6 @@ kcmp 341 renameat2 345 getrandom 347 memfd_create 348 +execveat 350 mlock2 356 copy_file_range 357 From patchwork Tue Sep 25 08:18:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinhui Huang X-Patchwork-Id: 974292 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=cn.fujitsu.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 42KDWC2XT6z9s9G for ; Tue, 25 Sep 2018 18:19:18 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 38C861A9627 for ; Tue, 25 Sep 2018 10:19:16 +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 3DF6D3E68B5 for ; Tue, 25 Sep 2018 10:19:12 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id 27FB11A00F37 for ; Tue, 25 Sep 2018 10:19:10 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="45322660" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 25 Sep 2018 16:19:02 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id EF9134B6ED5B for ; Tue, 25 Sep 2018 16:19:03 +0800 (CST) Received: from localhost.localdomain.localdomain (10.167.220.196) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 25 Sep 2018 16:19:07 +0800 From: Jinhui huang To: Date: Tue, 25 Sep 2018 16:18:55 +0800 Message-ID: <1537863535-25744-2-git-send-email-huangjh.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1537863535-25744-1-git-send-email-huangjh.jy@cn.fujitsu.com> References: <1537863535-25744-1-git-send-email-huangjh.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.196] X-yoursite-MailScanner-ID: EF9134B6ED5B.A2216 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: huangjh.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=none autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH 2/2] syscalls/execveat01: Add new testcase 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 1) Factor out check_execveat(). 2) Check the basic functionality of execveat(2). Signed-off-by: Jinhui huang Signed-off-by: Xiao Yang --- runtest/syscalls | 1 + testcases/kernel/syscalls/execveat/.gitignore | 1 + testcases/kernel/syscalls/execveat/execveat.h | 14 +++ testcases/kernel/syscalls/execveat/execveat01.c | 103 +++++++++++++++++++++ testcases/kernel/syscalls/execveat/execveat03.c | 10 +- .../kernel/syscalls/execveat/execveat_child.c | 2 +- 6 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 testcases/kernel/syscalls/execveat/execveat.h create mode 100644 testcases/kernel/syscalls/execveat/execveat01.c diff --git a/runtest/syscalls b/runtest/syscalls index 0d0be77..7004f64 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -148,6 +148,7 @@ execve03 execve03 execve04 execve04 execve05 execve05 -i 5 -n 32 execvp01 execvp01 +execveat01 execveat01 execveat03 execveat03 exit01 exit01 diff --git a/testcases/kernel/syscalls/execveat/.gitignore b/testcases/kernel/syscalls/execveat/.gitignore index cec18fd..4e0c786 100644 --- a/testcases/kernel/syscalls/execveat/.gitignore +++ b/testcases/kernel/syscalls/execveat/.gitignore @@ -1,2 +1,3 @@ +/execveat01 /execveat03 /execveat_child diff --git a/testcases/kernel/syscalls/execveat/execveat.h b/testcases/kernel/syscalls/execveat/execveat.h new file mode 100644 index 0000000..28e10b1 --- /dev/null +++ b/testcases/kernel/syscalls/execveat/execveat.h @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. + * Authors: Jinhui huang + * Xiao Yang + */ + +void check_execveat(void) +{ + int ret; + + ret = execveat(-1, "", NULL, NULL, AT_EMPTY_PATH); + if (ret == -1 && errno == EINVAL) + tst_brk(TCONF, "execveat() not supported"); +} diff --git a/testcases/kernel/syscalls/execveat/execveat01.c b/testcases/kernel/syscalls/execveat/execveat01.c new file mode 100644 index 0000000..e563a48 --- /dev/null +++ b/testcases/kernel/syscalls/execveat/execveat01.c @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. + * Authors: Jinhui huang + * Xiao Yang + */ +/* Test Description: + * This case checks the basic functionality of the execveat(2): + * 1) When pathname is relative, it is relative to the directory where + * the executed process is located and the dirfd is the descriptor of + * the directory. + * 2) When pathname is relative and dirfd is the special value AT_FDCWD, + * the pathname is the relative to the current working directory of + * the calling process. + * 3) When pathname is absolute, dirfd can be ignored. + * 4) When pathname is an empty string and the flag AT_EMPTY_PATH is + * specified, dirfd specifies the file to be executed. + */ + +#define _GNU_SOURCE +#include "config.h" + +#include +#include + +#include "tst_test.h" +#include "lapi/execveat.h" +#include "lapi/fcntl.h" +#include "execveat.h" + +#define MNTPOINT "mntpoint" +#define TEST_APP "execveat_child" +#define TEST_REL_APP MNTPOINT"/"TEST_APP + +static int fd1, fd4; +static int fd2 = AT_FDCWD, fd3 = -1; +static char app_abs_path[512]; + +static struct tcase { + int *fd; + char *pathname; + int flag; +} tcases[] = { + {&fd1, TEST_APP, 0}, + {&fd2, TEST_REL_APP, 0}, + {&fd3, app_abs_path, 0}, + {&fd4, "", AT_EMPTY_PATH}, +}; + +static void verify_execveat(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + char *argv[2] = {TEST_APP, NULL}; + pid_t pid; + + pid = SAFE_FORK(); + if (pid == 0) { + TEST(execveat(*tc->fd, tc->pathname, argv, environ, tc->flag)); + tst_res(TFAIL | TERRNO, "execveat() returns unexpected errno"); + } +} + +static void setup(void) +{ + char cur_dir_path[512]; + + check_execveat(); + + SAFE_CP(TEST_APP, TEST_REL_APP); + + SAFE_GETCWD(cur_dir_path, sizeof(cur_dir_path)); + sprintf(app_abs_path, "%s/%s", cur_dir_path, TEST_REL_APP); + + fd1 = SAFE_OPEN(MNTPOINT, O_DIRECTORY); + fd4 = SAFE_OPEN(TEST_REL_APP, O_PATH); +} + +static void cleanup(void) +{ + if (fd1 > 0) + SAFE_CLOSE(fd1); + + if (fd4 > 0) + SAFE_CLOSE(fd4); +} + +static const char *const resource_files[] = { + TEST_APP, + NULL, +}; + +static struct tst_test test = { + .resource_files = resource_files, + .tcnt = ARRAY_SIZE(tcases), + .test = verify_execveat, + .child_needs_reinit = 1, + .all_filesystems = 1, + .mntpoint = MNTPOINT, + .mount_device = 1, + .forks_child = 1, + .needs_root = 1, + .cleanup = cleanup, + .setup = setup, +}; diff --git a/testcases/kernel/syscalls/execveat/execveat03.c b/testcases/kernel/syscalls/execveat/execveat03.c index d2d4aaf..def3392 100644 --- a/testcases/kernel/syscalls/execveat/execveat03.c +++ b/testcases/kernel/syscalls/execveat/execveat03.c @@ -53,6 +53,7 @@ #include "tst_test.h" #include "lapi/execveat.h" #include "lapi/fcntl.h" +#include "execveat.h" #define OVL_MNT "ovl" #define TEST_APP "execveat_child" @@ -83,15 +84,6 @@ static void verify_execveat(void) do_child(); } -static void check_execveat(void) -{ - int ret; - - ret = execveat(-1, "", NULL, NULL, AT_EMPTY_PATH); - if (ret == -1 && errno == EINVAL) - tst_brk(TCONF, "execveat() not supported"); -} - static void setup(void) { int ret; diff --git a/testcases/kernel/syscalls/execveat/execveat_child.c b/testcases/kernel/syscalls/execveat/execveat_child.c index 9a3eb94..9a56032 100644 --- a/testcases/kernel/syscalls/execveat/execveat_child.c +++ b/testcases/kernel/syscalls/execveat/execveat_child.c @@ -24,7 +24,7 @@ /* * execveat_child.c - * dummy program which is used by execveat01.c testcase + * dummy program which is used by execveat01.c and execveat03.c testcases */ #define TST_NO_DEFAULT_MAIN