From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mimi Zohar Date: Fri, 27 Jan 2017 12:38:57 +0000 Subject: Re: [PATCH 1/3] ima_fs: One check less in ima_write_policy() after error detection Message-Id: <1485520737.2596.88.camel@linux.vnet.ibm.com> List-Id: References: <28a6918c-5714-cec8-2df7-85bcc37e4d75@users.sourceforge.net> In-Reply-To: <28a6918c-5714-cec8-2df7-85bcc37e4d75@users.sourceforge.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: SF Markus Elfring Cc: linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org, Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , LKML , kernel-janitors@vger.kernel.org On Wed, 2017-01-25 at 10:31 +0100, SF Markus Elfring wrote: > From: Markus Elfring > Date: Tue, 24 Jan 2017 20:30:55 +0100 > > Move the jump label directly before the desired assignment for the > variable "valid_policy" at the end so that the variable "result" will not > be checked once more after it was determined that a received input > parameter was not zero or a memory allocation failed. > Use the identifier "reset_validity" instead of the label "out". > > Signed-off-by: Markus Elfring > --- > security/integrity/ima/ima_fs.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c > index ca303e5d2b94..c1c8d34d111d 100644 > --- a/security/integrity/ima/ima_fs.c > +++ b/security/integrity/ima/ima_fs.c > @@ -321,12 +321,12 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf, > /* No partial writes. */ > result = -EINVAL; > if (*ppos != 0) > - goto out; > + goto reset_validity; > > result = -ENOMEM; > data = kmalloc(datalen + 1, GFP_KERNEL); > if (!data) > - goto out; > + goto reset_validity; > > *(data + datalen) = '\0'; > > @@ -353,8 +353,8 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf, > mutex_unlock(&ima_write_mutex); > out_free: > kfree(data); > -out: > if (result < 0) > +reset_validity: Really?! Do you really think this makes the code more readable? A more common, readable approach is to have two exit points - a normal exit and an error exit. Let's leave it to the compiler to do the optimization. Mimi > valid_policy = 0; > > return result; From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932619AbdA0OB1 (ORCPT ); Fri, 27 Jan 2017 09:01:27 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40843 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932284AbdA0OBV (ORCPT ); Fri, 27 Jan 2017 09:01:21 -0500 Subject: Re: [PATCH 1/3] ima_fs: One check less in ima_write_policy() after error detection From: Mimi Zohar To: SF Markus Elfring Cc: linux-ima-devel@lists.sourceforge.net, linux-ima-user@lists.sourceforge.net, linux-security-module@vger.kernel.org, Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , LKML , kernel-janitors@vger.kernel.org Date: Fri, 27 Jan 2017 07:38:57 -0500 In-Reply-To: <28a6918c-5714-cec8-2df7-85bcc37e4d75@users.sourceforge.net> References: <28a6918c-5714-cec8-2df7-85bcc37e4d75@users.sourceforge.net> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.12.11 (3.12.11-1.fc21) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17012712-0012-0000-0000-000003ABF4D8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17012712-0013-0000-0000-00001B2CF5A2 Message-Id: <1485520737.2596.88.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-01-27_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1701270125 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2017-01-25 at 10:31 +0100, SF Markus Elfring wrote: > From: Markus Elfring > Date: Tue, 24 Jan 2017 20:30:55 +0100 > > Move the jump label directly before the desired assignment for the > variable "valid_policy" at the end so that the variable "result" will not > be checked once more after it was determined that a received input > parameter was not zero or a memory allocation failed. > Use the identifier "reset_validity" instead of the label "out". > > Signed-off-by: Markus Elfring > --- > security/integrity/ima/ima_fs.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c > index ca303e5d2b94..c1c8d34d111d 100644 > --- a/security/integrity/ima/ima_fs.c > +++ b/security/integrity/ima/ima_fs.c > @@ -321,12 +321,12 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf, > /* No partial writes. */ > result = -EINVAL; > if (*ppos != 0) > - goto out; > + goto reset_validity; > > result = -ENOMEM; > data = kmalloc(datalen + 1, GFP_KERNEL); > if (!data) > - goto out; > + goto reset_validity; > > *(data + datalen) = '\0'; > > @@ -353,8 +353,8 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf, > mutex_unlock(&ima_write_mutex); > out_free: > kfree(data); > -out: > if (result < 0) > +reset_validity: Really?! Do you really think this makes the code more readable? A more common, readable approach is to have two exit points - a normal exit and an error exit. Let's leave it to the compiler to do the optimization. Mimi > valid_policy = 0; > > return result;