aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGordon Tetlow <gordon@FreeBSD.org>2020-12-01 19:34:45 +0000
committerGordon Tetlow <gordon@FreeBSD.org>2020-12-01 19:34:45 +0000
commit30710f108d29a61635778e82f300781a097caec4 (patch)
tree3275b383769be262d9fb30d4be1dbf12c024b871
parent1d21fe9cea3f530b4cfca495632d5a1595a32270 (diff)
downloadsrc-30710f108d29a61635778e82f300781a097caec4.tar.gz
src-30710f108d29a61635778e82f300781a097caec4.zip
Fix execve/fexecve system call auditing.
Approved by: so Security: FreeBSD-EN-20:19.audit
Notes
Notes: svn path=/releng/12.2/; revision=368249
-rw-r--r--sys/amd64/linux/linux_machdep.c3
-rw-r--r--sys/amd64/linux32/linux32_machdep.c3
-rw-r--r--sys/arm64/linux/linux_machdep.c3
-rw-r--r--sys/compat/freebsd32/freebsd32_misc.c2
-rw-r--r--sys/i386/linux/linux_machdep.c3
-rw-r--r--sys/kern/kern_exec.c3
-rw-r--r--sys/kern/subr_syscall.c10
7 files changed, 27 insertions, 0 deletions
diff --git a/sys/amd64/linux/linux_machdep.c b/sys/amd64/linux/linux_machdep.c
index 62c676f0b8da..774fab9bc698 100644
--- a/sys/amd64/linux/linux_machdep.c
+++ b/sys/amd64/linux/linux_machdep.c
@@ -81,6 +81,8 @@ __FBSDID("$FreeBSD$");
#include <x86/ifunc.h>
#include <x86/sysarch.h>
+#include <security/audit/audit.h>
+
#include <amd64/linux/linux.h>
#include <amd64/linux/linux_proto.h>
#include <compat/linux/linux_emul.h>
@@ -107,6 +109,7 @@ linux_execve(struct thread *td, struct linux_execve_args *args)
free(path, M_TEMP);
if (error == 0)
error = linux_common_execve(td, &eargs);
+ AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
return (error);
}
diff --git a/sys/amd64/linux32/linux32_machdep.c b/sys/amd64/linux32/linux32_machdep.c
index c853f6807a6b..42d9146c6df1 100644
--- a/sys/amd64/linux32/linux32_machdep.c
+++ b/sys/amd64/linux32/linux32_machdep.c
@@ -69,6 +69,8 @@ __FBSDID("$FreeBSD$");
#include <vm/vm.h>
#include <vm/vm_map.h>
+#include <security/audit/audit.h>
+
#include <compat/freebsd32/freebsd32_util.h>
#include <amd64/linux32/linux.h>
#include <amd64/linux32/linux32_proto.h>
@@ -138,6 +140,7 @@ linux_execve(struct thread *td, struct linux_execve_args *args)
free(path, M_TEMP);
if (error == 0)
error = linux_common_execve(td, &eargs);
+ AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
return (error);
}
diff --git a/sys/arm64/linux/linux_machdep.c b/sys/arm64/linux/linux_machdep.c
index 058cbe965b16..20e97d02c568 100644
--- a/sys/arm64/linux/linux_machdep.c
+++ b/sys/arm64/linux/linux_machdep.c
@@ -38,6 +38,8 @@ __FBSDID("$FreeBSD$");
#include <sys/proc.h>
#include <sys/sdt.h>
+#include <security/audit/audit.h>
+
#include <arm64/linux/linux.h>
#include <arm64/linux/linux_proto.h>
#include <compat/linux/linux_dtrace.h>
@@ -74,6 +76,7 @@ linux_execve(struct thread *td, struct linux_execve_args *uap)
free(path, M_TEMP);
if (error == 0)
error = linux_common_execve(td, &eargs);
+ AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
return (error);
}
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index 7916f2cefda7..c5a622ee228f 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -440,6 +440,7 @@ freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
if (error == 0)
error = kern_execve(td, &eargs, NULL);
post_execve(td, error, oldvmspace);
+ AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
return (error);
}
@@ -460,6 +461,7 @@ freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
error = kern_execve(td, &eargs, NULL);
}
post_execve(td, error, oldvmspace);
+ AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
return (error);
}
diff --git a/sys/i386/linux/linux_machdep.c b/sys/i386/linux/linux_machdep.c
index ba106d554ee4..ce177e78dc18 100644
--- a/sys/i386/linux/linux_machdep.c
+++ b/sys/i386/linux/linux_machdep.c
@@ -61,6 +61,8 @@ __FBSDID("$FreeBSD$");
#include <vm/vm.h>
#include <vm/vm_map.h>
+#include <security/audit/audit.h>
+
#include <i386/linux/linux.h>
#include <i386/linux/linux_proto.h>
#include <compat/linux/linux_emul.h>
@@ -111,6 +113,7 @@ linux_execve(struct thread *td, struct linux_execve_args *args)
free(newpath, M_TEMP);
if (error == 0)
error = linux_common_execve(td, &eargs);
+ AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
return (error);
}
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 3f72088644a2..f1a498bc6263 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -224,6 +224,7 @@ sys_execve(struct thread *td, struct execve_args *uap)
if (error == 0)
error = kern_execve(td, &args, NULL);
post_execve(td, error, oldvmspace);
+ AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
return (error);
}
@@ -251,6 +252,7 @@ sys_fexecve(struct thread *td, struct fexecve_args *uap)
error = kern_execve(td, &args, NULL);
}
post_execve(td, error, oldvmspace);
+ AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
return (error);
}
@@ -279,6 +281,7 @@ sys___mac_execve(struct thread *td, struct __mac_execve_args *uap)
if (error == 0)
error = kern_execve(td, &args, uap->mac_p);
post_execve(td, error, oldvmspace);
+ AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
return (error);
#else
return (ENOSYS);
diff --git a/sys/kern/subr_syscall.c b/sys/kern/subr_syscall.c
index 0eb7404f644d..728dfed7978d 100644
--- a/sys/kern/subr_syscall.c
+++ b/sys/kern/subr_syscall.c
@@ -142,6 +142,16 @@ syscallenter(struct thread *td)
AUDIT_SYSCALL_ENTER(sa->code, td);
error = (sa->callp->sy_call)(td, sa->args);
+
+ /*
+ * Note that some syscall implementations (e.g., sys_execve)
+ * will commit the audit record just before their final return.
+ * These were done under the assumption that nothing of interest
+ * would happen between their return and here, where we would
+ * normally commit the audit record. These assumptions will
+ * need to be revisited should any substantial logic be added
+ * above.
+ */
AUDIT_SYSCALL_EXIT(error, td);
/* Save the latest error return value. */