lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1295455337-20219-2-git-send-email-LinoSanfilippo@gmx.de>
Date:	Wed, 19 Jan 2011 17:42:04 +0100
From:	Lino Sanfilippo <LinoSanfilippo@....de>
To:	eparis@...hat.com
Cc:	linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
	Lino Sanfilippo <LinoSanfilippo@....de>
Subject: [PATCH 01/14] fsnotify: change locking order in fsnotify_add_mark()

Instead of taking
1. mark->lock
2. group->mark_lock
3. inode->lock

we now use another order in fsnotify_add_mark():
1. inode->lock
2. mark->lock

and assume that the callers took the group->mark_lock already.
By taking the mark_lock first, we can protect modification of the groups mark
list without the need of an extra lock like the group->mutex.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@....de>
---
 fs/notify/mark.c |   38 +++++---------------------------------
 1 files changed, 5 insertions(+), 33 deletions(-)

diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index 28b64eb..a677af0 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -213,20 +213,9 @@ int fsnotify_add_mark(struct fsnotify_mark *mark,
 
 	/*
 	 * LOCKING ORDER!!!!
-	 * mark->lock
-	 * group->mark_lock
 	 * inode->i_lock
+	 * mark->lock
 	 */
-	spin_lock(&mark->lock);
-	spin_lock(&group->mark_lock);
-
-	mark->flags |= FSNOTIFY_MARK_FLAG_ALIVE;
-	mark->group = group;
-	list_add(&mark->g_list, &group->marks_list);
-	fsnotify_get_mark(mark); /* for i_list and g_list */
-	atomic_inc(&group->num_marks);
-
-	ret = 0;
 	if (inode)
 		ret = fsnotify_add_inode_mark(mark, group, inode, allow_dups);
 	else if (mnt)
@@ -234,34 +223,17 @@ int fsnotify_add_mark(struct fsnotify_mark *mark,
 	else
 		BUG();
 	if (ret)
-		goto err;
-
-	spin_unlock(&group->mark_lock);
+		return ret;
 
-	/* this will pin the object if appropriate */
-	fsnotify_set_mark_mask_locked(mark, mark->mask);
+	fsnotify_get_mark(mark); /* for i_list and g_list */
 
-	spin_unlock(&mark->lock);
+	list_add(&mark->g_list, &group->marks_list);
+	atomic_inc(&group->num_marks);
 
 	if (inode)
 		__fsnotify_update_child_dentry_flags(inode);
 
 	return 0;
-err:
-	mark->flags &= ~FSNOTIFY_MARK_FLAG_ALIVE;
-	list_del_init(&mark->g_list);
-	mark->group = NULL;
-	atomic_dec(&group->num_marks);
-
-	spin_unlock(&group->mark_lock);
-	spin_unlock(&mark->lock);
-
-	spin_lock(&destroy_lock);
-	list_add(&mark->destroy_list, &destroy_list);
-	spin_unlock(&destroy_lock);
-	wake_up(&destroy_waitq);
-
-	return ret;
 }
 
 /*
-- 
1.5.6.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ