diff options
author | Miklos Szeredi <mszeredi@suse.cz> | 2015-05-14 04:04:44 -0400 |
---|---|---|
committer | Miklos Szeredi <mszeredi@suse.cz> | 2015-05-14 04:04:44 -0400 |
commit | d377c5eb54dd05aeb3094b7740252d19ba7791f7 (patch) | |
tree | e0af790ebf150f97fbb1ea79bdb0d5aa6f2a3474 | |
parent | 030bbdbf4c833bc69f502eae58498bc5572db736 (diff) |
ovl: don't remove non-empty opaque directory
When removing an opaque directory we can't just call rmdir() to check for
emptiness, because the directory will need to be replaced with a whiteout.
The replacement is done with RENAME_EXCHANGE, which doesn't check
emptiness.
Solution is just to check emptiness by reading the directory. In the
future we could add a new rename flag to check for emptiness even for
RENAME_EXCHANGE to optimize this case.
Reported-by: Vincent Batts <vbatts@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Tested-by: Jordi Pujol Palomer <jordipujolp@gmail.com>
Fixes: 263b4a0fee43 ("ovl: dont replace opaque dir")
Cc: <stable@vger.kernel.org> # v4.0+
-rw-r--r-- | fs/overlayfs/dir.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c index d139405d2bfa..2578a0c0677d 100644 --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c | |||
@@ -506,11 +506,25 @@ static int ovl_remove_and_whiteout(struct dentry *dentry, bool is_dir) | |||
506 | struct dentry *opaquedir = NULL; | 506 | struct dentry *opaquedir = NULL; |
507 | int err; | 507 | int err; |
508 | 508 | ||
509 | if (is_dir && OVL_TYPE_MERGE_OR_LOWER(ovl_path_type(dentry))) { | 509 | if (is_dir) { |
510 | opaquedir = ovl_check_empty_and_clear(dentry); | 510 | if (OVL_TYPE_MERGE_OR_LOWER(ovl_path_type(dentry))) { |
511 | err = PTR_ERR(opaquedir); | 511 | opaquedir = ovl_check_empty_and_clear(dentry); |
512 | if (IS_ERR(opaquedir)) | 512 | err = PTR_ERR(opaquedir); |
513 | goto out; | 513 | if (IS_ERR(opaquedir)) |
514 | goto out; | ||
515 | } else { | ||
516 | LIST_HEAD(list); | ||
517 | |||
518 | /* | ||
519 | * When removing an empty opaque directory, then it | ||
520 | * makes no sense to replace it with an exact replica of | ||
521 | * itself. But emptiness still needs to be checked. | ||
522 | */ | ||
523 | err = ovl_check_empty_dir(dentry, &list); | ||
524 | ovl_cache_free(&list); | ||
525 | if (err) | ||
526 | goto out; | ||
527 | } | ||
514 | } | 528 | } |
515 | 529 | ||
516 | err = ovl_lock_rename_workdir(workdir, upperdir); | 530 | err = ovl_lock_rename_workdir(workdir, upperdir); |