From: Mimi Zohar <zohar@linux.vnet.ibm.com>
To: SF Markus Elfring <elfring@users.sourceforge.net>
Cc: linux-ima-devel@lists.sourceforge.net,
linux-ima-user@lists.sourceforge.net,
linux-security-module@vger.kernel.org,
Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
James Morris <james.l.morris@oracle.com>,
"Serge E. Hallyn" <serge@hallyn.com>,
LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 1/3] ima_fs: One check less in ima_write_policy() after error detection
Date: Fri, 27 Jan 2017 12:38:57 +0000 [thread overview]
Message-ID: <1485520737.2596.88.camel@linux.vnet.ibm.com> (raw)
In-Reply-To: <28a6918c-5714-cec8-2df7-85bcc37e4d75@users.sourceforge.net>
On Wed, 2017-01-25 at 10:31 +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>
> ---
> 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;
WARNING: multiple messages have this Message-ID (diff)
From: Mimi Zohar <zohar@linux.vnet.ibm.com>
To: SF Markus Elfring <elfring@users.sourceforge.net>
Cc: linux-ima-devel@lists.sourceforge.net,
linux-ima-user@lists.sourceforge.net,
linux-security-module@vger.kernel.org,
Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
James Morris <james.l.morris@oracle.com>,
"Serge E. Hallyn" <serge@hallyn.com>,
LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 1/3] ima_fs: One check less in ima_write_policy() after error detection
Date: Fri, 27 Jan 2017 07:38:57 -0500 [thread overview]
Message-ID: <1485520737.2596.88.camel@linux.vnet.ibm.com> (raw)
In-Reply-To: <28a6918c-5714-cec8-2df7-85bcc37e4d75@users.sourceforge.net>
On Wed, 2017-01-25 at 10:31 +0100, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>
> ---
> 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;
next prev parent reply other threads:[~2017-01-27 12:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-25 9:30 [PATCH 0/3] ima_fs: Fine-tuning for ima_write_policy() SF Markus Elfring
2017-01-25 9:30 ` SF Markus Elfring
2017-01-25 9:31 ` [PATCH 1/3] ima_fs: One check less in ima_write_policy() after error detection SF Markus Elfring
2017-01-25 9:31 ` SF Markus Elfring
2017-01-27 12:38 ` Mimi Zohar [this message]
2017-01-27 12:38 ` Mimi Zohar
2017-01-25 9:33 ` [PATCH 2/3] ima_fs: Reorder input parameter validation in ima_write_policy() SF Markus Elfring
2017-01-25 9:33 ` SF Markus Elfring
2017-01-25 9:34 ` [PATCH 3/3] ima_fs: Move three error code assignments " SF Markus Elfring
2017-01-25 9:34 ` SF Markus Elfring
2017-01-27 12:39 ` Mimi Zohar
2017-01-27 12:39 ` Mimi Zohar
2017-01-29 23:43 ` James Morris
2017-01-29 23:43 ` James Morris
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=1485520737.2596.88.camel@linux.vnet.ibm.com \
--to=zohar@linux.vnet.ibm.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=elfring@users.sourceforge.net \
--cc=james.l.morris@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-ima-devel@lists.sourceforge.net \
--cc=linux-ima-user@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=serge@hallyn.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.