Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144646415
D16099.id45103.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D16099.id45103.diff
View Options
Index: tests/sys/audit/process-control.c
===================================================================
--- tests/sys/audit/process-control.c
+++ tests/sys/audit/process-control.c
@@ -26,6 +26,8 @@
*/
#include <sys/param.h>
+#include <sys/capsicum.h>
+#include <sys/ioctl.h>
#include <sys/uio.h>
#include <sys/ktrace.h>
#include <sys/mman.h>
@@ -34,10 +36,14 @@
#include <sys/resource.h>
#include <sys/rtprio.h>
#include <sys/stat.h>
+#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/wait.h>
+#include <security/audit/audit_ioctl.h>
+
#include <atf-c.h>
+#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdint.h>
@@ -1472,6 +1478,107 @@
}
+ATF_TC_WITH_CLEANUP(cap_enter_success);
+ATF_TC_HEAD(cap_enter_success, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+ "cap_enter(2) call");
+}
+
+ATF_TC_BODY(cap_enter_success, tc)
+{
+ int capinfo;
+ size_t len = sizeof(capinfo);
+ const char *capname = "kern.features.security_capability_mode";
+ ATF_REQUIRE_EQ(0, sysctlbyname(capname, &capinfo, &len, NULL, 0));
+
+ /* Without CAPABILITY_MODE enabled, cap_enter() returns ENOSYS */
+ if (!capinfo)
+ atf_tc_skip("Capsicum is not enabled in the system");
+
+ FILE *pipefd = setup(fds, auclass);
+ ATF_REQUIRE((pid = fork()) != -1);
+ if (pid) {
+ snprintf(pcregex, sizeof(pcregex),
+ "cap_enter.*%d.*return,success", pid);
+ ATF_REQUIRE(wait(&status) != -1);
+ check_audit(fds, pcregex, pipefd);
+ }
+ else {
+ ATF_REQUIRE_EQ(0, cap_enter());
+ /*
+ * cap_enter() buffers up the local auditpipe, hence we need
+ * to flush the extraneous audit records before we proceed
+ */
+ if (ioctl(fds[0].fd, AUDITPIPE_FLUSH) < 0)
+ atf_tc_fail("Auditpipe flush: %s", strerror(errno));
+
+ _exit(0);
+ }
+}
+
+ATF_TC_CLEANUP(cap_enter_success, tc)
+{
+ cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(cap_getmode_success);
+ATF_TC_HEAD(cap_getmode_success, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+ "cap_getmode(2) call");
+}
+
+ATF_TC_BODY(cap_getmode_success, tc)
+{
+ int capinfo, modep;
+ size_t len = sizeof(capinfo);
+ const char *capname = "kern.features.security_capability_mode";
+ ATF_REQUIRE_EQ(0, sysctlbyname(capname, &capinfo, &len, NULL, 0));
+
+ /* Without CAPABILITY_MODE enabled, cap_getmode() returns ENOSYS */
+ if (!capinfo)
+ atf_tc_skip("Capsicum is not enabled in the system");
+
+ pid = getpid();
+ snprintf(pcregex, sizeof(pcregex), "cap_getmode.*%d.*success", pid);
+
+ FILE *pipefd = setup(fds, auclass);
+ ATF_REQUIRE_EQ(0, cap_getmode(&modep));
+ check_audit(fds, pcregex, pipefd);
+}
+
+ATF_TC_CLEANUP(cap_getmode_success, tc)
+{
+ cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(cap_getmode_failure);
+ATF_TC_HEAD(cap_getmode_failure, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+ "cap_getmode(2) call");
+}
+
+ATF_TC_BODY(cap_getmode_failure, tc)
+{
+ pid = getpid();
+ snprintf(pcregex, sizeof(pcregex), "cap_getmode.*%d.*failure", pid);
+
+ FILE *pipefd = setup(fds, auclass);
+ /* cap_getmode(2) can either fail with EFAULT or ENOSYS */
+ ATF_REQUIRE_EQ(-1, cap_getmode(NULL));
+ check_audit(fds, pcregex, pipefd);
+}
+
+ATF_TC_CLEANUP(cap_getmode_failure, tc)
+{
+ cleanup();
+}
+
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, fork_success);
@@ -1540,5 +1647,9 @@
ATF_TP_ADD_TC(tp, procctl_success);
ATF_TP_ADD_TC(tp, procctl_failure);
+ ATF_TP_ADD_TC(tp, cap_enter_success);
+ ATF_TP_ADD_TC(tp, cap_getmode_success);
+ ATF_TP_ADD_TC(tp, cap_getmode_failure);
+
return (atf_no_error());
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Feb 11, 2:19 PM (15 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28654494
Default Alt Text
D16099.id45103.diff (3 KB)
Attached To
Mode
D16099: Introduce tests for Capability mode System calls and _exit(2)
Attached
Detach File
Event Timeline
Log In to Comment