mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-24 03:09:47 -04:00
selftests/landlock: Explicitly disable audit in teardowns
I'm seeing sporadic selftest failures, such as # RUN scoped_audit.connect_to_child ... # scoped_abstract_unix_test.c:314:connect_to_child:Expected 0 (0) == records.access (8) # connect_to_child: Test failed # FAIL scoped_audit.connect_to_child not ok 19 scoped_audit.connect_to_child This seems similar to what commit3647a4977f("selftests/landlock: Drain stale audit records on init") tried to fix. However, the added drain loop is not effective. When setting the AUDIT_STATUS_PID, the kauditd_thread is woken up starting to send messages from the hold queue to the netlink. Depending on scheduling of this kthread not all messages might be send via the netlink in the 1 us interval. Therefore, instead of trying to drain the queue, let's just disable audit when running non-audit tests or more precisely disable it after audit-tests. This way we won't generate any new audit message that could interfere with the other tests. The comment saying that on process exit audit will be disabled is wrong. The closed file descriptor just causes an auditd_reset(), not a disablement. So future messages will be queued in the hold queue. Cc: stable@vger.kernel.org Fixes:6a500b2297("selftests/landlock: Add tests for audit flags and domain IDs") Signed-off-by: Maximilian Heyne <mheyne@amazon.de> Link: https://patch.msgid.link/20260529-welsh-nagoya-b4d9ca60@mheyne-amazon [mic: Fix FD leak, update subject, call audit_cleanup() in audit_exec teardown] Signed-off-by: Mickaël Salaün <mic@digikod.net>
This commit is contained in:
committed by
Mickaël Salaün
parent
76579d09be
commit
0302cd72fe
@@ -553,10 +553,9 @@ static int audit_init_filter_exe(struct audit_filter *filter, const char *path)
|
||||
static int audit_cleanup(int audit_fd, struct audit_filter *filter)
|
||||
{
|
||||
struct audit_filter new_filter;
|
||||
int err = 0;
|
||||
|
||||
if (audit_fd < 0 || !filter) {
|
||||
int err;
|
||||
|
||||
/*
|
||||
* Simulates audit_init_with_exe_filter() when called from
|
||||
* FIXTURE_TEARDOWN_PARENT().
|
||||
@@ -567,23 +566,19 @@ static int audit_cleanup(int audit_fd, struct audit_filter *filter)
|
||||
|
||||
filter = &new_filter;
|
||||
err = audit_init_filter_exe(filter, NULL);
|
||||
if (err) {
|
||||
close(audit_fd);
|
||||
return err;
|
||||
}
|
||||
if (err)
|
||||
goto err_close;
|
||||
}
|
||||
|
||||
/* Filters might not be in place. */
|
||||
audit_filter_exe(audit_fd, filter, AUDIT_DEL_RULE);
|
||||
audit_filter_drop(audit_fd, AUDIT_DEL_RULE);
|
||||
|
||||
/*
|
||||
* Because audit_cleanup() might not be called by the test auditd
|
||||
* process, it might not be possible to explicitly set it. Anyway,
|
||||
* AUDIT_STATUS_ENABLED will implicitly be set to 0 when the auditd
|
||||
* process will exit.
|
||||
*/
|
||||
return close(audit_fd);
|
||||
err = audit_set_status(audit_fd, AUDIT_STATUS_ENABLED, 0);
|
||||
|
||||
err_close:
|
||||
close(audit_fd);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int audit_init_with_exe_filter(struct audit_filter *filter)
|
||||
|
||||
@@ -850,10 +850,8 @@ FIXTURE_SETUP(audit_exec)
|
||||
FIXTURE_TEARDOWN(audit_exec)
|
||||
{
|
||||
set_cap(_metadata, CAP_AUDIT_CONTROL);
|
||||
EXPECT_EQ(0, audit_filter_exe(self->audit_fd, &self->audit_filter,
|
||||
AUDIT_DEL_RULE));
|
||||
EXPECT_EQ(0, audit_cleanup(self->audit_fd, &self->audit_filter));
|
||||
clear_cap(_metadata, CAP_AUDIT_CONTROL);
|
||||
EXPECT_EQ(0, close(self->audit_fd));
|
||||
}
|
||||
|
||||
TEST_F(audit_exec, signal_and_open)
|
||||
|
||||
Reference in New Issue
Block a user