From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mimi Zohar Date: Fri, 27 Jan 2017 12:39:24 +0000 Subject: Re: [PATCH 3/3] ima_fs: Move three error code assignments in ima_write_policy() Message-Id: <1485520764.2596.89.camel@linux.vnet.ibm.com> List-Id: References: In-Reply-To: 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:34 +0100, SF Markus Elfring wrote: > From: Markus Elfring > Date: Tue, 24 Jan 2017 22:47:07 +0100 > > A local variable was set to an error code in three cases before a concrete > error situation was detected. Thus move the corresponding assignments into > if branches to indicate a software failure there. > > This issue was detected by using the Coccinelle software. This coding style was pretty common. I assume the compiler is smart enough to do the right thing. Is this a FYI, letting us know for the future the preferred coding style, or are we really upstreaming these sorts of coding style changes? Mimi > > Signed-off-by: Markus Elfring > --- > security/integrity/ima/ima_fs.c | 15 +++++++++------ > 1 file changed, 9 insertions(+), 6 deletions(-) > > diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c > index 98304411915d..a50c26f9772c 100644 > --- a/security/integrity/ima/ima_fs.c > +++ b/security/integrity/ima/ima_fs.c > @@ -317,21 +317,24 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf, > > /* No partial writes. */ > result = -EINVAL; > - if (*ppos != 0) > + if (*ppos != 0) { > + result = -EINVAL; > goto reset_validity; > + } > > - result = -ENOMEM; > if (datalen >= PAGE_SIZE) > datalen = PAGE_SIZE - 1; > data = kmalloc(datalen + 1, GFP_KERNEL); > - if (!data) > + if (!data) { > + result = -ENOMEM; > goto reset_validity; > + } > > *(data + datalen) = '\0'; > - > - result = -EFAULT; > - if (copy_from_user(data, buf, datalen)) > + if (copy_from_user(data, buf, datalen)) { > + result = -EFAULT; > goto out_free; > + } > > result = mutex_lock_interruptible(&ima_write_mutex); > if (result < 0) From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932471AbdA0Ml6 (ORCPT ); Fri, 27 Jan 2017 07:41:58 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34988 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932403AbdA0MlK (ORCPT ); Fri, 27 Jan 2017 07:41:10 -0500 Subject: Re: [PATCH 3/3] ima_fs: Move three error code assignments in ima_write_policy() 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:39:24 -0500 In-Reply-To: References: 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-000003ABF4F1 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17012712-0013-0000-0000-00001B2CF5BB Message-Id: <1485520764.2596.89.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:34 +0100, SF Markus Elfring wrote: > From: Markus Elfring > Date: Tue, 24 Jan 2017 22:47:07 +0100 > > A local variable was set to an error code in three cases before a concrete > error situation was detected. Thus move the corresponding assignments into > if branches to indicate a software failure there. > > This issue was detected by using the Coccinelle software. This coding style was pretty common. I assume the compiler is smart enough to do the right thing. Is this a FYI, letting us know for the future the preferred coding style, or are we really upstreaming these sorts of coding style changes? Mimi > > Signed-off-by: Markus Elfring > --- > security/integrity/ima/ima_fs.c | 15 +++++++++------ > 1 file changed, 9 insertions(+), 6 deletions(-) > > diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c > index 98304411915d..a50c26f9772c 100644 > --- a/security/integrity/ima/ima_fs.c > +++ b/security/integrity/ima/ima_fs.c > @@ -317,21 +317,24 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf, > > /* No partial writes. */ > result = -EINVAL; > - if (*ppos != 0) > + if (*ppos != 0) { > + result = -EINVAL; > goto reset_validity; > + } > > - result = -ENOMEM; > if (datalen >= PAGE_SIZE) > datalen = PAGE_SIZE - 1; > data = kmalloc(datalen + 1, GFP_KERNEL); > - if (!data) > + if (!data) { > + result = -ENOMEM; > goto reset_validity; > + } > > *(data + datalen) = '\0'; > - > - result = -EFAULT; > - if (copy_from_user(data, buf, datalen)) > + if (copy_from_user(data, buf, datalen)) { > + result = -EFAULT; > goto out_free; > + } > > result = mutex_lock_interruptible(&ima_write_mutex); > if (result < 0)