On Tue, Sep 01, 2026 at 05:35:16PM -0400, Paul Moore wrote:
> 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. 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
> >   done
> > 
> > Without 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/op
> > 
> > With 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
> > 
> > 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.
> 

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

> --
> paul-moore.com

Reply via email to