From: ebiederm@xmission.com (Eric W. Biederman)
To: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
Cc: linux-next@vger.kernel.org,
Christian Brauner <christian.brauner@ubuntu.com>,
Mark Rutland <mark.rutland@arm.com>,
Ingo Molnar <mingo@kernel.org>, Serge Hallyn <serge@hallyn.com>,
Seth Forshee <seth.forshee@canonical.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH -next] user_namespace: Replace gotos with return statements
Date: Wed, 18 Apr 2018 22:43:26 -0500 [thread overview]
Message-ID: <87in8nsvxd.fsf@xmission.com> (raw)
In-Reply-To: <20180419024641.24213-1-marcos.souza.org@gmail.com> (Marcos Paulo de Souza's message of "Wed, 18 Apr 2018 23:46:38 -0300")
Marcos Paulo de Souza <marcos.souza.org@gmail.com> writes:
> Found while inspecting the code that handles the setgroups procfs
> file.
What perchance might be the advantage of introducing multiple exits
into proc_setgroups_write?
I strongly suspect that if you look at the generated code it will
be worse after your patch.
Eric
> Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
> ---
> Tested locally setting up a new userns, and setting setgroups as deny and allow,
> worked as before.
>
> kernel/user_namespace.c | 20 +++++++-------------
> 1 file changed, 7 insertions(+), 13 deletions(-)
>
> diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
> index 246d4d4ce5c7..64a01254ac6b 100644
> --- a/kernel/user_namespace.c
> +++ b/kernel/user_namespace.c
> @@ -1142,22 +1142,18 @@ ssize_t proc_setgroups_write(struct file *file, const char __user *buf,
> struct user_namespace *ns = seq->private;
> char kbuf[8], *pos;
> bool setgroups_allowed;
> - ssize_t ret;
>
> /* Only allow a very narrow range of strings to be written */
> - ret = -EINVAL;
> if ((*ppos != 0) || (count >= sizeof(kbuf)))
> - goto out;
> + return -EINVAL;
>
> /* What was written? */
> - ret = -EFAULT;
> if (copy_from_user(kbuf, buf, count))
> - goto out;
> + return -EFAULT;
> kbuf[count] = '\0';
> pos = kbuf;
>
> /* What is being requested? */
> - ret = -EINVAL;
> if (strncmp(pos, "allow", 5) == 0) {
> pos += 5;
> setgroups_allowed = true;
> @@ -1167,14 +1163,13 @@ ssize_t proc_setgroups_write(struct file *file, const char __user *buf,
> setgroups_allowed = false;
> }
> else
> - goto out;
> + return -EINVAL;
>
> /* Verify there is not trailing junk on the line */
> pos = skip_spaces(pos);
> if (*pos != '\0')
> - goto out;
> + return -EINVAL;
>
> - ret = -EPERM;
> mutex_lock(&userns_state_mutex);
> if (setgroups_allowed) {
> /* Enabling setgroups after setgroups has been disabled
> @@ -1194,12 +1189,11 @@ ssize_t proc_setgroups_write(struct file *file, const char __user *buf,
>
> /* Report a successful write */
> *ppos = count;
> - ret = count;
> -out:
> - return ret;
> + return count;
> +
> out_unlock:
> mutex_unlock(&userns_state_mutex);
> - goto out;
> + return -EPERM;
> }
>
> bool userns_may_setgroups(const struct user_namespace *ns)
next prev parent reply other threads:[~2018-04-19 3:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-19 2:46 [PATCH -next] user_namespace: Replace gotos with return statements Marcos Paulo de Souza
2018-04-19 3:43 ` Eric W. Biederman [this message]
2018-05-02 14:12 ` Christian Brauner
2018-05-04 1:23 ` Marcos Paulo de Souza
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=87in8nsvxd.fsf@xmission.com \
--to=ebiederm@xmission.com \
--cc=christian.brauner@ubuntu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=marcos.souza.org@gmail.com \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=serge@hallyn.com \
--cc=seth.forshee@canonical.com \
/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;
as well as URLs for NNTP newsgroup(s).