[PATCH 4.4 45/50] ovl: fix getcwd() failure after unsuccessful rmdir

From: Greg Kroah-Hartman
Date: Mon Mar 14 2016 - 14:11:54 EST


4.4-stable review patch. If anyone has any objections, please let me know.

------------------

From: Rui Wang <rui.y.wang@xxxxxxxxx>

commit ce9113bbcbf45a57c082d6603b9a9f342be3ef74 upstream.

ovl_remove_upper() should do d_drop() only after it successfully
removes the dir, otherwise a subsequent getcwd() system call will
fail, breaking userspace programs.

This is to fix: https://bugzilla.kernel.org/show_bug.cgi?id=110491

Signed-off-by: Rui Wang <rui.y.wang@xxxxxxxxx>
Reviewed-by: Konstantin Khlebnikov <koct9i@xxxxxxxxx>
Signed-off-by: Miklos Szeredi <miklos@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>


---
fs/overlayfs/dir.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -618,7 +618,8 @@ static int ovl_remove_upper(struct dentr
* sole user of this dentry. Too tricky... Just unhash for
* now.
*/
- d_drop(dentry);
+ if (!err)
+ d_drop(dentry);
mutex_unlock(&dir->i_mutex);

return err;