Skip to content

Commit b566f7a

Browse files
committed
selftests/landlock: Fix snprintf truncation checks in audit helpers
snprintf() returns the number of characters that would have been written, excluding the terminating NUL byte. When the output is truncated, this return value equals or exceeds the buffer size. Fix matches_log_domain_allocated() and matches_log_domain_deallocated() to detect truncation with ">=" instead of ">". Cc: Günther Noack <gnoack@google.com> Cc: stable@vger.kernel.org Fixes: 6a500b2 ("selftests/landlock: Add tests for audit flags and domain IDs") Reviewed-by: Günther Noack <gnoack3000@gmail.com> Link: https://lore.kernel.org/r/20260402192608.1458252-2-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent e75e380 commit b566f7a

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • tools/testing/selftests/landlock

tools/testing/selftests/landlock/audit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static int __maybe_unused matches_log_domain_allocated(int audit_fd, pid_t pid,
309309

310310
log_match_len =
311311
snprintf(log_match, sizeof(log_match), log_template, pid);
312-
if (log_match_len > sizeof(log_match))
312+
if (log_match_len >= sizeof(log_match))
313313
return -E2BIG;
314314

315315
return audit_match_record(audit_fd, AUDIT_LANDLOCK_DOMAIN, log_match,
@@ -326,7 +326,7 @@ static int __maybe_unused matches_log_domain_deallocated(
326326

327327
log_match_len = snprintf(log_match, sizeof(log_match), log_template,
328328
num_denials);
329-
if (log_match_len > sizeof(log_match))
329+
if (log_match_len >= sizeof(log_match))
330330
return -E2BIG;
331331

332332
return audit_match_record(audit_fd, AUDIT_LANDLOCK_DOMAIN, log_match,

0 commit comments

Comments
 (0)