audit: Measure and reduce syscall filtering overhead
cover audit: Measure and reduce syscall filtering overhead
This series adds a repeatable microbenchmark for audit's fixed syscall overhead and uses it to address two cases where audit continues doing work which cannot produce a record.
Patch 1 adds audit_bench, a manually run getpid(2) microbenchmark under tools/testing/selftests/audit. It leaves policy management to the caller so the same workload can measure different rule configurations without silently changing the system policy.
Patch 2 fixes audit_n_rules and audit_signals accounting when rules are removed automatically with a watch or tree, or after an LSM rule update fails. These paths could leave the counters nonzero after the last applicable rule had disappeared, causing every subsequent syscall to allocate a non-dummy audit context. It also centralizes rule accounting so all rule removal paths share the same bookkeeping.
The median getpid latency in the same unpinned VM was:
no rules stale state fixed automatically removed watch 38 ns 55 ns 38 ns automatically removed tree 38 ns 59 ns 38 ns
Patch 3 builds on those lifecycle helpers. It maintains an aggregate mask of the syscall numbers present in exit rules and checks that mask before walking the exit filter list. The mask is architecture-independent and therefore conservative: overlapping syscall numbers may cause an unnecessary scan, but cannot suppress a match.
For an unrelated getpid workload, the median latency scaled as follows:
exit rules 1 32 128 256 before 55 ns 71 ns 428 ns 791 ns after 55 ns 55 ns 55 ns 55 ns
The aggregate mask is updated through the centralized accounting helpers. Insertion sets the relevant bits before publishing the rule with list_add_rcu(); removal unlinks the rule before clearing them. This keeps the lockless rejection test conservative during concurrent rule changes.
The series does not change the audit userspace ABI or rule matching semantics. The benchmark and complete reproduction procedures are documented in the individual patches.
---
Stanislav Kinsburskii (3):
selftests/audit: Add syscall overhead benchmark
audit: Fix filter rule accounting after automatic removal
audit: Skip exit filtering for syscalls without rules
MAINTAINERS | 1 + kernel/audit.h | 7 + kernel/audit_tree.c | 1 + kernel/audit_watch.c | 2 + kernel/auditfilter.c | 140 +++++++++++------ kernel/auditsc.c | 13 ++ tools/testing/selftests/Makefile | 1 + tools/testing/selftests/audit/.gitignore | 2 + tools/testing/selftests/audit/Makefile | 9 ++ tools/testing/selftests/audit/README | 30 ++++ tools/testing/selftests/audit/audit_bench.c | 227 ++++++++++++++++++++++++++++ 11 files changed, 389 insertions(+), 44 deletions(-)
---
base-commit: ea2bff00da89d7767d677bb68470130ba96f4928
change-id: 20260806-audit-96a1e71d38b1
Best regards,
Signature · 1 line
Stanislav Kinsburskii <[email protected]>
PATCH 1/3 selftests/audit: Add syscall overhead benchmark
Add a microbenchmark which repeatedly invokes getpid(2) and reports the per-operation latency across multiple repetitions. The workload avoids filesystem and other syscall-specific work so the fixed audit syscall overhead remains visible.
The benchmark deliberately leaves audit policy management to the caller. This permits comparisons with increasing numbers of unrelated exit rules and with automatically removed watch or tree rules without modifying an existing policy unexpectedly.
--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/audit/.gitignore | 2 + tools/testing/selftests/audit/Makefile | 9 ++ tools/testing/selftests/audit/README | 30 ++++ tools/testing/selftests/audit/audit_bench.c | 227 ++++++++++++++++++++++++++++ 6 files changed, 270 insertions(+)
MAINTAINERS +1 -0
@@ -4365,6 +4365,7 @@ F: include/linux/audit_arch.h F: include/uapi/linux/audit.h F: kernel/audit* F: lib/*audit.c +F: tools/testing/selftests/audit/ K: \baudit_[a-z_0-9]\+\b AUTOFDO BUILD
tools/testing/selftests/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 TARGETS += acct +TARGETS += audit TARGETS += alloc_tag TARGETS += alsa TARGETS += amd-pstate
tools/testing/selftests/audit/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +audit_bench
tools/testing/selftests/audit/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 + +CFLAGS += -O2 -Wall -Wextra +LDLIBS += -lm + +TEST_GEN_PROGS_EXTENDED := audit_bench +TEST_FILES := README + +include ../lib.mk
tools/testing/selftests/audit/README new file +30 -0
@@ -0,0 +1,30 @@ +Audit syscall overhead benchmark +================================ + +Build it with: + + make -C tools/testing/selftests/audit + +The benchmark repeatedly invokes getpid(2). It does not install or remove +audit rules. Configure the policy explicitly with auditctl, then run the same +workload for each policy. + +For example: + + sudo auditctl -a always,exit -F arch=b64 -S openat + sudo ./tools/testing/selftests/audit/audit_bench + sudo auditctl -d always,exit -F arch=b64 -S openat + +The getpid workload exposes the fixed per-syscall audit overhead without +adding filesystem work. Useful comparisons are no rules, increasing numbers +of unrelated syscall rules, and a clean state versus one where a watch or +tree rule was removed automatically. Keep the machine idle, pin with --cpu +when possible, and collect profiles with perf stat and perf record. Report +the kernel commit, CPU model, audit status, policy and auditd state with every +comparison. + +After printing each repetition, the benchmark reports the median, arithmetic +mean, sample standard deviation, coefficient of variation and observed range +of per-operation latency across repetitions. The coefficient of variation +makes noisy runs easy to identify; increase the iteration count or investigate +system noise when it is high.
tools/testing/selftests/audit/audit_bench.c new file +227 -0
227 lines not on this page · raw message
Signature · 1 line
2.43.0
Paul Moore
maintainerRe: [PATCH 1/3] selftests/audit: Add syscall overhead benchmark
Quoted 12 lines · On Aug 6, 2026 Stanislav Kinsburskii <[email protected]> wrote:
Add a microbenchmark which repeatedly invokes getpid(2) and reports the per-operation latency across multiple repetitions. The workload avoids filesystem and other syscall-specific work so the fixed audit syscall overhead remains visible.
The benchmark deliberately leaves audit policy management to the caller. This permits comparisons with increasing numbers of unrelated exit rules and with automatically removed watch or tree rules without modifying an existing policy unexpectedly.
Signed-off-by Stanislav Kinsburskii <[email protected]>
Quoted 8 lines
--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/audit/.gitignore | 2 + tools/testing/selftests/audit/Makefile | 9 ++ tools/testing/selftests/audit/README | 30 ++++ tools/testing/selftests/audit/audit_bench.c | 227 ++++++++++++++++++++++++++++ 6 files changed, 270 insertions(+)
Thanks for this Stanislav, but I'm not certain that we want to merge this into the kernel and have this become the defacto standard for audit performance. It's a simple, easy to understand test, but I worry that it might be too simplistic to properly characterize audit performance.
... and no, I'm sorry, but I don't have a better suggestion off the top of my head :)
However, audit_bench might be useful as part of the manual_tests in the audit-testsuite?
https://github.com/linux-audit/audit-testsuite
--
paul-moore.com
Re: [PATCH 1/3] selftests/audit: Add syscall overhead benchmark
Quoted 27 lines · Paul Moore
Quoted 12 lines · On Aug 6, 2026 Stanislav Kinsburskii <[email protected]> wrote:
Add a microbenchmark which repeatedly invokes getpid(2) and reports the per-operation latency across multiple repetitions. The workload avoids filesystem and other syscall-specific work so the fixed audit syscall overhead remains visible.
The benchmark deliberately leaves audit policy management to the caller. This permits comparisons with increasing numbers of unrelated exit rules and with automatically removed watch or tree rules without modifying an existing policy unexpectedly.
Signed-off-by Stanislav Kinsburskii <[email protected]>Quoted 8 lines
--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/audit/.gitignore | 2 + tools/testing/selftests/audit/Makefile | 9 ++ tools/testing/selftests/audit/README | 30 ++++ tools/testing/selftests/audit/audit_bench.c | 227 ++++++++++++++++++++++++++++ 6 files changed, 270 insertions(+)Thanks for this Stanislav, but I'm not certain that we want to merge this into the kernel and have this become the defacto standard for audit performance. It's a simple, easy to understand test, but I worry that it might be too simplistic to properly characterize audit performance.
Quoted 8 lines
... and no, I'm sorry, but I don't have a better suggestion off the top of my head :)
However,
audit_benchmight be useful as part of themanual_testsin the audit-testsuite?
Sure, here is a PR: https://github.com/linux-audit/audit-testsuite/pull/129
Thanks,
Stanislav
Quoted 2 lines
--
paul-moore.com
PATCH 2/3 audit: Fix filter rule accounting after automatic removal
In reply to Stanislav KinsburskiiThe audit_n_rules and audit_signals counters are incremented when filter rules are installed and decremented by the explicit rule deletion path. Rules can also disappear when a watch or tree is removed, or when an LSM rule cannot be reconstructed, but those paths do not update the counters.
As a result, audit_n_rules can remain nonzero after the last applicable rule has gone away, causing subsequent syscalls to allocate non-dummy audit contexts unnecessarily. A stale audit_signals value similarly causes unnecessary signal auditing work.
This can be reproduced for an inode watch with:
mkdir /tmp/audit-n-rules-bench
touch /tmp/audit-n-rules-bench/watched
auditctl -w /tmp/audit-n-rules-bench/watched -p r \
-k audit_n_rules_bench
rm /tmp/audit-n-rules-bench/watched
rmdir /tmp/audit-n-rules-benchThe rm updates the watch after its inode disappears, and the rmdir causes audit_remove_parent_watches() to remove the rule. For an audit tree, the kill_rules() path can be reproduced with:
mkdir /tmp/audit-kill-rules
auditctl -a always,exit -F arch=b64 \
-F dir=/tmp/audit-kill-rules -F perm=r \
-k audit_kill_rules_test
rmdir /tmp/audit-kill-rulesIn both cases, auditctl -l reports no rules after the directory is removed. Run the following before installing the rule and again after it has disappeared:
audit_bench --iterations 10000000 --repetitions 10
For the inode watch, the same VM produced:
no rules:
median=38 mean=39 stddev=4 (10%) range=38..53 ns/op
automatically removed, before this fix:
median=55 mean=56 stddev=3 (5%) range=55..65 ns/op
automatically removed, with this fix:
median=38 mean=39 stddev=4 (10%) range=38..52 ns/opFor the audit tree, it produced:
no rules:
median=38 mean=39 stddev=4 (9%) range=38..52 ns/op
automatically removed, before this fix:
median=59 mean=60 stddev=2 (3%) range=59..67 ns/op
automatically removed, with this fix:
median=38 mean=39 stddev=4 (9%) range=38..52 ns/opReboot between the unpatched and patched tests because an already stale counter cannot be repaired by deleting rules which are no longer present.
Factor the existing counter updates into common rule insertion and removal helpers and call the removal helper from every automatic removal path. All of these updates remain serialized by audit_filter_mutex.
--- kernel/audit.h | 5 +++ kernel/audit_tree.c | 1 + kernel/audit_watch.c | 2 ++ kernel/auditfilter.c | 86 +++++++++++++++++++++++++--------------------------- 4 files changed, 50 insertions(+), 44 deletions(-)
kernel/audit.h +5 -0
@@ -272,6 +272,9 @@ extern void audit_put_tty(struct tty_struct *tty);/* audit watch/mark/tree functions */ extern unsigned int audit_serial (void );#ifdef CONFIG_AUDITSYSCALL +void audit_rule_account (const struct audit_krule *rule); +void audit_rule_unaccount (const struct audit_krule *rule); +extern int auditsc_get_stamp (struct audit_context *ctx,struct audit_stamp *stamp);
@@ -315,6 +318,8 @@ extern void audit_filter_inodes(struct task_struct *tsk, struct audit_context *ctx);extern struct list_head *audit_killed_trees (void );#else /* CONFIG_AUDITSYSCALL */ +#define audit_rule_account (...) do { } while (0) +#define audit_rule_unaccount (...) do { } while (0)#define auditsc_get_stamp (c, s) 0#define audit_put_watch (w) do { } while (0)#define audit_get_watch (w) do { } while (0)
kernel/audit_tree.c +1 -0
@@ -558,6 +558,7 @@ static void kill_rules(struct audit_context *context, struct audit_tree *tree) rule->tree =NULL ;list_del_rcu (&entry->list);list_del (&entry->rule.list); +audit_rule_unaccount (rule);call_rcu (&entry->rcu, audit_free_rule_rcu); } }
kernel/audit_watch.c +2 -0
@@ -284,6 +284,7 @@ static void audit_update_watch(struct audit_parent *parent, nentry =audit_dupe_rule (&oentry->rule, ctx);if (IS_ERR (nentry)) {list_del (&oentry->rule.list); +audit_rule_unaccount (r);audit_panic ("error updating watch, removing" ); }else {int h =audit_hash_ino (ino);
@@ -336,6 +337,7 @@ static void audit_remove_parent_watches(struct audit_parent *parent)list_del (&r->rlist);list_del (&r->list);list_del_rcu (&e->list); +audit_rule_unaccount (r);call_rcu (&e->rcu, audit_free_rule_rcu); }audit_remove_watch (w);
kernel/auditfilter.c +42 -44
146 lines not on this page · raw message
Signature · 1 line
2.43.0
Paul Moore
maintainerRe: [PATCH 2/3] audit: Fix filter rule accounting after automatic removal
Quoted 64 lines · On Aug 6, 2026 Stanislav Kinsburskii <[email protected]> wrote:
The
audit_n_rulesandaudit_signalscounters are incremented when filter rules are installed and decremented by the explicit rule deletion path. Rules can also disappear when a watch or tree is removed, or when an LSM rule cannot be reconstructed, but those paths do not update the counters.As a result,
audit_n_rulescan remain nonzero after the last applicable rule has gone away, causing subsequent syscalls to allocate non-dummy audit contexts unnecessarily. A staleaudit_signalsvalue similarly causes unnecessary signal auditing work.This can be reproduced for an inode watch with:
mkdir /tmp/audit-n-rules-bench touch /tmp/audit-n-rules-bench/watched auditctl -w /tmp/audit-n-rules-bench/watched -p r \ -k audit_n_rules_bench rm /tmp/audit-n-rules-bench/watched rmdir /tmp/audit-n-rules-benchThe rm updates the watch after its inode disappears, and the rmdir causes
audit_remove_parent_watches()to remove the rule. For an audit tree, thekill_rules()path can be reproduced with:mkdir /tmp/audit-kill-rules auditctl -a always,exit -F arch=b64 \ -F dir=/tmp/audit-kill-rules -F perm=r \ -k audit_kill_rules_test rmdir /tmp/audit-kill-rulesIn both cases, auditctl -l reports no rules after the directory is removed. Run the following before installing the rule and again after it has disappeared:
audit_bench --iterations 10000000 --repetitions 10For the inode watch, the same VM produced:
no rules:
median=38 mean=39 stddev=4 (10%) range=38..53 ns/op automatically removed, before this fix: median=55 mean=56 stddev=3 (5%) range=55..65 ns/op automatically removed, with this fix: median=38 mean=39 stddev=4 (10%) range=38..52 ns/opFor the audit tree, it produced:
no rules:
median=38 mean=39 stddev=4 (9%) range=38..52 ns/op automatically removed, before this fix: median=59 mean=60 stddev=2 (3%) range=59..67 ns/op automatically removed, with this fix: median=38 mean=39 stddev=4 (9%) range=38..52 ns/opReboot between the unpatched and patched tests because an already stale counter cannot be repaired by deleting rules which are no longer present.
Factor the existing counter updates into common rule insertion and removal helpers and call the removal helper from every automatic removal path. All of these updates remain serialized by
audit_filter_mutex.Fixes 471a5c7c8391 ("[PATCH] introduce audit rules counter")Fixes e54dc2431d74 ("[PATCH] audit signal recipients")Signed-off-by Stanislav Kinsburskii <[email protected]>
Quoted 6 lines
--- kernel/audit.h | 5 +++ kernel/audit_tree.c | 1 + kernel/audit_watch.c | 2 ++ kernel/auditfilter.c | 86 +++++++++++++++++++++++++--------------------------- 4 files changed, 50 insertions(+), 44 deletions(-)
This looks good to me. I'm going to merge this into audit/dev, but I'm going to drop the "audit_bench" references from the commit description as I don't think we want that tool in the kernel sources right now.
Thanks Stanislav, both for finding the bug and providing a clean, elegant fix.
--
paul-moore.com
PATCH 3/3 audit: Skip exit filtering for syscalls without rules
In reply to Stanislav KinsburskiiAudit walks every exit filter rule for each audited syscall, even when no rule contains the current syscall number. Policies with many unrelated rules therefore add linear overhead to otherwise uninteresting syscalls.
Maintain a reference count for each syscall bit present in exit filter rules and derive an aggregate interest mask. Update the mask through the centralized rule lifecycle helpers, which cover explicit and automatic rule removal. Use the mask as a lockless rejection test before entering the exit filter RCU traversal.
The mask is architecture-independent. Syscall number overlap between architectures can cause an unnecessary scan but cannot suppress a match.
The aggregate bit must be set before list_add_rcu() publishes a new rule. Otherwise, a reader could observe the rule after publication while the aggregate mask still rejects its syscall. Move audit_rule_account() before the list insertion to provide this ordering. Rule removal already uses the inverse safe ordering: it unlinks the rule before clearing the aggregate bit, so a concurrent reader can only perform an unnecessary scan, not miss a rule.
To measure the effect, install increasing numbers of distinct statx rules in a disposable VM and benchmark the unrelated getpid syscall after each set is installed:
for nr_rules in 1 32 128 256; do
auditctl -D
for uid in $(seq 1 $nr_rules); do
auditctl -a always,exit -F arch=b64 -S statx \
-F uid=$uid
done
audit_bench
doneWithout this change, the same unpinned VM produced:
1 rule:
median=55 ns/op
32 rules:
median=71 ns/op
128 rules:
median=428 ns/op
256 rules:
median=791 ns/opWith this change, it produced:
1 rule:
median=55 ns/op
32 rules:
median=55 ns/op
128 rules:
median=55 ns/op
256 rules:
median=55 ns/op--- kernel/audit.h | 2 ++ kernel/auditfilter.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++- kernel/auditsc.c | 13 ++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-)
kernel/audit.h +2 -0
@@ -272,6 +272,8 @@ extern void audit_put_tty(struct tty_struct *tty);/* audit watch/mark/tree functions */ extern unsigned int audit_serial (void );#ifdef CONFIG_AUDITSYSCALL +extern u32 audit_exit_filter_mask[AUDIT_BITMASK_SIZE ]; +void audit_rule_account (const struct audit_krule *rule);void audit_rule_unaccount (const struct audit_krule *rule);
kernel/auditfilter.c +55 -1
86 lines not on this page · raw message
kernel/auditsc.c +13 -0
@@ -861,6 +861,16 @@ static void audit_filter_uring(struct task_struct *tsk,rcu_read_unlock (); } +static inline bool audit_exit_filter_may_match (unsigned long syscall) +{ +u32 word; + +if (syscall >=AUDIT_BITMASK_SIZE *32 ) +return false; + word =AUDIT_WORD (syscall); +return READ_ONCE (audit_exit_filter_mask[word]) &AUDIT_BIT (syscall); +} +/* At syscall exit time, this filter is called if the audit_state is * not low enough that auditing cannot take place, but is also not * high enough that we already know we have to write an audit record
@@ -872,6 +882,9 @@ static void audit_filter_syscall(struct task_struct *tsk,if (auditd_test_task (tsk))return ; +if (!audit_exit_filter_may_match (ctx->major)) +return ; +rcu_read_lock ();__audit_filter_op (tsk, ctx, &audit_filter_list[AUDIT_FILTER_EXIT ],NULL , ctx->major);
Signature · 1 line
2.43.0
Paul Moore
maintainerRe: [PATCH 3/3] audit: Skip exit filtering for syscalls without rules
Quoted 57 lines · On Aug 6, 2026 Stanislav Kinsburskii <[email protected]> wrote:
Audit walks every exit filter rule for each audited syscall, even when no rule contains the current syscall number. Policies with many unrelated rules therefore add linear overhead to otherwise uninteresting syscalls.
Maintain a reference count for each syscall bit present in exit filter rules and derive an aggregate interest mask. Update the mask through the centralized rule lifecycle helpers, which cover explicit and automatic rule removal. Use the mask as a lockless rejection test before entering the exit filter RCU traversal.
The mask is architecture-independent. Syscall number overlap between architectures can cause an unnecessary scan but cannot suppress a match.
The aggregate bit must be set before
list_add_rcu()publishes a new rule. Otherwise, a reader could observe the rule after publication while the aggregate mask still rejects its syscall. Moveaudit_rule_account()before the list insertion to provide this ordering. Rule removal already uses the inverse safe ordering: it unlinks the rule before clearing the aggregate bit, so a concurrent reader can only perform an unnecessary scan, not miss a rule.To measure the effect, install increasing numbers of distinct statx rules in a disposable VM and benchmark the unrelated getpid syscall after each set is installed:
for nr_rules in 1 32 128 256; do auditctl -D for uid in $(seq 1 $nr_rules); do auditctl -a always,exit -F arch=b64 -S statx \ -F uid=$uid done audit_bench doneWithout this change, the same unpinned VM produced:
1 rule:
median=55 ns/op 32 rules: median=71 ns/op 128 rules: median=428 ns/op 256 rules: median=791 ns/opWith this change, it produced:
1 rule:
median=55 ns/op 32 rules: median=55 ns/op 128 rules: median=55 ns/op 256 rules: median=55 ns/op
Quoted 6 lines
Signed-off-by Stanislav Kinsburskii <[email protected]>--- kernel/audit.h | 2 ++ kernel/auditfilter.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++- kernel/auditsc.c | 13 ++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-)
We've had similar proposals in the past, and I'll say the same thing I've said in the past: I'm not certain that our answer to filter performance is to add additional complexity and filtering. It may turn out that an approach like this is the only option, but I'd really like to see more effort put into improving a singular filter mechanism (either the current approach or a replacement design) before we start layering on additional complexity.
--
paul-moore.com
Re: [PATCH 3/3] audit: Skip exit filtering for syscalls without rules
Quoted 65 lines · Paul Moore
Quoted 57 lines · On Aug 6, 2026 Stanislav Kinsburskii <[email protected]> wrote:
Audit walks every exit filter rule for each audited syscall, even when no rule contains the current syscall number. Policies with many unrelated rules therefore add linear overhead to otherwise uninteresting syscalls.
Maintain a reference count for each syscall bit present in exit filter rules and derive an aggregate interest mask. Update the mask through the centralized rule lifecycle helpers, which cover explicit and automatic rule removal. Use the mask as a lockless rejection test before entering the exit filter RCU traversal.
The mask is architecture-independent. Syscall number overlap between architectures can cause an unnecessary scan but cannot suppress a match.
The aggregate bit must be set before
list_add_rcu()publishes a new rule. Otherwise, a reader could observe the rule after publication while the aggregate mask still rejects its syscall. Moveaudit_rule_account()before the list insertion to provide this ordering. Rule removal already uses the inverse safe ordering: it unlinks the rule before clearing the aggregate bit, so a concurrent reader can only perform an unnecessary scan, not miss a rule.To measure the effect, install increasing numbers of distinct statx rules in a disposable VM and benchmark the unrelated getpid syscall after each set is installed:
for nr_rules in 1 32 128 256; do auditctl -D for uid in $(seq 1 $nr_rules); do auditctl -a always,exit -F arch=b64 -S statx \ -F uid=$uid done audit_bench doneWithout this change, the same unpinned VM produced:
1 rule:
median=55 ns/op 32 rules: median=71 ns/op 128 rules: median=428 ns/op 256 rules: median=791 ns/opWith this change, it produced:
1 rule:
median=55 ns/op 32 rules: median=55 ns/op 128 rules: median=55 ns/op 256 rules: median=55 ns/opQuoted 6 lines
Signed-off-by Stanislav Kinsburskii <[email protected]>--- kernel/audit.h | 2 ++ kernel/auditfilter.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++- kernel/auditsc.c | 13 ++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-)
Quoted 8 lines
We've had similar proposals in the past, and I'll say the same thing I've said in the past: I'm not certain that our answer to filter performance is to add additional complexity and filtering. It may turn out that an approach like this is the only option, but I'd really like to see more effort put into improving a singular filter mechanism (either the current approach or a replacement design) before we start layering on additional complexity.
I see. Indeed, the mask is effectively another filter in front of the existing rule list.
One alternative would be to replace the global runtime exit-rule traversal with an array of RCU-protected, ordered candidate lists, conceptually:
candidates[__NR_getpid] = {
rules whose syscall mask includes __NR_getpid
}Filtering would then look roughly like:
rcu_read_lock();
list_for_each_entry_rcu(candidate, &candidates[syscall], list) {
if (audit_filter_rules(...))
break;
}
rcu_read_unlock();A canonical registry would still keep each rule once for rule management and listing, while the syscall path would use only the candidate index. This would make the index the runtime filtering mechanism, rather than another filter layered in front of the existing traversal.
What do you think about this approach?
Thanks,
Stanislav
Quoted 2 lines
--
paul-moore.com
Quoted 4 lines · Stanislav Kinsburskii
This series adds a repeatable microbenchmark for audit's fixed syscall overhead and uses it to address two cases where audit continues doing work which cannot produce a record.
A gentle ping on this series.
Thanks,
Stanislav
Quoted 65 lines
Patch 1 adds
audit_bench, a manually run getpid(2) microbenchmark undertools/testing/selftests/audit. It leaves policy management to the caller so the same workload can measure different rule configurations without silently changing the system policy.Patch 2 fixes
audit_n_rulesandaudit_signalsaccounting when rules are removed automatically with a watch or tree, or after an LSM rule update fails. These paths could leave the counters nonzero after the last applicable rule had disappeared, causing every subsequent syscall to allocate a non-dummy audit context. It also centralizes rule accounting so all rule removal paths share the same bookkeeping.The median getpid latency in the same unpinned VM was:
no rules stale state fixed automatically removed watch 38 ns 55 ns 38 ns automatically removed tree 38 ns 59 ns 38 nsPatch 3 builds on those lifecycle helpers. It maintains an aggregate mask of the syscall numbers present in exit rules and checks that mask before walking the exit filter list. The mask is architecture-independent and therefore conservative: overlapping syscall numbers may cause an unnecessary scan, but cannot suppress a match.
For an unrelated getpid workload, the median latency scaled as follows:
exit rules 1 32 128 256 before 55 ns 71 ns 428 ns 791 ns after 55 ns 55 ns 55 ns 55 nsThe aggregate mask is updated through the centralized accounting helpers. Insertion sets the relevant bits before publishing the rule with
list_add_rcu(); removal unlinks the rule before clearing them. This keeps the lockless rejection test conservative during concurrent rule changes.The series does not change the audit userspace ABI or rule matching semantics. The benchmark and complete reproduction procedures are documented in the individual patches.
---
Stanislav Kinsburskii (3):
selftests/audit: Add syscall overhead benchmark
audit: Fix filter rule accounting after automatic removal
audit: Skip exit filtering for syscalls without rulesMAINTAINERS | 1 + kernel/audit.h | 7 + kernel/audit_tree.c | 1 + kernel/audit_watch.c | 2 + kernel/auditfilter.c | 140 +++++++++++------ kernel/auditsc.c | 13 ++ tools/testing/selftests/Makefile | 1 + tools/testing/selftests/audit/.gitignore | 2 + tools/testing/selftests/audit/Makefile | 9 ++ tools/testing/selftests/audit/README | 30 ++++ tools/testing/selftests/audit/audit_bench.c | 227 ++++++++++++++++++++++++++++ 11 files changed, 389 insertions(+), 44 deletions(-)---
base-commit:ea2bff00da89d7767d677bb68470130ba96f4928
change-id: 20260806-audit-96a1e71d38b1Best regards,
Signature · 1 line
Stanislav Kinsburskii <[email protected]>
Paul Moore
maintainerQuoted 6 lines · Stanislav Kinsburskii
Quoted 3 lines · Stanislav Kinsburskii
This series adds a repeatable microbenchmark for audit's fixed syscall overhead and uses it to address two cases where audit continues doing work which cannot produce a record.
A gentle ping on this series.
As I just mentioned to another submitter, your patch hit the mailing list at a time when the audit/dev branch was closed to everything except for critical fixes. We have a doc, listed in the audit MAINTAINERS entry, which describes the management of the audit tree and our processes:
https://github.com/linux-audit/audit-kernel/blob/main/README.md
Beyond that, while I have briefly looked at your patchset, I haven't had a chance yet to properly review it. Given a quick glance, patch 2/3 seems good and reasonable; it even cleans up some macro ugliness, which is very nice. I'm not sure about enshrining an audit benchmark in the kernel selftests, as you do in patch 1/3, although it might be worthwhile as part of the audit-testsuite; I want to think on that a bit more. In the past others have proposed similar things as you've done in patch 3/3, but I really dislike the idea of adding more filtering to the audit filter; I'd much rather see what we can do to fix/improve the existing filtering.
Anyway, that's where things are at, but it basically boils down to "yes, I've seen your patches, and no I haven't finished reviewing them yet; your patience is appreciated.".
--
paul-moore.com