From nobody Fri Jan 17 13:40:56 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YZLV02FwNz5l0dm; Fri, 17 Jan 2025 13:40:56 +0000 (UTC) (envelope-from git@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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YZLV01n3kz3mcF; Fri, 17 Jan 2025 13:40:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737121256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NmwoLqLvyVn4GTIcibPkH22sz+nCaE5vhir23AuoobM=; b=hgZDo27wVct9fy/2G2N+O1y06HWLKbq+IdWpBX1WFYk54p327iZ+AGZguu1WiH/ZrJnaDU IC6cucowN3zc7P/QOz9OAwn8q5XaFgJDv56khH1KQs9pvbkQA0+dkyxZMDjGdyc4tZldEk WufKUmR3v90PFk8PmG3VuVt64r85r5N2McauFUQ6hOdnS+8ErXywjuQfvVykT8orb7O0JT vSfWdRo3twhfCxCor5MpQWg0V89w2UrmYI6xluNDAyY94BBWkCdHWmzk7QnOqV32zVGOVj gXAbW93TVV6XMUmSJolGW5EEBpSJlsBevWHjqKYG53AZsRllPh8E7lElvzepWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737121256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NmwoLqLvyVn4GTIcibPkH22sz+nCaE5vhir23AuoobM=; b=HHmbkWhKtJorXBL++gvvicsfDK8Q1xg9gO26r5bRBSPyMtD/+UpA3FD8hDbrojBhqxGmqo /1SmebRwSKQogldcVSUKKCbxwg9OSfLYBGW3H5+KFaVf+HBDWOwh9bsZYMIhq8UeFf9oc0 YirLkIk7k+ggYPfDDOtmkCq7M5oor80E2UvXcC9zWKuXi8AQxiAdut5VCZWTfWMmGE4ij6 FroWVPqFRUSzclh6EGDloniBvzP0sa2uifEaufrycbPQi+Q39Fqt/7MgAl2U27UeFtusiS OpOlgEpCgxoG9Atg4IBl8rWT9mLXnyw6PnJ3hUMpc9bJP7fQ2uuJudQfz/hgBQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737121256; a=rsa-sha256; cv=none; b=bjt+CBuIroowRncUMjZNli4FDwKyHGZxcme2dDpls5ARugyko5/R/1anmKDX2NGdKsqyf6 akF1CSYksrdi8Px1ED6hujl3fTk/j9A5zqcGpKeqosj3wpMSmM9oFaSSGaDHhsLIhIQQ7t yya6i/GhC+9gVwc2FKEiOc0+v+TYm8TDcbSfaMg1vSftAdo3XjNaS1SH8wbc+vfDELpfxk QZhMQ6P8qXxeogo2somV0ElVDGKX3DmaDoZWxOKbfWXBDlNFxK93fhF6UeLv2W9evwDuGI AuYEmZrQx5lIt2Efg3OmzRjGVUTx/8UoE21+EV2JwHcYc/gLVjqY5+v650YO5g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YZLV00rB3z59W; Fri, 17 Jan 2025 13:40:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50HDeuds097179; Fri, 17 Jan 2025 13:40:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50HDeuor097176; Fri, 17 Jan 2025 13:40:56 GMT (envelope-from git) Date: Fri, 17 Jan 2025 13:40:56 GMT Message-Id: <202501171340.50HDeuor097176@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 1bf531bcd791 - stable/13 - audit: Fix short-circuiting in syscallenter() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1bf531bcd791794a39511359fbab612944a9e7b2 Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1bf531bcd791794a39511359fbab612944a9e7b2 commit 1bf531bcd791794a39511359fbab612944a9e7b2 Author: Mark Johnston AuthorDate: 2025-01-14 14:19:24 +0000 Commit: Mark Johnston CommitDate: 2025-01-17 13:40:49 +0000 audit: Fix short-circuiting in syscallenter() syscallenter() has a slow path to handle syscall auditing and dtrace syscall tracing. It uses AUDIT_SYSCALL_ENTER() to check whether to take the slow path, but this macro also has side effects: it writes the audit log entry. When systrace (dtrace syscall tracing) is enabled, this would get short-circuited, and we end up not writing audit log entries. Introduce a pure macro to check whether auditing is enabled, use it in syscallenter() instead of AUDIT_SYSCALL_ENTER(). Reviewed by: kib Reported by: Joe Duin Fixes: 2f7292437d0c ("Merge audit and systrace checks") MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D48448 (cherry picked from commit f78fe930854cac6eed55859b45e0a7b5d87189d6) --- sys/kern/subr_syscall.c | 8 +++++--- sys/security/audit/audit.h | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sys/kern/subr_syscall.c b/sys/kern/subr_syscall.c index 67ec87d2d563..9ad11b81b6fa 100644 --- a/sys/kern/subr_syscall.c +++ b/sys/kern/subr_syscall.c @@ -140,9 +140,8 @@ syscallenter(struct thread *td) sy_thr_static = (se->sy_thrcnt & SY_THR_STATIC) != 0; - if (__predict_false(SYSTRACE_ENABLED() || - AUDIT_SYSCALL_ENTER(sa->code, td) || - !sy_thr_static)) { + if (__predict_false(AUDIT_SYSCALL_ENABLED() || + SYSTRACE_ENABLED() || !sy_thr_static)) { if (!sy_thr_static) { error = syscall_thread_enter(td, &se); sy_thr_static = (se->sy_thrcnt & SY_THR_STATIC) != 0; @@ -157,6 +156,9 @@ syscallenter(struct thread *td) if (__predict_false(se->sy_entry != 0)) (*systrace_probe_func)(sa, SYSTRACE_ENTRY, 0); #endif + + AUDIT_SYSCALL_ENTER(sa->code, td); + error = (se->sy_call)(td, sa->args); /* Save the latest error return value. */ if (__predict_false((td->td_pflags & TDP_NERRNO) != 0)) diff --git a/sys/security/audit/audit.h b/sys/security/audit/audit.h index b87dd52e0773..28e84dce79f3 100644 --- a/sys/security/audit/audit.h +++ b/sys/security/audit/audit.h @@ -389,9 +389,11 @@ void audit_thread_free(struct thread *td); audit_arg_vnode2((vp)); \ } while (0) +#define AUDIT_SYSCALL_ENABLED() audit_syscalls_enabled + #define AUDIT_SYSCALL_ENTER(code, td) ({ \ bool _audit_entered = false; \ - if (__predict_false(audit_syscalls_enabled)) { \ + if (audit_syscalls_enabled) { \ audit_syscall_enter(code, td); \ _audit_entered = true; \ } \ @@ -468,6 +470,7 @@ void audit_thread_free(struct thread *td); #define AUDITING_TD(td) 0 +#define AUDIT_SYSCALL_ENABLED() 0 #define AUDIT_SYSCALL_ENTER(code, td) 0 #define AUDIT_SYSCALL_EXIT(error, td)