From 8f817ae5aa4e10364643e89231da7a996958c8b3 Mon Sep 17 00:00:00 2001 From: Gordon Tetlow Date: Tue, 1 Dec 2020 19:34:45 +0000 Subject: [PATCH] Fix execve/fexecve system call auditing. Approved by: so Security: FreeBSD-EN-20:19.audit --- sys/amd64/linux/linux_machdep.c | 3 +++ sys/amd64/linux32/linux32_machdep.c | 3 +++ sys/arm64/linux/linux_machdep.c | 3 +++ sys/compat/freebsd32/freebsd32_misc.c | 2 ++ sys/i386/linux/linux_machdep.c | 3 +++ sys/kern/kern_exec.c | 3 +++ sys/kern/subr_syscall.c | 10 ++++++++++ 7 files changed, 27 insertions(+) diff --git a/sys/amd64/linux/linux_machdep.c b/sys/amd64/linux/linux_machdep.c index d52ad37a346..bb7088f805f 100644 --- a/sys/amd64/linux/linux_machdep.c +++ b/sys/amd64/linux/linux_machdep.c @@ -81,6 +81,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include @@ -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 c498d548e2f..d8fb0e1ba77 100644 --- a/sys/amd64/linux32/linux32_machdep.c +++ b/sys/amd64/linux32/linux32_machdep.c @@ -69,6 +69,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include @@ -143,6 +145,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 ef6faf27545..32518d7d90e 100644 --- a/sys/arm64/linux/linux_machdep.c +++ b/sys/arm64/linux/linux_machdep.c @@ -38,6 +38,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include @@ -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 3585bc6191d..dc96d8f3215 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 0753986182b..4ab10f2cf1d 100644 --- a/sys/i386/linux/linux_machdep.c +++ b/sys/i386/linux/linux_machdep.c @@ -61,6 +61,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include @@ -116,6 +118,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 7a125fc9893..d06c0aef4d9 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 6c70ddc9f78..877a8c96842 100644 --- a/sys/kern/subr_syscall.c +++ b/sys/kern/subr_syscall.c @@ -133,6 +133,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. */ -- 2.45.0