Skip to contentSkip to conversation

vfs: fix may_write_real() for overlayfs directories

PATCH New Amir Goldstein 1 participant 1 message Sep 18, 2017 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfs: fix may_write_real() for overlayfs directories

Overlayfs directory file_inode() is the overlay inode whether the real inode is upper or lower.

---

Miklos,

This is a correctness fix.
I only noticed it because may_write_real() change broke xfstest generic/158. The test tries to dedupe a directory, expects EINVAL and gets EPERM on overlayfs instead.

I am not sure if there are cases where this incorrectness could lead to EPERM when directory is upper and operation on dir should succeed.

Amir.

 fs/namespace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/namespace.c +3 -1
index 54059b142d6b..3b601f115b6c 100644
@@ -468,7 +468,9 @@ static inline int may_write_real(struct file *file)
 
 	/* File refers to upper, writable layer? */
 	upperdentry = d_real(dentry, NULL, 0, D_REAL_UPPER);
-	if (upperdentry && file_inode(file) == d_inode(upperdentry))
+	if (upperdentry &&
+	    (file_inode(file) == d_inode(upperdentry) ||
+	     file_inode(file) == d_inode(dentry)))
 		return 0;
 
 	/* Lower layer: can't write to real file, sorry... */
Signature · 1 line
2.7.4