[RFC PATCH 1/5] audit: only call audit_expand() once in audit_log_vformat()
Paul Moore <[email protected]> Fri, 24 Jul 2026 15:56:19 -0400
| Newsgroups | org.kernel.vger.audit |
|---|---|
| Message-ID | <[email protected]> |
The audit_expand() function ends up calling into pskb_expand_head() which does a non-trivial amount of work. Limiting the number of times we call audit_expand() is a positive from a performance perspective. We also know that audit buffers are originally allocated with a size of AUDIT_BUFSIZ (1024 bytes at the time of this patch), which makes it very unlikely that an audit buffer would ever be fully depleted and in need of expansion. With all of this in mind, don't call audit_expand() in audit_log_vformat() until we know how much buffer space we need, cleaning up the code and potentially dropping one audit_expand() call from the audit hot path. Signed-off-by: Paul Moore <[email protected]> --- kernel/audit.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/kernel/audit.c b/kernel/audit.c index 9412af9144bc..ec88dd10eb79 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -2023,11 +2023,6 @@ void audit_log_vformat(struct audit_buffer *ab, const char *fmt, va_list args) BUG_ON(!ab->skb); skb = ab->skb; avail = skb_tailroom(skb); - if (avail == 0) { - avail = audit_expand(ab, AUDIT_BUFSIZ); - if (!avail) - goto out; - } va_copy(args2, args); len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args); if (len >= avail) { @@ -2037,14 +2032,14 @@ void audit_log_vformat(struct audit_buffer *ab, const char *fmt, va_list args) avail = audit_expand(ab, max_t(unsigned int, AUDIT_BUFSIZ, 1+len-avail)); if (!avail) - goto out_va_end; + goto out; len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args2); } if (len > 0) skb_put(skb, len); -out_va_end: - va_end(args2); + out: + va_end(args2); return; } -- 2.55.0