From owner-svn-src-head@freebsd.org Tue Jun 26 19:26:29 2018 Return-Path: Delivered-To: svn-src-head@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 7ADF910138D4; Tue, 26 Jun 2018 19:26:08 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2C44D805D1; Tue, 26 Jun 2018 19:26:08 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0D4B7188CA; Tue, 26 Jun 2018 19:26:08 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5QJQ7GP013624; Tue, 26 Jun 2018 19:26:07 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5QJQ7RV013623; Tue, 26 Jun 2018 19:26:07 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201806261926.w5QJQ7RV013623@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Tue, 26 Jun 2018 19:26:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335677 - head/tests/sys/audit X-SVN-Group: head X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: head/tests/sys/audit X-SVN-Commit-Revision: 335677 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jun 2018 19:26:30 -0000 Author: asomers Date: Tue Jun 26 19:26:07 2018 New Revision: 335677 URL: https://svnweb.freebsd.org/changeset/base/335677 Log: audit(4): add tests for pipe, posix_openpt, shm_open, and shm_unlink Submitted by: aniketp MFC after: 2 weeks Sponsored by: Google, Inc. (GSoC 2018) Differential Revision: https://reviews.freebsd.org/D15963 Modified: head/tests/sys/audit/inter-process.c Modified: head/tests/sys/audit/inter-process.c ============================================================================== --- head/tests/sys/audit/inter-process.c Tue Jun 26 19:13:49 2018 (r335676) +++ head/tests/sys/audit/inter-process.c Tue Jun 26 19:26:07 2018 (r335677) @@ -36,6 +36,7 @@ #include #include +#include #include #include "utils.h" @@ -47,7 +48,6 @@ struct msgstr { }; typedef struct msgstr msgstr_t; - static pid_t pid; static int msqid, shmid, semid; static union semun semarg; @@ -57,6 +57,7 @@ static struct shmid_ds shmbuff; static struct semid_ds sembuff; static char ipcregex[BUFFSIZE]; static const char *auclass = "ip"; +static char path[BUFFSIZE] = "/fileforaudit"; static unsigned short semvals[BUFFSIZE]; @@ -1398,6 +1399,194 @@ ATF_TC_CLEANUP(semctl_illegal_command, tc) } +ATF_TC_WITH_CLEANUP(shm_open_success); +ATF_TC_HEAD(shm_open_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "shm_open(2) call"); +} + +ATF_TC_BODY(shm_open_success, tc) +{ + pid = getpid(); + snprintf(ipcregex, sizeof(ipcregex), "shm_open.*%d.*ret.*success", pid); + + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE(shm_open(SHM_ANON, O_CREAT | O_TRUNC | O_RDWR, 0600) != -1); + check_audit(fds, ipcregex, pipefd); +} + +ATF_TC_CLEANUP(shm_open_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(shm_open_failure); +ATF_TC_HEAD(shm_open_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "shm_open(2) call"); +} + +ATF_TC_BODY(shm_open_failure, tc) +{ + const char *regex = "shm_open.*fileforaudit.*return,failure"; + FILE *pipefd = setup(fds, auclass); + /* Failure reason: File does not exist */ + ATF_REQUIRE_EQ(-1, shm_open(path, O_TRUNC | O_RDWR, 0600)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(shm_open_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(shm_unlink_success); +ATF_TC_HEAD(shm_unlink_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "shm_unlink(2) call"); +} + +ATF_TC_BODY(shm_unlink_success, tc) +{ + /* Build an absolute path to a file in the test-case directory */ + char dirpath[50]; + ATF_REQUIRE(getcwd(dirpath, sizeof(dirpath)) != NULL); + strlcat(dirpath, path, sizeof(dirpath)); + ATF_REQUIRE(shm_open(dirpath, O_CREAT | O_TRUNC | O_RDWR, 0600) != -1); + + const char *regex = "shm_unlink.*fileforaudit.*return,success"; + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE_EQ(0, shm_unlink(dirpath)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(shm_unlink_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(shm_unlink_failure); +ATF_TC_HEAD(shm_unlink_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "shm_unlink(2) call"); +} + +ATF_TC_BODY(shm_unlink_failure, tc) +{ + const char *regex = "shm_unlink.*fileforaudit.*return,failure"; + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE_EQ(-1, shm_unlink(path)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(shm_unlink_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(pipe_success); +ATF_TC_HEAD(pipe_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "pipe(2) call"); +} + +ATF_TC_BODY(pipe_success, tc) +{ + int filedesc[2]; + pid = getpid(); + snprintf(ipcregex, sizeof(ipcregex), "pipe.*%d.*return,success", pid); + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE_EQ(0, pipe(filedesc)); + check_audit(fds, ipcregex, pipefd); + + close(filedesc[0]); + close(filedesc[1]); +} + +ATF_TC_CLEANUP(pipe_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(pipe_failure); +ATF_TC_HEAD(pipe_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "pipe(2) call"); +} + +ATF_TC_BODY(pipe_failure, tc) +{ + pid = getpid(); + snprintf(ipcregex, sizeof(ipcregex), "pipe.*%d.*return.failure", pid); + + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE_EQ(-1, pipe(NULL)); + check_audit(fds, ipcregex, pipefd); +} + +ATF_TC_CLEANUP(pipe_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(posix_openpt_success); +ATF_TC_HEAD(posix_openpt_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "posix_openpt(2) call"); +} + +ATF_TC_BODY(posix_openpt_success, tc) +{ + int filedesc; + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE((filedesc = posix_openpt(O_RDWR | O_NOCTTY)) != -1); + /* Check for the presence of filedesc in the audit record */ + snprintf(ipcregex, sizeof(ipcregex), + "posix_openpt.*return,success,%d", filedesc); + check_audit(fds, ipcregex, pipefd); + close(filedesc); +} + +ATF_TC_CLEANUP(posix_openpt_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(posix_openpt_failure); +ATF_TC_HEAD(posix_openpt_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "posix_openpt(2) call"); +} + +ATF_TC_BODY(posix_openpt_failure, tc) +{ + const char *regex = "posix_openpt.*return,failure : Invalid argument"; + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE_EQ(-1, posix_openpt(-1)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(posix_openpt_failure, tc) +{ + cleanup(); +} + + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, msgget_success); @@ -1456,6 +1645,16 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, semctl_rmid_success); ATF_TP_ADD_TC(tp, semctl_rmid_failure); ATF_TP_ADD_TC(tp, semctl_illegal_command); + + ATF_TP_ADD_TC(tp, shm_open_success); + ATF_TP_ADD_TC(tp, shm_open_failure); + ATF_TP_ADD_TC(tp, shm_unlink_success); + ATF_TP_ADD_TC(tp, shm_unlink_failure); + + ATF_TP_ADD_TC(tp, pipe_success); + ATF_TP_ADD_TC(tp, pipe_failure); + ATF_TP_ADD_TC(tp, posix_openpt_success); + ATF_TP_ADD_TC(tp, posix_openpt_failure); return (atf_no_error()); }