From nobody Thu Feb 10 20:22:16 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 572A719C0AB8; Thu, 10 Feb 2022 20:22:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jvp7s1gkyz3mVJ; Thu, 10 Feb 2022 20:22:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644524537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TyO2JCai83C2n07mKj8S2wURoA/kfjKp0fkme2yMUpU=; b=hBVI7nSRGkZsiz7D8NXWby8Pg8f9CjuThu9iLbYUlYkGy7V3/CVCskEf5ap5YOREsjvwKy TPyf3sWGAO5THzvAz/ZS2iU9fx8hHK1pSntI7Yvc67/hmr/1I30BNNeAZcjlQMpCNwIYrZ J2eF8E4d6xQeM5z17GZJtByA6TMcZHEjKO0S9EjAYj4WWdRBSCm/2vG7cy3lYRksH0ubmS m1q0Kl85pGBgVHVnYTUB+Vq82++3tlBiQlVW1GbgrKTfBEbOgNLVQoy4skeRA/bOz72QgW HdawnYpWG+QOMAd8JYtbvbheyOcGY6yXjfSUni37tSam/y6RXcQX4RXyqJY+Ag== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 11E3B26F36; Thu, 10 Feb 2022 20:22:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 21AKMGof088370; Thu, 10 Feb 2022 20:22:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21AKMGbP088369; Thu, 10 Feb 2022 20:22:16 GMT (envelope-from git) Date: Thu, 10 Feb 2022 20:22:16 GMT Message-Id: <202202102022.21AKMGbP088369@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: d352fa262709 - stable/13 - tests: add a basic test for argc == 0 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: d352fa2627096c0cdb1238e06c047f91a3ef0527 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644524537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TyO2JCai83C2n07mKj8S2wURoA/kfjKp0fkme2yMUpU=; b=QBhvi4CjcBh/pTSzLwzaUoaFQjJLBRuKQkEaMUhNhV8Rk0SF1d3SGIvtEaLL0/aDedM+yU rR8x7T3/EgSVbLw5nh3l0yjZXAoVIBk6NKeV/Nqkozw05xWL/qP0Zn574So/XwVyxbBd+m QbYhPziUp+aHDFU+uOp1Uxz/QP/92O4UsKwJ6gdLbO3XYC64X3s2KEydq3fbxwQTk6ntNy JZuWal5ItyoQ/yAEqHMEfvXxeR/Duy/MQzkLm0tKu8f+/zfkv3san69ICuXQQOPWsplinM kJWFu4Zj/safbpWTXQHg/QFfKkoVUX2b4O75KAWTukU3UYvOu84eEjoEDvIJxg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644524537; a=rsa-sha256; cv=none; b=w0grm6/61D+zEPTvACwEuXxCUfQpCxzL2qefPiX7tuarDZWz4SEOXDD8BW3fUKwyzQpRIA cjJvEn55XFDS2m0blMw8Ru90nVE83t2SNqPO1TzAJE561RmIS+6dCGpBNVLZTRLMVxl5uS uB5+pTKPHjrCmWhaSGD9w9eysg+BOLnKGmBiWHRms1wF3TB5oqEw5gH0g4iQKc0HGNUwLt iSs73ZotTRD1cotb6agiQ3wAu8eJhV4+P1wHIPnOnW3H0c5TxFpixYnA7JqhT/fTrLkRkR e8d7axoY5pyHxNI8WXqyxg8XUZCBlNu/Np8UEpx84+NKBZtFLcKxxB4ReUqVwQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=d352fa2627096c0cdb1238e06c047f91a3ef0527 commit d352fa2627096c0cdb1238e06c047f91a3ef0527 Author: Kyle Evans AuthorDate: 2022-01-26 01:22:03 +0000 Commit: Kyle Evans CommitDate: 2022-02-10 20:21:59 +0000 tests: add a basic test for argc == 0 The kernel should reject such exec()s now, early on. Instead of adding the needed boilerplate to write a test in C, just add an -n argument for "(n)ull argv" to the execve helper and exec this other helper that just exits silently with argv count. (cherry picked from commit e5b431fc0c20771a2a18cb5169d75cf337d0f1dd) --- tests/sys/kern/execve/Makefile | 1 + tests/sys/kern/execve/execve_argc_helper.c | 15 +++++++++++++++ tests/sys/kern/execve/execve_helper.c | 13 ++++++++++--- tests/sys/kern/execve/execve_test.sh | 18 ++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/tests/sys/kern/execve/Makefile b/tests/sys/kern/execve/Makefile index 82c5d4b85b10..d1dcae623df4 100644 --- a/tests/sys/kern/execve/Makefile +++ b/tests/sys/kern/execve/Makefile @@ -10,6 +10,7 @@ ATF_TESTS_SH+= execve_test PROGS+= good_aout PROGS+= execve_helper +PROGS+= execve_argc_helper LDFLAGS.goodaout+= -static diff --git a/tests/sys/kern/execve/execve_argc_helper.c b/tests/sys/kern/execve/execve_argc_helper.c new file mode 100644 index 000000000000..519c96902fdf --- /dev/null +++ b/tests/sys/kern/execve/execve_argc_helper.c @@ -0,0 +1,15 @@ +/* + * This file is in the public domain. + */ + +#include + +#include + +int +main(int argc, char **argv __unused) +{ + + printf("%d\n", argc); + return (0); +} diff --git a/tests/sys/kern/execve/execve_helper.c b/tests/sys/kern/execve/execve_helper.c index 989b3e4b9761..c14ca2d29554 100644 --- a/tests/sys/kern/execve/execve_helper.c +++ b/tests/sys/kern/execve/execve_helper.c @@ -38,17 +38,24 @@ #include #include #include +#include #include +/* Passing -n == null_argv */ +static char * const null_argv[] = { NULL }; + int main(int argc, char **argv) { - if (argc != 2) { - fprintf(stderr, "usage: %s \n", argv[0]); + if (argc == 2) { + execve(argv[1], &argv[1], NULL); + } else if (argc == 3 && strcmp(argv[1], "-n") == 0) { + execve(argv[2], null_argv, NULL); + } else { + fprintf(stderr, "usage: %s [-n] \n", argv[0]); exit(2); } - execve(argv[1], &argv[1], NULL); err(1, "execve failed"); } diff --git a/tests/sys/kern/execve/execve_test.sh b/tests/sys/kern/execve/execve_test.sh index ef803a18d442..d3650f3472cc 100644 --- a/tests/sys/kern/execve/execve_test.sh +++ b/tests/sys/kern/execve/execve_test.sh @@ -99,6 +99,23 @@ trunc_aout_body() -x "cd $(atf_get_srcdir) && ./execve_helper trunc_aout" } +empty_args_head() +{ + atf_set "descr" "Empty argv behavior" +} +empty_args_body() +{ + atf_check -o inline:"1\n" \ + -x "cd $(atf_get_srcdir) && ./execve_helper execve_argc_helper" + + # Historically we allowed argc == 0, while execve(2) claimed we didn't. + # execve() should kick back an EINVAL now. We verified the helper was + # there/working in the check just above. + atf_check -s exit:1 \ + -e match:".+Invalid argument$" \ + -x "cd $(atf_get_srcdir) && ./execve_helper -n execve_argc_helper" +} + atf_init_test_cases() { atf_add_test_case bad_interp_len @@ -111,5 +128,6 @@ atf_init_test_cases() atf_add_test_case script_arg_nospace atf_add_test_case sparse_aout atf_add_test_case trunc_aout + atf_add_test_case empty_args }