From: "Günther Noack" <gnoack@google.com>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: Boqun Feng <boqun.feng@gmail.com>, Ingo Molnar <mingo@redhat.com>,
Konstantin Meskhidze <konstantin.meskhidze@huawei.com>,
Matthieu Buffet <matthieu@buffet.re>,
Mikhail Ivanov <ivanov.mikhail1@huawei-partners.com>,
Peter Zijlstra <peterz@infradead.org>,
Shervin Oloumi <enlightened@chromium.org>,
Waiman Long <longman@redhat.com>, Will Deacon <will@kernel.org>,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org
Subject: Re: [PATCH v1 2/4] landlock: Use scoped guards for ruleset in landlock_add_rule()
Date: Mon, 13 Jan 2025 23:06:31 +0100 [thread overview]
Message-ID: <Z4WOZ_yqVbgoHBlB@google.com> (raw)
In-Reply-To: <20250113161112.452505-3-mic@digikod.net>
On Mon, Jan 13, 2025 at 05:11:10PM +0100, Mickaël Salaün wrote:
> Simplify error handling by replacing goto statements with automatic
> calls to landlock_put_ruleset() when going out of scope.
>
> This change depends on the TCP support.
>
> Cc: Günther Noack <gnoack@google.com>
> Cc: Konstantin Meskhidze <konstantin.meskhidze@huawei.com>
> Cc: Mikhail Ivanov <ivanov.mikhail1@huawei-partners.com>
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
> Link: https://lore.kernel.org/r/20250113161112.452505-3-mic@digikod.net
> ---
> security/landlock/syscalls.c | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/security/landlock/syscalls.c b/security/landlock/syscalls.c
> index 5a7f1f77292e..a9760d252fc2 100644
> --- a/security/landlock/syscalls.c
> +++ b/security/landlock/syscalls.c
> @@ -399,8 +399,7 @@ SYSCALL_DEFINE4(landlock_add_rule, const int, ruleset_fd,
> const enum landlock_rule_type, rule_type,
> const void __user *const, rule_attr, const __u32, flags)
> {
> - struct landlock_ruleset *ruleset;
> - int err;
> + struct landlock_ruleset *ruleset __free(landlock_put_ruleset) = NULL;
>
> if (!is_initialized())
> return -EOPNOTSUPP;
> @@ -416,17 +415,12 @@ SYSCALL_DEFINE4(landlock_add_rule, const int, ruleset_fd,
>
> switch (rule_type) {
> case LANDLOCK_RULE_PATH_BENEATH:
> - err = add_rule_path_beneath(ruleset, rule_attr);
> - break;
> + return add_rule_path_beneath(ruleset, rule_attr);
> case LANDLOCK_RULE_NET_PORT:
> - err = add_rule_net_port(ruleset, rule_attr);
> - break;
> + return add_rule_net_port(ruleset, rule_attr);
> default:
> - err = -EINVAL;
> - break;
> + return -EINVAL;
> }
> - landlock_put_ruleset(ruleset);
> - return err;
> }
>
> /* Enforcement */
> --
> 2.47.1
>
Reviewed-by: Günther Noack <gnoack@google.com>
next prev parent reply other threads:[~2025-01-13 22:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 16:11 [PATCH v1 0/4] Use scoped guards on Landlock Mickaël Salaün
2025-01-13 16:11 ` [PATCH v1 1/4] landlock: Use scoped guards for ruleset Mickaël Salaün
2025-01-13 22:05 ` Günther Noack
2025-01-13 16:11 ` [PATCH v1 2/4] landlock: Use scoped guards for ruleset in landlock_add_rule() Mickaël Salaün
2025-01-13 22:06 ` Günther Noack [this message]
2025-01-13 16:11 ` [PATCH v1 3/4] locking/mutex: Add mutex_nest_1() scoped guard Mickaël Salaün
2025-01-13 16:11 ` [PATCH v1 4/4] landlock: Use scoped guards for mutex Mickaël Salaün
2025-01-14 9:25 ` Günther Noack
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=Z4WOZ_yqVbgoHBlB@google.com \
--to=gnoack@google.com \
--cc=boqun.feng@gmail.com \
--cc=enlightened@chromium.org \
--cc=ivanov.mikhail1@huawei-partners.com \
--cc=konstantin.meskhidze@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=longman@redhat.com \
--cc=matthieu@buffet.re \
--cc=mic@digikod.net \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@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