From: ebiederm@xmission.com (Eric W. Biederman)
To: Sachin Shukla <sachin.s5@samsung.com>
Cc: Kees Cook <keescook@chromium.org>,
Serge Hallyn <serge@hallyn.com>, Andrey Vagin <avagin@openvz.org>,
linux-kernel@vger.kernel.org, sachiniiitm@gmail.com,
ravikant.s2@samsung.com, p.shailesh@samsung.com,
ashish.kalra@samsung.com, vidushi.koul@samsung.com
Subject: Re: [PATCH] Kernel: Improvement in code readability when memdup_user_nul() fails.
Date: Fri, 11 Nov 2016 10:55:57 -0600 [thread overview]
Message-ID: <87eg2iklb6.fsf@xmission.com> (raw)
In-Reply-To: <1478855235-26233-1-git-send-email-sachin.s5@samsung.com> (Sachin Shukla's message of "Fri, 11 Nov 2016 14:37:15 +0530")
Sachin Shukla <sachin.s5@samsung.com> writes:
> From: "Sachin Shukla" <sachin.s5@samsung.com>
>
> There is no need to call kfree() if memdup_user_nul() fails, as no memory
> was allocated and the error in the error-valued pointer should be
> returned.
Nacked-by: "Eric W. Biederman" <ebiederm@xmission.com>
This is stupid, unnecesary gratituous change that makes the maintenance
of the code worse.
>
> Signed-off-by: Sachin Shukla <sachin.s5@samsung.com>
> ---
> kernel/user_namespace.c | 25 ++++++++++++++-----------
> 1 file changed, 14 insertions(+), 11 deletions(-)
>
> diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
> index 86b7854..a0ffbf0 100644
> --- a/kernel/user_namespace.c
> +++ b/kernel/user_namespace.c
> @@ -672,28 +672,31 @@ static ssize_t map_write(struct file *file, const char __user *buf,
> */
> mutex_lock(&userns_state_mutex);
>
> - ret = -EPERM;
> /* Only allow one successful write to the map */
> - if (map->nr_extents != 0)
> - goto out;
> + if (map->nr_extents != 0) {
> + mutex_unlock(&userns_state_mutex);
> + return -EPERM;
> + }
>
> /*
> * Adjusting namespace settings requires capabilities on the target.
> */
> - if (cap_valid(cap_setid) && !file_ns_capable(file, ns, CAP_SYS_ADMIN))
> - goto out;
> + if (cap_valid(cap_setid) && !file_ns_capable(file, ns, CAP_SYS_ADMIN)) {
> + mutex_unlock(&userns_state_mutex);
> + return -EPERM;
> + }
>
> /* Only allow < page size writes at the beginning of the file */
> - ret = -EINVAL;
> - if ((*ppos != 0) || (count >= PAGE_SIZE))
> - goto out;
> + if ((*ppos != 0) || (count >= PAGE_SIZE)) {
> + mutex_unlock(&userns_state_mutex);
> + return -EINVAL;
> + }
>
> /* Slurp in the user data */
> kbuf = memdup_user_nul(buf, count);
> if (IS_ERR(kbuf)) {
> - ret = PTR_ERR(kbuf);
> - kbuf = NULL;
> - goto out;
> + mutex_unlock(&userns_state_mutex);
> + return PTR_ERR(kbuf);
> }
>
> /* Parse the user data */
prev parent reply other threads:[~2016-11-11 16:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-11 9:07 [PATCH] Kernel: Improvement in code readability when memdup_user_nul() fails Sachin Shukla
2016-11-11 10:02 ` Vivek Gautam
2016-11-11 15:40 ` Serge E. Hallyn
2016-11-11 16:55 ` Eric W. Biederman [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=87eg2iklb6.fsf@xmission.com \
--to=ebiederm@xmission.com \
--cc=ashish.kalra@samsung.com \
--cc=avagin@openvz.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=p.shailesh@samsung.com \
--cc=ravikant.s2@samsung.com \
--cc=sachin.s5@samsung.com \
--cc=sachiniiitm@gmail.com \
--cc=serge@hallyn.com \
--cc=vidushi.koul@samsung.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).