locks: close potential race between setlease and open
[linux-2.6-block.git] / include / linux / fs.h
index 09f553c59813a2b2f88991ab0ab854880e07e574..df8474408331d6143486869c9f920f8ce387674f 100644 (file)
@@ -1964,6 +1964,12 @@ static inline int locks_verify_truncate(struct inode *inode,
 
 static inline int break_lease(struct inode *inode, unsigned int mode)
 {
+       /*
+        * Since this check is lockless, we must ensure that any refcounts
+        * taken are done before checking inode->i_flock. Otherwise, we could
+        * end up racing with tasks trying to set a new lease on this file.
+        */
+       smp_mb();
        if (inode->i_flock)
                return __break_lease(inode, mode, FL_LEASE);
        return 0;