From nobody Thu Feb 10 20:22:22 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 3B7D019C0C96; Thu, 10 Feb 2022 20:22:24 +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 4Jvp7z1thCz3mgd; Thu, 10 Feb 2022 20:22:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644524543; 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=SMnTb1kfaAnb2dg/VDeCk4xrpNBwshlJKq2kALEMuR8=; b=ZOtrshysmcZlaa5CkCulaMDd2G8l3hm07C/T90vL3Bw9qUc/NyypmqtlrDW5160nBh6Ek4 aAk5y/TdKZ+gi4NwEIEcd/FHrIjdxoPuSshGNobe8wRqjHDDrnWiL9DtY5rIXgsfQXOs+Q Y0DYZaVf8uXKqtIuVVuONt/21MHPKmIbsVd6k/XtuoC9w1GgldS3+LQsG9ABBBnkyPNJZp 82ViW5K8IN/PgT01g1dA5pE8gr8fUrBPEQSvm7JgguPn8Ui2twfJ7byUOax++6Fb3pLLXG B8jNZEk5CR0ckkV59fIU6br0l6NDFSzQwljMwUgmJ/cOnAP3aKkTsGhr3a37Eg== 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 748A226B76; Thu, 10 Feb 2022 20:22:22 +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 21AKMM60089362; Thu, 10 Feb 2022 20:22:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21AKMMIX089361; Thu, 10 Feb 2022 20:22:22 GMT (envelope-from git) Date: Thu, 10 Feb 2022 20:22:22 GMT Message-Id: <202202102022.21AKMMIX089361@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: 888b2e616d3d - stable/12 - 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/12 X-Git-Reftype: branch X-Git-Commit: 888b2e616d3d692f5c85e1cd57ec5c7b23be776b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644524543; 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=SMnTb1kfaAnb2dg/VDeCk4xrpNBwshlJKq2kALEMuR8=; b=URR0IA/y8RwJJn0SMGYLYU/hj3/8hzcGEEvrvDelkX7RKzb263wZYVqiT2bkKwJSuac5KW DeXhhK2eoiheGpDmuUVgN/91mhuEN6+znYdo5mBxxPjgoJ40GKrbfbeSLCZph1sGo0Id/3 P/00BFPe2SIpFwsfQ4mc5FdUjL67Oy+ceWlQ1BPvbmOS58CcX+ApH0Piwdwd3sEAcyZ+0R 8Qjve1afWxDv1Hobh+NUFz4QQH9ZRDJqI2mQ1h3lOt8iNBIddonejIbN9OPfxxPYpIWXSO uaiVF3L7Oo3aDTWeCxiFrWmBKnVo9z1S/KjPGcO06U4bajXYo9VPsPLFSfioqw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644524543; a=rsa-sha256; cv=none; b=oDDE0pVyrfKc602t+qUegHCZ19TeYzPYcLcwBgWMM1vAoSTlfJjAbphGD4sFIdJidRsexs N8C18Kq21L9UvgUMI7ECAyo5Gk+6CJbGR+ISFWEfMkITnle9xBhECTZkGWPfZcDdpo4G5Z qKhmCp/Alnpgdg7V46D7N4Qdmk/uc6OjcQbHkWjDT4H6i0qfb9uQukPbf2fhUz4GC5CaOI 1l8ptDPLNsQZsk/M/CqmMEUCbtOwj+wV/6AaCnnz2+rfnQhPsZ0X7UAturCPxaIxZblp6u rTqil73hgex+gakwyiCDo0Xg4FoOaYqDZT0nfaD7dNQ6wWh4V4pqGf3kq7mKTQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=888b2e616d3d692f5c85e1cd57ec5c7b23be776b commit 888b2e616d3d692f5c85e1cd57ec5c7b23be776b Author: Kyle Evans AuthorDate: 2022-01-26 01:22:03 +0000 Commit: Kyle Evans CommitDate: 2022-02-10 20:17:55 +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 }