public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: 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>,
	Mimi Zohar <zohar@linux.vnet.ibm.com>,
	"Serge E. Hallyn" <serge@hallyn.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 3/3] ima_fs: Move three error code assignments in ima_write_policy()
Date: Wed, 25 Jan 2017 09:34:29 +0000	[thread overview]
Message-ID: <b6339fa4-69b3-afc4-18a8-254369fec074@users.sourceforge.net> (raw)
In-Reply-To: <e06d5392-5262-2d88-aa6b-79e53a20fc8b@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 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)
-- 
2.11.0


  parent reply	other threads:[~2017-01-25  9:34 UTC|newest]

Thread overview: 7+ 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:31 ` [PATCH 1/3] ima_fs: One check less in ima_write_policy() after error detection SF Markus Elfring
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:34 ` SF Markus Elfring [this message]
2017-01-27 12:39   ` [PATCH 3/3] ima_fs: Move three error code assignments " Mimi Zohar
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=b6339fa4-69b3-afc4-18a8-254369fec074@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=dmitry.kasatkin@gmail.com \
    --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 \
    --cc=zohar@linux.vnet.ibm.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