linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petko Manolov <petkan@mip-labs.com>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>,
	James Morris <jmorris@namei.org>,
	linux-next@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mimi Zohar <zohar@linux.vnet.ibm.com>
Subject: Re: linux-next: manual merge of the security tree with the vfs tree
Date: Fri, 1 Jan 2016 19:29:37 +0200	[thread overview]
Message-ID: <20160101172937.GD13634@localhost> (raw)
In-Reply-To: <20160101043416.GE9938@ZenIV.linux.org.uk>

On 16-01-01 04:34:16, Al Viro wrote:
> On Thu, Dec 31, 2015 at 12:45:35PM +0200, Petko Manolov wrote:
> 
> > I introduced the write mutex when ima_write_policy() stopped being serialized by 
> > other means.  Come to think about it the semaphore could be taken right before 
> > copy_from_user() so it is my fault, not Stephen's.
> 
> s/before/after/, surely?

Right.  This is a quick patch which i hope solves most issues...


		Petko


>From 6c9058009c59fda5b8e98a3fc09497ce3efdb3e9 Mon Sep 17 00:00:00 2001
From: Petko Manolov <petkan@mip-labs.com>
Date: Fri, 1 Jan 2016 19:10:43 +0200
Subject: [PATCH] ima_write_policy() optimizations;

There is no need to hold the write semaphore for so long.  We only need it
around ima_parse_add_rule();

The return path now takes into account failed kmalloc() call.

Signed-off-by: Petko Manolov <petkan@mip-labs.com>
---
 security/integrity/ima/ima_fs.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
index 3caed6d..d2c0d55 100644
--- a/security/integrity/ima/ima_fs.c
+++ b/security/integrity/ima/ima_fs.c
@@ -261,13 +261,7 @@ static const struct file_operations ima_ascii_measurements_ops = {
 static ssize_t ima_write_policy(struct file *file, const char __user *buf,
 				size_t datalen, loff_t *ppos)
 {
-	char *data = NULL;
 	ssize_t result;
-	int res;
-
-	res = mutex_lock_interruptible(&ima_write_mutex);
-	if (res)
-		return res;
 
 	if (datalen >= PAGE_SIZE)
 		datalen = PAGE_SIZE - 1;
@@ -286,15 +280,21 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf,
 
 	result = -EFAULT;
 	if (copy_from_user(data, buf, datalen))
-		goto out;
+		goto out_free;
+
+	result = mutex_lock_interruptible(&ima_write_mutex);
+	if (result)
+		goto out_free;
 
 	result = ima_parse_add_rule(data);
-out:
+
+	mutex_unlock(&ima_write_mutex);
+
 	if (result < 0)
 		valid_policy = 0;
+out_free:
 	kfree(data);
-	mutex_unlock(&ima_write_mutex);
-
+out:
 	return result;
 }
 
-- 
2.6.4



  reply	other threads:[~2016-01-01 17:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-31  4:24 linux-next: manual merge of the security tree with the vfs tree Stephen Rothwell
2015-12-31  4:30 ` Al Viro
2015-12-31 10:45   ` Petko Manolov
2016-01-01  4:34     ` Al Viro
2016-01-01 17:29       ` Petko Manolov [this message]
2016-01-01 17:41         ` [PATCH] ima_write_policy() optimizations; kbuild test robot
2016-01-04  1:37 ` linux-next: manual merge of the security tree with the vfs tree Mimi Zohar
2016-01-04  1:55   ` Stephen Rothwell
  -- strict thread matches above, loose matches on Subject: below --
2019-08-12  4:44 Stephen Rothwell
2015-05-13  4:39 Stephen Rothwell
2015-05-13  4:26 Stephen Rothwell
2014-12-10  2:47 Stephen Rothwell

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=20160101172937.GD13634@localhost \
    --to=petkan@mip-labs.com \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=sfr@canb.auug.org.au \
    --cc=viro@ZenIV.linux.org.uk \
    --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;
as well as URLs for NNTP newsgroup(s).