From: Greg KH <greg@kroah.com>
To: Sasha Levin <sashal@kernel.org>
Cc: stable@vger.kernel.org, "Mickaël Salaün" <mic@digikod.net>,
"Günther Noack" <gnoack@google.com>,
"Günther Noack" <gnoack3000@gmail.com>
Subject: Re: [PATCH 6.18.y] selftests/landlock: Fix socket file descriptor leaks in audit helpers
Date: Mon, 4 May 2026 11:58:25 +0200 [thread overview]
Message-ID: <2026050420-overfed-obstacle-83f2@gregkh> (raw)
In-Reply-To: <20260502130541.590744-1-sashal@kernel.org>
On Sat, May 02, 2026 at 09:05:41AM -0400, Sasha Levin wrote:
> From: Mickaël Salaün <mic@digikod.net>
>
> [ Upstream commit 9143d790337a0d066c2d632c802f69b981e6c23a ]
>
> audit_init() opens a netlink socket and configures it, but leaks the
> file descriptor if audit_set_status() or setsockopt() fails. Fix this
> by jumping to an error path that closes the socket before returning.
>
> Apply the same fix to audit_init_with_exe_filter(), which leaks the file
> descriptor from audit_init() if audit_init_filter_exe() or
> audit_filter_exe() fails, and to audit_cleanup(), which leaks it if
> audit_init_filter_exe() fails in FIXTURE_TEARDOWN_PARENT().
>
> Cc: Günther Noack <gnoack@google.com>
> Cc: stable@vger.kernel.org
> Fixes: 6a500b22971c ("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-3-mic@digikod.net
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> tools/testing/selftests/landlock/audit.h | 26 +++++++++++++++++-------
> 1 file changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/landlock/audit.h b/tools/testing/selftests/landlock/audit.h
> index 02fd1393947a7..36a6816b47f13 100644
> --- a/tools/testing/selftests/landlock/audit.h
> +++ b/tools/testing/selftests/landlock/audit.h
> @@ -379,19 +379,25 @@ static int audit_init(void)
>
> err = audit_set_status(fd, AUDIT_STATUS_ENABLED, 1);
> if (err)
> - return err;
> + goto err_close;
>
> err = audit_set_status(fd, AUDIT_STATUS_PID, getpid());
> if (err)
> - return err;
> + goto err_close;
>
> /* Sets a timeout for negative tests. */
> err = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &audit_tv_default,
> sizeof(audit_tv_default));
> - if (err)
> - return -errno;
> + if (err) {
> + err = -errno;
> + goto err_close;
> + }
>
> return fd;
> +
> +err_close:
> + close(fd);
> + return err;
> }
>
> static int audit_init_filter_exe(struct audit_filter *filter, const char *path)
> @@ -441,8 +447,10 @@ static int audit_cleanup(int audit_fd, struct audit_filter *filter)
>
> filter = &new_filter;
> err = audit_init_filter_exe(filter, NULL);
> - if (err)
> + if (err) {
> + close(audit_fd);
> return err;
> + }
> }
>
> /* Filters might not be in place. */
> @@ -468,11 +476,15 @@ static int audit_init_with_exe_filter(struct audit_filter *filter)
>
> err = audit_init_filter_exe(filter, NULL);
> if (err)
> - return err;
> + goto err_close;
>
> err = audit_filter_exe(fd, filter, AUDIT_ADD_RULE);
> if (err)
> - return err;
> + goto err_close;
>
> return fd;
> +
> +err_close:
> + close(fd);
> + return err;
> }
> --
> 2.53.0
>
>
Also does not apply :(
prev parent reply other threads:[~2026-05-04 9:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-01 11:05 FAILED: patch "[PATCH] selftests/landlock: Fix socket file descriptor leaks in audit" failed to apply to 6.18-stable tree gregkh
2026-05-02 13:05 ` [PATCH 6.18.y] selftests/landlock: Fix socket file descriptor leaks in audit helpers Sasha Levin
2026-05-04 9:58 ` Greg KH [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2026050420-overfed-obstacle-83f2@gregkh \
--to=greg@kroah.com \
--cc=gnoack3000@gmail.com \
--cc=gnoack@google.com \
--cc=mic@digikod.net \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox