From owner-svn-soc-all@freebsd.org Thu May 24 11:58:36 2018 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C1A12EEAC82 for ; Thu, 24 May 2018 11:58:36 +0000 (UTC) (envelope-from aniketp@FreeBSD.org) Received: from mxrelay.ysv.freebsd.org (mxrelay.ysv.freebsd.org [IPv6:2001:1900:2254:206a::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.ysv.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 584F286766 for ; Thu, 24 May 2018 11:58:36 +0000 (UTC) (envelope-from aniketp@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.ysv.freebsd.org (Postfix) with ESMTPS id 9A8D8976D for ; Thu, 24 May 2018 11:58:35 +0000 (UTC) (envelope-from aniketp@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id w4OBwZGh072802 for ; Thu, 24 May 2018 11:58:35 GMT (envelope-from aniketp@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id w4OBwXlO072776 for svn-soc-all@FreeBSD.org; Thu, 24 May 2018 11:58:33 GMT (envelope-from aniketp@FreeBSD.org) Date: Thu, 24 May 2018 11:58:33 GMT Message-Id: <201805241158.w4OBwXlO072776@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to aniketp@FreeBSD.org using -f From: aniketp@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r337247 - soc2018/aniketp/head/tests/sys/audit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 May 2018 11:58:37 -0000 Author: aniketp Date: Thu May 24 11:58:32 2018 New Revision: 337247 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=337247 Log: Add 2 execve(2) test-cases for exec audit class Added: soc2018/aniketp/head/tests/sys/audit/exec.c Modified: soc2018/aniketp/head/tests/sys/audit/Makefile Modified: soc2018/aniketp/head/tests/sys/audit/Makefile ============================================================================== --- soc2018/aniketp/head/tests/sys/audit/Makefile Wed May 23 11:36:06 2018 (r337246) +++ soc2018/aniketp/head/tests/sys/audit/Makefile Thu May 24 11:58:32 2018 (r337247) @@ -6,8 +6,10 @@ ATF_TESTS_C+= file-delete ATF_TESTS_C+= file-read ATF_TESTS_C+= file-write +ATF_TESTS_C+= file-close ATF_TESTS_C+= file-attribute-access ATF_TESTS_C+= file-attribute-modify +ATF_TESTS_C+= exec SRCS.file-create+= file-create.c SRCS.file-create+= utils.c @@ -17,10 +19,14 @@ SRCS.file-read+= utils.c SRCS.file-write+= file-write.c SRCS.file-write+= utils.c +SRCS.file-close+= file-close.c +SRCS.file-close+= utils.c SRCS.file-attribute-access+= file-attribute-access.c SRCS.file-attribute-access+= utils.c SRCS.file-attribute-modify+= file-attribute-modify.c SRCS.file-attribute-modify+= utils.c +SRCS.exec+= exec.c +SRCS.exec+= utils.c TEST_METADATA.file-create+= timeout="30" TEST_METADATA.file-create+= required_user="root" @@ -30,10 +36,14 @@ TEST_METADATA.file-read+= required_user="root" TEST_METADATA.file-write+= timeout="30" TEST_METADATA.file-write+= required_user="root" +TEST_METADATA.file-close+= timeout="30" +TEST_METADATA.file-close+= required_user="root" TEST_METADATA.file-attribute-access+= timeout="30" TEST_METADATA.file-attribute-access+= required_user="root" TEST_METADATA.file-attribute-modify+= timeout="30" TEST_METADATA.file-attribute-modify+= required_user="root" +TEST_METADATA.exec+= timeout="30" +TEST_METADATA.exec+= required_user="root" WARNS?= 6 Added: soc2018/aniketp/head/tests/sys/audit/exec.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2018/aniketp/head/tests/sys/audit/exec.c Thu May 24 11:58:32 2018 (r337247) @@ -0,0 +1,112 @@ +/*- + * Copyright 2018 Aniket Pandey + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include + +#include +#include +#include + +#include "utils.h" + +static pid_t pid; +static int status; +static struct pollfd fds[1]; +static char argument[] = "sample-argument"; + + +ATF_TC_WITH_CLEANUP(execve_success); +ATF_TC_HEAD(execve_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "execve(2) call"); +} + +ATF_TC_BODY(execve_success, tc) +{ + char bin[] = "/usr/bin/true"; + + const char *regex = "execve.*sample-argument"; + char *arg[] = {bin, argument, NULL}; + FILE *pipefd = setup(fds, "ex"); + + ATF_REQUIRE((pid = fork()) != -1); + if (pid) { + ATF_REQUIRE(wait(&status) != -1); + check_audit(fds, regex, pipefd); + } + else { + ATF_REQUIRE(execve(bin, arg, NULL) != -1); + } +} + +ATF_TC_CLEANUP(execve_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(execve_failure); +ATF_TC_HEAD(execve_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "execve(2) call"); +} + +ATF_TC_BODY(execve_failure, tc) +{ + char bin[] = "/does/not/exist"; + const char *regex = "execve.*sample-argument.*return,failure"; + char *arg[] = {bin, argument, NULL}; + FILE *pipefd = setup(fds, "ex"); + + ATF_REQUIRE((pid = fork()) != -1); + if (pid) { + ATF_REQUIRE(wait(&status) != -1); + check_audit(fds, regex, pipefd); + } + else { + ATF_REQUIRE_EQ(-1, execve(bin, arg, NULL)); + } +} + +ATF_TC_CLEANUP(execve_failure, tc) +{ + cleanup(); +} + + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, execve_success); + ATF_TP_ADD_TC(tp, execve_failure); + + return (atf_no_error()); +} +