Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934518AbcKKQ6v (ORCPT ); Fri, 11 Nov 2016 11:58:51 -0500 Received: from out01.mta.xmission.com ([166.70.13.231]:47622 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756494AbcKKQ6g (ORCPT ); Fri, 11 Nov 2016 11:58:36 -0500 From: ebiederm@xmission.com (Eric W. Biederman) To: Sachin Shukla Cc: Kees Cook , Serge Hallyn , Andrey Vagin , linux-kernel@vger.kernel.org, sachiniiitm@gmail.com, ravikant.s2@samsung.com, p.shailesh@samsung.com, ashish.kalra@samsung.com, vidushi.koul@samsung.com References: <1478855235-26233-1-git-send-email-sachin.s5@samsung.com> Date: Fri, 11 Nov 2016 10:55:57 -0600 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") Message-ID: <87eg2iklb6.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1c5F9k-0004Gk-Nb;;;mid=<87eg2iklb6.fsf@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=75.170.125.99;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+5o8YAHH+f99zKfmxkib2WPJeejJXRPzU= X-SA-Exim-Connect-IP: 75.170.125.99 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa01 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_02 5+ unique symbols in subject * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_03 6+ unique symbols in subject X-Spam-DCC: XMission; sa01 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Sachin Shukla X-Spam-Relay-Country: X-Spam-Timing: total 6030 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 3.8 (0.1%), b_tie_ro: 2.8 (0.0%), parse: 1.26 (0.0%), extract_message_metadata: 30 (0.5%), get_uri_detail_list: 2.6 (0.0%), tests_pri_-1000: 11 (0.2%), tests_pri_-950: 2.0 (0.0%), tests_pri_-900: 1.87 (0.0%), tests_pri_-400: 32 (0.5%), check_bayes: 30 (0.5%), b_tokenize: 12 (0.2%), b_tok_get_all: 8 (0.1%), b_comp_prob: 3.8 (0.1%), b_tok_touch_all: 3.4 (0.1%), b_finish: 0.92 (0.0%), tests_pri_0: 533 (8.8%), check_dkim_signature: 0.93 (0.0%), check_dkim_adsp: 8 (0.1%), tests_pri_500: 5410 (89.7%), poll_dns_idle: 5402 (89.6%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH] Kernel: Improvement in code readability when memdup_user_nul() fails. X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1957 Lines: 67 Sachin Shukla writes: > From: "Sachin Shukla" > > 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" This is stupid, unnecesary gratituous change that makes the maintenance of the code worse. > > Signed-off-by: Sachin Shukla > --- > 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 */