All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] IMA: update ima_counts_put
@ 2009-09-04 17:08 Mimi Zohar
  2009-09-06 21:59 ` Eric Paris
  2009-09-07  2:17 ` [GIT] IMA regression fix James Morris
  0 siblings, 2 replies; 30+ messages in thread
From: Mimi Zohar @ 2009-09-04 17:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: Mimi Zohar, Al Viro, James Morris, David Safford, Ciprian Docan,
	J.R. Okajima, Mimi Zohar

- As ima_counts_put() may be called after the inode has been freed,
verify that the inode is not NULL, before dereferencing it.

- Maintain the IMA file counters in may_open() properly, decrementing
any counter increments on subsequent errors.

Reported-by: Ciprian Docan <docan@eden.rutgers.edu>
Reported-by: J.R. Okajima <hooanon05@yahoo.co.jp>
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
---
 fs/namei.c                        |   22 +++++++++++++++-------
 security/integrity/ima/ima_main.c |    6 +++++-
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index ee01308..fcfc553 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1544,28 +1544,31 @@ int may_open(struct path *path, int acc_mode, int flag)
 	 * An append-only file must be opened in append mode for writing.
 	 */
 	if (IS_APPEND(inode)) {
+		error = -EPERM;
 		if  ((flag & FMODE_WRITE) && !(flag & O_APPEND))
-			return -EPERM;
+			goto err_out;
 		if (flag & O_TRUNC)
-			return -EPERM;
+			goto err_out;
 	}
 
 	/* O_NOATIME can only be set by the owner or superuser */
 	if (flag & O_NOATIME)
-		if (!is_owner_or_cap(inode))
-			return -EPERM;
+		if (!is_owner_or_cap(inode)) {
+			error = -EPERM;
+			goto err_out;
+		}
 
 	/*
 	 * Ensure there are no outstanding leases on the file.
 	 */
 	error = break_lease(inode, flag);
 	if (error)
-		return error;
+		goto err_out;
 
 	if (flag & O_TRUNC) {
 		error = get_write_access(inode);
 		if (error)
-			return error;
+			goto err_out;
 
 		/*
 		 * Refuse to truncate files with mandatory locks held on them.
@@ -1583,12 +1586,17 @@ int may_open(struct path *path, int acc_mode, int flag)
 		}
 		put_write_access(inode);
 		if (error)
-			return error;
+			goto err_out;
 	} else
 		if (flag & FMODE_WRITE)
 			vfs_dq_init(inode);
 
 	return 0;
+err_out:
+	ima_counts_put(path, acc_mode ?
+		       acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC) :
+		       ACC_MODE(flag) & (MAY_READ | MAY_WRITE));
+	return error;
 }
 
 /*
diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
index 101c512..f0c9634 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -249,7 +249,11 @@ void ima_counts_put(struct path *path, int mask)
 	struct inode *inode = path->dentry->d_inode;
 	struct ima_iint_cache *iint;
 
-	if (!ima_initialized || !S_ISREG(inode->i_mode))
+ 	/* The inode may already have been freed, freeing the iint
+	 * with it. Verify the inode is not NULL before dereferencing
+	 * it.
+	 */
+	if (!ima_initialized || !inode || !S_ISREG(inode->i_mode))
 		return;
 	iint = ima_iint_find_insert_get(inode);
 	if (!iint)
-- 
1.6.0.6


^ permalink raw reply related	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2009-09-15  7:51 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-04 17:08 [PATCH] IMA: update ima_counts_put Mimi Zohar
2009-09-06 21:59 ` Eric Paris
2009-09-07  2:17 ` [GIT] IMA regression fix James Morris
2009-09-12  7:24   ` [origin tree boot crash] Revert "selinux: clean up avc node cache when disabling selinux" Ingo Molnar
2009-09-12  7:58     ` [origin tree boot crash #2] kernel BUG at kernel/cred.c:855! Ingo Molnar
2009-09-12  8:19       ` Ingo Molnar
2009-09-12  8:40         ` [PATCH] out-of-tree: Whack warning off in kernel/cred.c Ingo Molnar
2009-09-12  9:58       ` [origin tree boot crash #2] kernel BUG at kernel/cred.c:855! Eric Paris
2009-09-12  9:46     ` [origin tree boot crash] Revert "selinux: clean up avc node cache when disabling selinux" Eric Paris
2009-09-12 10:43       ` Ingo Molnar
2009-09-12 13:58         ` [origin tree boot hang] lockup in key_schedule_gc() Ingo Molnar
2009-09-12 20:27           ` Eric Paris
2009-09-14  6:15             ` Ingo Molnar
2009-09-14 14:38           ` David Howells
2009-09-13  2:28     ` [origin tree boot crash] Revert "selinux: clean up avc node cache when disabling selinux" Eric Paris
2009-09-13 23:03       ` Eric Paris
2009-09-14  7:16       ` [origin tree SLAB corruption] BUG kmalloc-64: Poison overwritten, INFO: Allocated in bdi_alloc_work+0x2b/0x100 age=175 cpu=1 pid=3514 Ingo Molnar
2009-09-14  7:57         ` Pekka Enberg
2009-09-14  9:20           ` Jens Axboe
2009-09-14  9:23             ` Pekka Enberg
2009-09-14 14:40         ` Linus Torvalds
2009-09-14 16:29           ` Paul E. McKenney
2009-09-14 17:10             ` Jens Axboe
2009-09-15  6:57               ` Ingo Molnar
2009-09-15  7:00                 ` Jens Axboe
2009-09-15  7:11                 ` [origin tree SLAB corruption #2] " Ingo Molnar
2009-09-15  7:24                   ` Jens Axboe
2009-09-15  7:44                     ` Ingo Molnar
2009-09-15  7:48                       ` Ingo Molnar
2009-09-15  7:51                         ` Jens Axboe

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.