From owner-svn-src-all@freebsd.org Tue Oct 27 13:13:06 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 912C644CFFF; Tue, 27 Oct 2020 13:13:06 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CLBw23JPjz4pD2; Tue, 27 Oct 2020 13:13:06 +0000 (UTC) (envelope-from kevans@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 55951C1C0; Tue, 27 Oct 2020 13:13:06 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09RDD6L2048614; Tue, 27 Oct 2020 13:13:06 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09RDD48l048608; Tue, 27 Oct 2020 13:13:04 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202010271313.09RDD48l048608@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 27 Oct 2020 13:13:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r367080 - in stable/12/sys: amd64/linux amd64/linux32 arm64/linux compat/freebsd32 i386/linux kern X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/12/sys: amd64/linux amd64/linux32 arm64/linux compat/freebsd32 i386/linux kern X-SVN-Commit-Revision: 367080 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Oct 2020 13:13:06 -0000 Author: kevans Date: Tue Oct 27 13:13:04 2020 New Revision: 367080 URL: https://svnweb.freebsd.org/changeset/base/367080 Log: MFC r367002, r367060 r367002: audit: correct reporting of *execve(2) success r326145 corrected do_execve() to return EJUSTRETURN upon success so that important registers are not clobbered. This had the side effect of tapping out 'failures' for all *execve(2) audit records, which is less than useful for auditing purposes. Audit exec returns earlier, where we can know for sure that EJUSTRETURN translates to success. Note that this unsets TDP_AUDITREC as we commit the audit record, so the usual audit in the syscall return path will do nothing. r367060: audit: also correctly audit linux_execve() Linux execve() gets audited as AUE_EXECVE as well, we should also interpret the return from this correctly for the same reasoning as in r367002. PR: 249179, 242938 Modified: stable/12/sys/amd64/linux/linux_machdep.c stable/12/sys/amd64/linux32/linux32_machdep.c stable/12/sys/arm64/linux/linux_machdep.c stable/12/sys/compat/freebsd32/freebsd32_misc.c stable/12/sys/i386/linux/linux_machdep.c stable/12/sys/kern/kern_exec.c stable/12/sys/kern/subr_syscall.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/amd64/linux/linux_machdep.c ============================================================================== --- stable/12/sys/amd64/linux/linux_machdep.c Tue Oct 27 12:49:40 2020 (r367079) +++ stable/12/sys/amd64/linux/linux_machdep.c Tue Oct 27 13:13:04 2020 (r367080) @@ -81,6 +81,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include @@ -107,6 +109,7 @@ linux_execve(struct thread *td, struct linux_execve_ar free(path, M_TEMP); if (error == 0) error = linux_common_execve(td, &eargs); + AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td); return (error); } Modified: stable/12/sys/amd64/linux32/linux32_machdep.c ============================================================================== --- stable/12/sys/amd64/linux32/linux32_machdep.c Tue Oct 27 12:49:40 2020 (r367079) +++ stable/12/sys/amd64/linux32/linux32_machdep.c Tue Oct 27 13:13:04 2020 (r367080) @@ -69,6 +69,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include @@ -138,6 +140,7 @@ linux_execve(struct thread *td, struct linux_execve_ar free(path, M_TEMP); if (error == 0) error = linux_common_execve(td, &eargs); + AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td); return (error); } Modified: stable/12/sys/arm64/linux/linux_machdep.c ============================================================================== --- stable/12/sys/arm64/linux/linux_machdep.c Tue Oct 27 12:49:40 2020 (r367079) +++ stable/12/sys/arm64/linux/linux_machdep.c Tue Oct 27 13:13:04 2020 (r367080) @@ -38,6 +38,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include @@ -74,6 +76,7 @@ linux_execve(struct thread *td, struct linux_execve_ar free(path, M_TEMP); if (error == 0) error = linux_common_execve(td, &eargs); + AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td); return (error); } Modified: stable/12/sys/compat/freebsd32/freebsd32_misc.c ============================================================================== --- stable/12/sys/compat/freebsd32/freebsd32_misc.c Tue Oct 27 12:49:40 2020 (r367079) +++ stable/12/sys/compat/freebsd32/freebsd32_misc.c Tue Oct 27 13:13:04 2020 (r367080) @@ -440,6 +440,7 @@ freebsd32_execve(struct thread *td, struct freebsd32_e if (error == 0) error = kern_execve(td, &eargs, NULL, oldvmspace); 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_ error = kern_execve(td, &eargs, NULL, oldvmspace); } post_execve(td, error, oldvmspace); + AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td); return (error); } Modified: stable/12/sys/i386/linux/linux_machdep.c ============================================================================== --- stable/12/sys/i386/linux/linux_machdep.c Tue Oct 27 12:49:40 2020 (r367079) +++ stable/12/sys/i386/linux/linux_machdep.c Tue Oct 27 13:13:04 2020 (r367080) @@ -61,6 +61,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include @@ -111,6 +113,7 @@ linux_execve(struct thread *td, struct linux_execve_ar free(newpath, M_TEMP); if (error == 0) error = linux_common_execve(td, &eargs); + AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td); return (error); } Modified: stable/12/sys/kern/kern_exec.c ============================================================================== --- stable/12/sys/kern/kern_exec.c Tue Oct 27 12:49:40 2020 (r367079) +++ stable/12/sys/kern/kern_exec.c Tue Oct 27 13:13:04 2020 (r367080) @@ -224,6 +224,7 @@ sys_execve(struct thread *td, struct execve_args *uap) if (error == 0) error = kern_execve(td, &args, NULL, oldvmspace); 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 *ua error = kern_execve(td, &args, NULL, oldvmspace); } 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_execv if (error == 0) error = kern_execve(td, &args, uap->mac_p, oldvmspace); post_execve(td, error, oldvmspace); + AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td); return (error); #else return (ENOSYS); Modified: stable/12/sys/kern/subr_syscall.c ============================================================================== --- stable/12/sys/kern/subr_syscall.c Tue Oct 27 12:49:40 2020 (r367079) +++ stable/12/sys/kern/subr_syscall.c Tue Oct 27 13:13:04 2020 (r367080) @@ -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. */