Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2011 Novell Inc. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/fs.h> |
| 11 | #include <linux/namei.h> |
| 12 | #include <linux/xattr.h> |
| 13 | #include <linux/security.h> |
| 14 | #include <linux/cred.h> |
Miklos Szeredi | 3ea22a7 | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 15 | #include <linux/module.h> |
Miklos Szeredi | 38b2569 | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 16 | #include <linux/posix_acl.h> |
| 17 | #include <linux/posix_acl_xattr.h> |
Richard Weinberger | 6a45b36 | 2016-09-16 11:45:24 +0200 | [diff] [blame] | 18 | #include <linux/atomic.h> |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 19 | #include <linux/ratelimit.h> |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 20 | #include "overlayfs.h" |
| 21 | |
Miklos Szeredi | 3ea22a7 | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 22 | static unsigned short ovl_redirect_max = 256; |
| 23 | module_param_named(redirect_max, ovl_redirect_max, ushort, 0644); |
| 24 | MODULE_PARM_DESC(ovl_redirect_max, |
| 25 | "Maximum length of absolute redirect xattr value"); |
| 26 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 27 | void ovl_cleanup(struct inode *wdir, struct dentry *wdentry) |
| 28 | { |
| 29 | int err; |
| 30 | |
| 31 | dget(wdentry); |
David Howells | e36cb0b | 2015-01-29 12:02:35 +0000 | [diff] [blame] | 32 | if (d_is_dir(wdentry)) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 33 | err = ovl_do_rmdir(wdir, wdentry); |
| 34 | else |
| 35 | err = ovl_do_unlink(wdir, wdentry); |
| 36 | dput(wdentry); |
| 37 | |
| 38 | if (err) { |
| 39 | pr_err("overlayfs: cleanup of '%pd2' failed (%i)\n", |
| 40 | wdentry, err); |
| 41 | } |
| 42 | } |
| 43 | |
Miklos Szeredi | 3d27573 | 2017-05-19 09:33:49 +0200 | [diff] [blame] | 44 | struct dentry *ovl_lookup_temp(struct dentry *workdir) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 45 | { |
| 46 | struct dentry *temp; |
| 47 | char name[20]; |
Richard Weinberger | 6a45b36 | 2016-09-16 11:45:24 +0200 | [diff] [blame] | 48 | static atomic_t temp_id = ATOMIC_INIT(0); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 49 | |
Richard Weinberger | 6a45b36 | 2016-09-16 11:45:24 +0200 | [diff] [blame] | 50 | /* counter is allowed to wrap, since temp dentries are ephemeral */ |
| 51 | snprintf(name, sizeof(name), "#%x", atomic_inc_return(&temp_id)); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 52 | |
| 53 | temp = lookup_one_len(name, workdir, strlen(name)); |
| 54 | if (!IS_ERR(temp) && temp->d_inode) { |
| 55 | pr_err("overlayfs: workdir/%s already exists\n", name); |
| 56 | dput(temp); |
| 57 | temp = ERR_PTR(-EIO); |
| 58 | } |
| 59 | |
| 60 | return temp; |
| 61 | } |
| 62 | |
| 63 | /* caller holds i_mutex on workdir */ |
| 64 | static struct dentry *ovl_whiteout(struct dentry *workdir, |
| 65 | struct dentry *dentry) |
| 66 | { |
| 67 | int err; |
| 68 | struct dentry *whiteout; |
| 69 | struct inode *wdir = workdir->d_inode; |
| 70 | |
Miklos Szeredi | 3d27573 | 2017-05-19 09:33:49 +0200 | [diff] [blame] | 71 | whiteout = ovl_lookup_temp(workdir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 72 | if (IS_ERR(whiteout)) |
| 73 | return whiteout; |
| 74 | |
| 75 | err = ovl_do_whiteout(wdir, whiteout); |
| 76 | if (err) { |
| 77 | dput(whiteout); |
| 78 | whiteout = ERR_PTR(err); |
| 79 | } |
| 80 | |
| 81 | return whiteout; |
| 82 | } |
| 83 | |
| 84 | int ovl_create_real(struct inode *dir, struct dentry *newdentry, |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 85 | struct cattr *attr, struct dentry *hardlink, bool debug) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 86 | { |
| 87 | int err; |
| 88 | |
| 89 | if (newdentry->d_inode) |
| 90 | return -ESTALE; |
| 91 | |
| 92 | if (hardlink) { |
| 93 | err = ovl_do_link(hardlink, dir, newdentry, debug); |
| 94 | } else { |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 95 | switch (attr->mode & S_IFMT) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 96 | case S_IFREG: |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 97 | err = ovl_do_create(dir, newdentry, attr->mode, debug); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 98 | break; |
| 99 | |
| 100 | case S_IFDIR: |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 101 | err = ovl_do_mkdir(dir, newdentry, attr->mode, debug); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 102 | break; |
| 103 | |
| 104 | case S_IFCHR: |
| 105 | case S_IFBLK: |
| 106 | case S_IFIFO: |
| 107 | case S_IFSOCK: |
| 108 | err = ovl_do_mknod(dir, newdentry, |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 109 | attr->mode, attr->rdev, debug); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 110 | break; |
| 111 | |
| 112 | case S_IFLNK: |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 113 | err = ovl_do_symlink(dir, newdentry, attr->link, debug); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 114 | break; |
| 115 | |
| 116 | default: |
| 117 | err = -EPERM; |
| 118 | } |
| 119 | } |
| 120 | if (!err && WARN_ON(!newdentry->d_inode)) { |
| 121 | /* |
| 122 | * Not quite sure if non-instantiated dentry is legal or not. |
| 123 | * VFS doesn't seem to care so check and warn here. |
| 124 | */ |
| 125 | err = -ENOENT; |
| 126 | } |
| 127 | return err; |
| 128 | } |
| 129 | |
Amir Goldstein | 21a2287 | 2017-05-17 00:12:41 +0300 | [diff] [blame] | 130 | static int ovl_set_opaque_xerr(struct dentry *dentry, struct dentry *upper, |
| 131 | int xerr) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 132 | { |
Miklos Szeredi | 5cf5b47 | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 133 | int err; |
| 134 | |
Amir Goldstein | 21a2287 | 2017-05-17 00:12:41 +0300 | [diff] [blame] | 135 | err = ovl_check_setxattr(dentry, upper, OVL_XATTR_OPAQUE, "y", 1, xerr); |
Miklos Szeredi | 5cf5b47 | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 136 | if (!err) |
| 137 | ovl_dentry_set_opaque(dentry); |
| 138 | |
| 139 | return err; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 140 | } |
| 141 | |
Amir Goldstein | 21a2287 | 2017-05-17 00:12:41 +0300 | [diff] [blame] | 142 | static int ovl_set_opaque(struct dentry *dentry, struct dentry *upperdentry) |
| 143 | { |
| 144 | /* |
| 145 | * Fail with -EIO when trying to create opaque dir and upper doesn't |
| 146 | * support xattrs. ovl_rename() calls ovl_set_opaque_xerr(-EXDEV) to |
| 147 | * return a specific error for noxattr case. |
| 148 | */ |
| 149 | return ovl_set_opaque_xerr(dentry, upperdentry, -EIO); |
| 150 | } |
| 151 | |
Vivek Goyal | 72e4848 | 2016-06-16 10:09:14 -0400 | [diff] [blame] | 152 | /* Common operations required to be done after creation of file on upper */ |
| 153 | static void ovl_instantiate(struct dentry *dentry, struct inode *inode, |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 154 | struct dentry *newdentry, bool hardlink) |
Vivek Goyal | 72e4848 | 2016-06-16 10:09:14 -0400 | [diff] [blame] | 155 | { |
| 156 | ovl_dentry_version_inc(dentry->d_parent); |
| 157 | ovl_dentry_update(dentry, newdentry); |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 158 | if (!hardlink) { |
| 159 | ovl_inode_update(inode, d_inode(newdentry)); |
| 160 | ovl_copyattr(newdentry->d_inode, inode); |
| 161 | } else { |
| 162 | WARN_ON(ovl_inode_real(inode, NULL) != d_inode(newdentry)); |
| 163 | inc_nlink(inode); |
| 164 | } |
Vivek Goyal | 72e4848 | 2016-06-16 10:09:14 -0400 | [diff] [blame] | 165 | d_instantiate(dentry, inode); |
Amir Goldstein | 5b6c905 | 2017-04-24 19:54:13 +0300 | [diff] [blame] | 166 | /* Force lookup of new upper hardlink to find its lower */ |
| 167 | if (hardlink) |
| 168 | d_drop(dentry); |
Vivek Goyal | 72e4848 | 2016-06-16 10:09:14 -0400 | [diff] [blame] | 169 | } |
| 170 | |
Amir Goldstein | 97c684c | 2016-11-21 18:57:34 +0200 | [diff] [blame] | 171 | static bool ovl_type_merge(struct dentry *dentry) |
| 172 | { |
| 173 | return OVL_TYPE_MERGE(ovl_path_type(dentry)); |
| 174 | } |
| 175 | |
Amir Goldstein | ee1d6d37 | 2017-05-11 16:42:26 +0300 | [diff] [blame] | 176 | static bool ovl_type_origin(struct dentry *dentry) |
| 177 | { |
| 178 | return OVL_TYPE_ORIGIN(ovl_path_type(dentry)); |
| 179 | } |
| 180 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 181 | static int ovl_create_upper(struct dentry *dentry, struct inode *inode, |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 182 | struct cattr *attr, struct dentry *hardlink) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 183 | { |
| 184 | struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); |
| 185 | struct inode *udir = upperdir->d_inode; |
| 186 | struct dentry *newdentry; |
| 187 | int err; |
| 188 | |
Miklos Szeredi | 38b2569 | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 189 | if (!hardlink && !IS_POSIXACL(udir)) |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 190 | attr->mode &= ~current_umask(); |
Miklos Szeredi | 38b2569 | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 191 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 192 | inode_lock_nested(udir, I_MUTEX_PARENT); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 193 | newdentry = lookup_one_len(dentry->d_name.name, upperdir, |
| 194 | dentry->d_name.len); |
| 195 | err = PTR_ERR(newdentry); |
| 196 | if (IS_ERR(newdentry)) |
| 197 | goto out_unlock; |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 198 | err = ovl_create_real(udir, newdentry, attr, hardlink, false); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 199 | if (err) |
| 200 | goto out_dput; |
| 201 | |
Amir Goldstein | 4a99f3c | 2017-04-24 22:26:40 +0300 | [diff] [blame] | 202 | if (ovl_type_merge(dentry->d_parent) && d_is_dir(newdentry)) { |
Amir Goldstein | 97c684c | 2016-11-21 18:57:34 +0200 | [diff] [blame] | 203 | /* Setting opaque here is just an optimization, allow to fail */ |
| 204 | ovl_set_opaque(dentry, newdentry); |
| 205 | } |
| 206 | |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 207 | ovl_instantiate(dentry, inode, newdentry, !!hardlink); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 208 | newdentry = NULL; |
| 209 | out_dput: |
| 210 | dput(newdentry); |
| 211 | out_unlock: |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 212 | inode_unlock(udir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 213 | return err; |
| 214 | } |
| 215 | |
| 216 | static int ovl_lock_rename_workdir(struct dentry *workdir, |
| 217 | struct dentry *upperdir) |
| 218 | { |
| 219 | /* Workdir should not be the same as upperdir */ |
| 220 | if (workdir == upperdir) |
| 221 | goto err; |
| 222 | |
| 223 | /* Workdir should not be subdir of upperdir and vice versa */ |
| 224 | if (lock_rename(workdir, upperdir) != NULL) |
| 225 | goto err_unlock; |
| 226 | |
| 227 | return 0; |
| 228 | |
| 229 | err_unlock: |
| 230 | unlock_rename(workdir, upperdir); |
| 231 | err: |
| 232 | pr_err("overlayfs: failed to lock workdir+upperdir\n"); |
| 233 | return -EIO; |
| 234 | } |
| 235 | |
| 236 | static struct dentry *ovl_clear_empty(struct dentry *dentry, |
| 237 | struct list_head *list) |
| 238 | { |
| 239 | struct dentry *workdir = ovl_workdir(dentry); |
| 240 | struct inode *wdir = workdir->d_inode; |
| 241 | struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); |
| 242 | struct inode *udir = upperdir->d_inode; |
| 243 | struct path upperpath; |
| 244 | struct dentry *upper; |
| 245 | struct dentry *opaquedir; |
| 246 | struct kstat stat; |
| 247 | int err; |
| 248 | |
Miklos Szeredi | cc6f67b | 2015-05-19 14:30:12 +0200 | [diff] [blame] | 249 | if (WARN_ON(!workdir)) |
| 250 | return ERR_PTR(-EROFS); |
| 251 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 252 | err = ovl_lock_rename_workdir(workdir, upperdir); |
| 253 | if (err) |
| 254 | goto out; |
| 255 | |
| 256 | ovl_path_upper(dentry, &upperpath); |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 257 | err = vfs_getattr(&upperpath, &stat, |
| 258 | STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 259 | if (err) |
| 260 | goto out_unlock; |
| 261 | |
| 262 | err = -ESTALE; |
| 263 | if (!S_ISDIR(stat.mode)) |
| 264 | goto out_unlock; |
| 265 | upper = upperpath.dentry; |
| 266 | if (upper->d_parent->d_inode != udir) |
| 267 | goto out_unlock; |
| 268 | |
Miklos Szeredi | 3d27573 | 2017-05-19 09:33:49 +0200 | [diff] [blame] | 269 | opaquedir = ovl_lookup_temp(workdir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 270 | err = PTR_ERR(opaquedir); |
| 271 | if (IS_ERR(opaquedir)) |
| 272 | goto out_unlock; |
| 273 | |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 274 | err = ovl_create_real(wdir, opaquedir, |
| 275 | &(struct cattr){.mode = stat.mode}, NULL, true); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 276 | if (err) |
| 277 | goto out_dput; |
| 278 | |
| 279 | err = ovl_copy_xattr(upper, opaquedir); |
| 280 | if (err) |
| 281 | goto out_cleanup; |
| 282 | |
Miklos Szeredi | 5cf5b47 | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 283 | err = ovl_set_opaque(dentry, opaquedir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 284 | if (err) |
| 285 | goto out_cleanup; |
| 286 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 287 | inode_lock(opaquedir->d_inode); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 288 | err = ovl_set_attr(opaquedir, &stat); |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 289 | inode_unlock(opaquedir->d_inode); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 290 | if (err) |
| 291 | goto out_cleanup; |
| 292 | |
| 293 | err = ovl_do_rename(wdir, opaquedir, udir, upper, RENAME_EXCHANGE); |
| 294 | if (err) |
| 295 | goto out_cleanup; |
| 296 | |
| 297 | ovl_cleanup_whiteouts(upper, list); |
| 298 | ovl_cleanup(wdir, upper); |
| 299 | unlock_rename(workdir, upperdir); |
| 300 | |
| 301 | /* dentry's upper doesn't match now, get rid of it */ |
| 302 | d_drop(dentry); |
| 303 | |
| 304 | return opaquedir; |
| 305 | |
| 306 | out_cleanup: |
| 307 | ovl_cleanup(wdir, opaquedir); |
| 308 | out_dput: |
| 309 | dput(opaquedir); |
| 310 | out_unlock: |
| 311 | unlock_rename(workdir, upperdir); |
| 312 | out: |
| 313 | return ERR_PTR(err); |
| 314 | } |
| 315 | |
Miklos Szeredi | a105d68 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 316 | static struct dentry *ovl_check_empty_and_clear(struct dentry *dentry) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 317 | { |
| 318 | int err; |
| 319 | struct dentry *ret = NULL; |
Miklos Szeredi | 30c17eb | 2016-07-29 12:05:25 +0200 | [diff] [blame] | 320 | enum ovl_path_type type = ovl_path_type(dentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 321 | LIST_HEAD(list); |
| 322 | |
| 323 | err = ovl_check_empty_dir(dentry, &list); |
Miklos Szeredi | 30c17eb | 2016-07-29 12:05:25 +0200 | [diff] [blame] | 324 | if (err) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 325 | ret = ERR_PTR(err); |
Miklos Szeredi | 30c17eb | 2016-07-29 12:05:25 +0200 | [diff] [blame] | 326 | goto out_free; |
Miklos Szeredi | a105d68 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 327 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 328 | |
Miklos Szeredi | 30c17eb | 2016-07-29 12:05:25 +0200 | [diff] [blame] | 329 | /* |
| 330 | * When removing an empty opaque directory, then it makes no sense to |
| 331 | * replace it with an exact replica of itself. |
| 332 | * |
| 333 | * If no upperdentry then skip clearing whiteouts. |
| 334 | * |
| 335 | * Can race with copy-up, since we don't hold the upperdir mutex. |
| 336 | * Doesn't matter, since copy-up can't create a non-empty directory |
| 337 | * from an empty one. |
| 338 | */ |
| 339 | if (OVL_TYPE_UPPER(type) && OVL_TYPE_MERGE(type)) |
| 340 | ret = ovl_clear_empty(dentry, &list); |
| 341 | |
| 342 | out_free: |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 343 | ovl_cache_free(&list); |
| 344 | |
| 345 | return ret; |
| 346 | } |
| 347 | |
Miklos Szeredi | 38b2569 | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 348 | static int ovl_set_upper_acl(struct dentry *upperdentry, const char *name, |
| 349 | const struct posix_acl *acl) |
| 350 | { |
| 351 | void *buffer; |
| 352 | size_t size; |
| 353 | int err; |
| 354 | |
| 355 | if (!IS_ENABLED(CONFIG_FS_POSIX_ACL) || !acl) |
| 356 | return 0; |
| 357 | |
| 358 | size = posix_acl_to_xattr(NULL, acl, NULL, 0); |
| 359 | buffer = kmalloc(size, GFP_KERNEL); |
| 360 | if (!buffer) |
| 361 | return -ENOMEM; |
| 362 | |
| 363 | size = posix_acl_to_xattr(&init_user_ns, acl, buffer, size); |
| 364 | err = size; |
| 365 | if (err < 0) |
| 366 | goto out_free; |
| 367 | |
| 368 | err = vfs_setxattr(upperdentry, name, buffer, size, XATTR_CREATE); |
| 369 | out_free: |
| 370 | kfree(buffer); |
| 371 | return err; |
| 372 | } |
| 373 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 374 | static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode, |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 375 | struct cattr *cattr, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 376 | struct dentry *hardlink) |
| 377 | { |
| 378 | struct dentry *workdir = ovl_workdir(dentry); |
| 379 | struct inode *wdir = workdir->d_inode; |
| 380 | struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); |
| 381 | struct inode *udir = upperdir->d_inode; |
| 382 | struct dentry *upper; |
| 383 | struct dentry *newdentry; |
| 384 | int err; |
Miklos Szeredi | 38b2569 | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 385 | struct posix_acl *acl, *default_acl; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 386 | |
Miklos Szeredi | cc6f67b | 2015-05-19 14:30:12 +0200 | [diff] [blame] | 387 | if (WARN_ON(!workdir)) |
| 388 | return -EROFS; |
| 389 | |
Miklos Szeredi | 38b2569 | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 390 | if (!hardlink) { |
| 391 | err = posix_acl_create(dentry->d_parent->d_inode, |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 392 | &cattr->mode, &default_acl, &acl); |
Miklos Szeredi | 38b2569 | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 393 | if (err) |
| 394 | return err; |
| 395 | } |
| 396 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 397 | err = ovl_lock_rename_workdir(workdir, upperdir); |
| 398 | if (err) |
| 399 | goto out; |
| 400 | |
Miklos Szeredi | 3d27573 | 2017-05-19 09:33:49 +0200 | [diff] [blame] | 401 | newdentry = ovl_lookup_temp(workdir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 402 | err = PTR_ERR(newdentry); |
| 403 | if (IS_ERR(newdentry)) |
| 404 | goto out_unlock; |
| 405 | |
| 406 | upper = lookup_one_len(dentry->d_name.name, upperdir, |
| 407 | dentry->d_name.len); |
| 408 | err = PTR_ERR(upper); |
| 409 | if (IS_ERR(upper)) |
| 410 | goto out_dput; |
| 411 | |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 412 | err = ovl_create_real(wdir, newdentry, cattr, hardlink, true); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 413 | if (err) |
| 414 | goto out_dput2; |
| 415 | |
Miklos Szeredi | bb0d2b8 | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 416 | /* |
| 417 | * mode could have been mutilated due to umask (e.g. sgid directory) |
| 418 | */ |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 419 | if (!hardlink && |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 420 | !S_ISLNK(cattr->mode) && |
| 421 | newdentry->d_inode->i_mode != cattr->mode) { |
Miklos Szeredi | bb0d2b8 | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 422 | struct iattr attr = { |
| 423 | .ia_valid = ATTR_MODE, |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 424 | .ia_mode = cattr->mode, |
Miklos Szeredi | bb0d2b8 | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 425 | }; |
| 426 | inode_lock(newdentry->d_inode); |
| 427 | err = notify_change(newdentry, &attr, NULL); |
| 428 | inode_unlock(newdentry->d_inode); |
| 429 | if (err) |
| 430 | goto out_cleanup; |
| 431 | } |
Miklos Szeredi | 38b2569 | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 432 | if (!hardlink) { |
| 433 | err = ovl_set_upper_acl(newdentry, XATTR_NAME_POSIX_ACL_ACCESS, |
| 434 | acl); |
| 435 | if (err) |
| 436 | goto out_cleanup; |
| 437 | |
| 438 | err = ovl_set_upper_acl(newdentry, XATTR_NAME_POSIX_ACL_DEFAULT, |
| 439 | default_acl); |
| 440 | if (err) |
| 441 | goto out_cleanup; |
| 442 | } |
Miklos Szeredi | bb0d2b8 | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 443 | |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 444 | if (!hardlink && S_ISDIR(cattr->mode)) { |
Miklos Szeredi | 5cf5b47 | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 445 | err = ovl_set_opaque(dentry, newdentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 446 | if (err) |
| 447 | goto out_cleanup; |
| 448 | |
| 449 | err = ovl_do_rename(wdir, newdentry, udir, upper, |
| 450 | RENAME_EXCHANGE); |
| 451 | if (err) |
| 452 | goto out_cleanup; |
| 453 | |
| 454 | ovl_cleanup(wdir, upper); |
| 455 | } else { |
| 456 | err = ovl_do_rename(wdir, newdentry, udir, upper, 0); |
| 457 | if (err) |
| 458 | goto out_cleanup; |
| 459 | } |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 460 | ovl_instantiate(dentry, inode, newdentry, !!hardlink); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 461 | newdentry = NULL; |
| 462 | out_dput2: |
| 463 | dput(upper); |
| 464 | out_dput: |
| 465 | dput(newdentry); |
| 466 | out_unlock: |
| 467 | unlock_rename(workdir, upperdir); |
| 468 | out: |
Miklos Szeredi | 38b2569 | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 469 | if (!hardlink) { |
| 470 | posix_acl_release(acl); |
| 471 | posix_acl_release(default_acl); |
| 472 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 473 | return err; |
| 474 | |
| 475 | out_cleanup: |
| 476 | ovl_cleanup(wdir, newdentry); |
| 477 | goto out_dput2; |
| 478 | } |
| 479 | |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 480 | static int ovl_create_or_link(struct dentry *dentry, struct inode *inode, |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 481 | struct cattr *attr, struct dentry *hardlink) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 482 | { |
| 483 | int err; |
Vivek Goyal | 1175b6b | 2016-07-01 16:34:28 -0400 | [diff] [blame] | 484 | const struct cred *old_cred; |
| 485 | struct cred *override_cred; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 486 | |
| 487 | err = ovl_copy_up(dentry->d_parent); |
| 488 | if (err) |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 489 | return err; |
Miklos Szeredi | bb0d2b8 | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 490 | |
Vivek Goyal | 1175b6b | 2016-07-01 16:34:28 -0400 | [diff] [blame] | 491 | old_cred = ovl_override_creds(dentry->d_sb); |
| 492 | err = -ENOMEM; |
| 493 | override_cred = prepare_creds(); |
| 494 | if (override_cred) { |
Miklos Szeredi | bb0d2b8 | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 495 | override_cred->fsuid = inode->i_uid; |
| 496 | override_cred->fsgid = inode->i_gid; |
Vivek Goyal | 2602625 | 2016-07-13 10:44:52 -0400 | [diff] [blame] | 497 | if (!hardlink) { |
| 498 | err = security_dentry_create_files_as(dentry, |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 499 | attr->mode, &dentry->d_name, old_cred, |
Vivek Goyal | 2602625 | 2016-07-13 10:44:52 -0400 | [diff] [blame] | 500 | override_cred); |
| 501 | if (err) { |
| 502 | put_cred(override_cred); |
| 503 | goto out_revert_creds; |
| 504 | } |
| 505 | } |
Vivek Goyal | 1175b6b | 2016-07-01 16:34:28 -0400 | [diff] [blame] | 506 | put_cred(override_creds(override_cred)); |
| 507 | put_cred(override_cred); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 508 | |
Miklos Szeredi | c412ce4 | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 509 | if (!ovl_dentry_is_whiteout(dentry)) |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 510 | err = ovl_create_upper(dentry, inode, attr, |
Vivek Goyal | 1175b6b | 2016-07-01 16:34:28 -0400 | [diff] [blame] | 511 | hardlink); |
| 512 | else |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 513 | err = ovl_create_over_whiteout(dentry, inode, attr, |
| 514 | hardlink); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 515 | } |
Vivek Goyal | 2602625 | 2016-07-13 10:44:52 -0400 | [diff] [blame] | 516 | out_revert_creds: |
Vivek Goyal | 1175b6b | 2016-07-01 16:34:28 -0400 | [diff] [blame] | 517 | revert_creds(old_cred); |
Miklos Szeredi | bb0d2b8 | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 518 | if (!err) { |
| 519 | struct inode *realinode = d_inode(ovl_dentry_upper(dentry)); |
| 520 | |
| 521 | WARN_ON(inode->i_mode != realinode->i_mode); |
| 522 | WARN_ON(!uid_eq(inode->i_uid, realinode->i_uid)); |
| 523 | WARN_ON(!gid_eq(inode->i_gid, realinode->i_gid)); |
Miklos Szeredi | bb0d2b8 | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 524 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 525 | return err; |
| 526 | } |
| 527 | |
| 528 | static int ovl_create_object(struct dentry *dentry, int mode, dev_t rdev, |
| 529 | const char *link) |
| 530 | { |
| 531 | int err; |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 532 | struct inode *inode; |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 533 | struct cattr attr = { |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 534 | .rdev = rdev, |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 535 | .link = link, |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 536 | }; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 537 | |
| 538 | err = ovl_want_write(dentry); |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 539 | if (err) |
| 540 | goto out; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 541 | |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 542 | err = -ENOMEM; |
Miklos Szeredi | ca4c8a3 | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 543 | inode = ovl_new_inode(dentry->d_sb, mode, rdev); |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 544 | if (!inode) |
| 545 | goto out_drop_write; |
| 546 | |
| 547 | inode_init_owner(inode, dentry->d_parent->d_inode, mode); |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 548 | attr.mode = inode->i_mode; |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 549 | |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 550 | err = ovl_create_or_link(dentry, inode, &attr, NULL); |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 551 | if (err) |
| 552 | iput(inode); |
| 553 | |
| 554 | out_drop_write: |
| 555 | ovl_drop_write(dentry); |
| 556 | out: |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 557 | return err; |
| 558 | } |
| 559 | |
| 560 | static int ovl_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
| 561 | bool excl) |
| 562 | { |
| 563 | return ovl_create_object(dentry, (mode & 07777) | S_IFREG, 0, NULL); |
| 564 | } |
| 565 | |
| 566 | static int ovl_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
| 567 | { |
| 568 | return ovl_create_object(dentry, (mode & 07777) | S_IFDIR, 0, NULL); |
| 569 | } |
| 570 | |
| 571 | static int ovl_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
| 572 | dev_t rdev) |
| 573 | { |
| 574 | /* Don't allow creation of "whiteout" on overlay */ |
| 575 | if (S_ISCHR(mode) && rdev == WHITEOUT_DEV) |
| 576 | return -EPERM; |
| 577 | |
| 578 | return ovl_create_object(dentry, mode, rdev, NULL); |
| 579 | } |
| 580 | |
| 581 | static int ovl_symlink(struct inode *dir, struct dentry *dentry, |
| 582 | const char *link) |
| 583 | { |
| 584 | return ovl_create_object(dentry, S_IFLNK, 0, link); |
| 585 | } |
| 586 | |
| 587 | static int ovl_link(struct dentry *old, struct inode *newdir, |
| 588 | struct dentry *new) |
| 589 | { |
| 590 | int err; |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 591 | struct inode *inode; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 592 | |
| 593 | err = ovl_want_write(old); |
| 594 | if (err) |
| 595 | goto out; |
| 596 | |
| 597 | err = ovl_copy_up(old); |
| 598 | if (err) |
| 599 | goto out_drop_write; |
| 600 | |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 601 | inode = d_inode(old); |
| 602 | ihold(inode); |
| 603 | |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 604 | err = ovl_create_or_link(new, inode, NULL, ovl_dentry_upper(old)); |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 605 | if (err) |
| 606 | iput(inode); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 607 | |
| 608 | out_drop_write: |
| 609 | ovl_drop_write(old); |
| 610 | out: |
| 611 | return err; |
| 612 | } |
| 613 | |
Miklos Szeredi | a105d68 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 614 | static int ovl_remove_and_whiteout(struct dentry *dentry, bool is_dir) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 615 | { |
| 616 | struct dentry *workdir = ovl_workdir(dentry); |
| 617 | struct inode *wdir = workdir->d_inode; |
| 618 | struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); |
| 619 | struct inode *udir = upperdir->d_inode; |
| 620 | struct dentry *whiteout; |
| 621 | struct dentry *upper; |
| 622 | struct dentry *opaquedir = NULL; |
| 623 | int err; |
Maxim Patlasov | cfc9fde | 2016-07-21 18:24:26 -0700 | [diff] [blame] | 624 | int flags = 0; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 625 | |
Miklos Szeredi | cc6f67b | 2015-05-19 14:30:12 +0200 | [diff] [blame] | 626 | if (WARN_ON(!workdir)) |
| 627 | return -EROFS; |
| 628 | |
Miklos Szeredi | d377c5e | 2015-05-14 10:04:44 +0200 | [diff] [blame] | 629 | if (is_dir) { |
Miklos Szeredi | 30c17eb | 2016-07-29 12:05:25 +0200 | [diff] [blame] | 630 | opaquedir = ovl_check_empty_and_clear(dentry); |
| 631 | err = PTR_ERR(opaquedir); |
| 632 | if (IS_ERR(opaquedir)) |
| 633 | goto out; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | err = ovl_lock_rename_workdir(workdir, upperdir); |
| 637 | if (err) |
| 638 | goto out_dput; |
| 639 | |
Maxim Patlasov | cfc9fde | 2016-07-21 18:24:26 -0700 | [diff] [blame] | 640 | upper = lookup_one_len(dentry->d_name.name, upperdir, |
| 641 | dentry->d_name.len); |
| 642 | err = PTR_ERR(upper); |
| 643 | if (IS_ERR(upper)) |
| 644 | goto out_unlock; |
| 645 | |
| 646 | err = -ESTALE; |
| 647 | if ((opaquedir && upper != opaquedir) || |
| 648 | (!opaquedir && ovl_dentry_upper(dentry) && |
| 649 | upper != ovl_dentry_upper(dentry))) { |
| 650 | goto out_dput_upper; |
| 651 | } |
| 652 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 653 | whiteout = ovl_whiteout(workdir, dentry); |
| 654 | err = PTR_ERR(whiteout); |
| 655 | if (IS_ERR(whiteout)) |
Maxim Patlasov | cfc9fde | 2016-07-21 18:24:26 -0700 | [diff] [blame] | 656 | goto out_dput_upper; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 657 | |
Maxim Patlasov | cfc9fde | 2016-07-21 18:24:26 -0700 | [diff] [blame] | 658 | if (d_is_dir(upper)) |
| 659 | flags = RENAME_EXCHANGE; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 660 | |
Maxim Patlasov | cfc9fde | 2016-07-21 18:24:26 -0700 | [diff] [blame] | 661 | err = ovl_do_rename(wdir, whiteout, udir, upper, flags); |
| 662 | if (err) |
| 663 | goto kill_whiteout; |
| 664 | if (flags) |
| 665 | ovl_cleanup(wdir, upper); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 666 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 667 | ovl_dentry_version_inc(dentry->d_parent); |
| 668 | out_d_drop: |
| 669 | d_drop(dentry); |
| 670 | dput(whiteout); |
Maxim Patlasov | cfc9fde | 2016-07-21 18:24:26 -0700 | [diff] [blame] | 671 | out_dput_upper: |
| 672 | dput(upper); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 673 | out_unlock: |
| 674 | unlock_rename(workdir, upperdir); |
| 675 | out_dput: |
| 676 | dput(opaquedir); |
| 677 | out: |
| 678 | return err; |
| 679 | |
| 680 | kill_whiteout: |
| 681 | ovl_cleanup(wdir, whiteout); |
| 682 | goto out_d_drop; |
| 683 | } |
| 684 | |
| 685 | static int ovl_remove_upper(struct dentry *dentry, bool is_dir) |
| 686 | { |
| 687 | struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); |
| 688 | struct inode *dir = upperdir->d_inode; |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 689 | struct dentry *upper; |
Amir Goldstein | d159511 | 2016-10-26 12:34:06 +0300 | [diff] [blame] | 690 | struct dentry *opaquedir = NULL; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 691 | int err; |
| 692 | |
Amir Goldstein | d159511 | 2016-10-26 12:34:06 +0300 | [diff] [blame] | 693 | /* Redirect dir can be !ovl_lower_positive && OVL_TYPE_MERGE */ |
| 694 | if (is_dir && ovl_dentry_get_redirect(dentry)) { |
| 695 | opaquedir = ovl_check_empty_and_clear(dentry); |
| 696 | err = PTR_ERR(opaquedir); |
| 697 | if (IS_ERR(opaquedir)) |
| 698 | goto out; |
| 699 | } |
| 700 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 701 | inode_lock_nested(dir, I_MUTEX_PARENT); |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 702 | upper = lookup_one_len(dentry->d_name.name, upperdir, |
| 703 | dentry->d_name.len); |
| 704 | err = PTR_ERR(upper); |
| 705 | if (IS_ERR(upper)) |
| 706 | goto out_unlock; |
| 707 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 708 | err = -ESTALE; |
Amir Goldstein | d159511 | 2016-10-26 12:34:06 +0300 | [diff] [blame] | 709 | if ((opaquedir && upper != opaquedir) || |
| 710 | (!opaquedir && upper != ovl_dentry_upper(dentry))) |
| 711 | goto out_dput_upper; |
| 712 | |
| 713 | if (is_dir) |
| 714 | err = vfs_rmdir(dir, upper); |
| 715 | else |
| 716 | err = vfs_unlink(dir, upper, NULL); |
| 717 | ovl_dentry_version_inc(dentry->d_parent); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 718 | |
| 719 | /* |
| 720 | * Keeping this dentry hashed would mean having to release |
| 721 | * upperpath/lowerpath, which could only be done if we are the |
| 722 | * sole user of this dentry. Too tricky... Just unhash for |
| 723 | * now. |
| 724 | */ |
Rui Wang | ce9113b | 2016-01-08 23:09:59 +0800 | [diff] [blame] | 725 | if (!err) |
| 726 | d_drop(dentry); |
Amir Goldstein | d159511 | 2016-10-26 12:34:06 +0300 | [diff] [blame] | 727 | out_dput_upper: |
| 728 | dput(upper); |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 729 | out_unlock: |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 730 | inode_unlock(dir); |
Amir Goldstein | d159511 | 2016-10-26 12:34:06 +0300 | [diff] [blame] | 731 | dput(opaquedir); |
| 732 | out: |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 733 | return err; |
| 734 | } |
| 735 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 736 | static int ovl_do_remove(struct dentry *dentry, bool is_dir) |
| 737 | { |
| 738 | enum ovl_path_type type; |
| 739 | int err; |
Vivek Goyal | 1175b6b | 2016-07-01 16:34:28 -0400 | [diff] [blame] | 740 | const struct cred *old_cred; |
| 741 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 742 | err = ovl_want_write(dentry); |
| 743 | if (err) |
| 744 | goto out; |
| 745 | |
| 746 | err = ovl_copy_up(dentry->d_parent); |
| 747 | if (err) |
| 748 | goto out_drop_write; |
| 749 | |
| 750 | type = ovl_path_type(dentry); |
Vivek Goyal | 1175b6b | 2016-07-01 16:34:28 -0400 | [diff] [blame] | 751 | |
| 752 | old_cred = ovl_override_creds(dentry->d_sb); |
Miklos Szeredi | 2aff453 | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 753 | if (!ovl_lower_positive(dentry)) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 754 | err = ovl_remove_upper(dentry, is_dir); |
Vivek Goyal | 1175b6b | 2016-07-01 16:34:28 -0400 | [diff] [blame] | 755 | else |
Miklos Szeredi | a105d68 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 756 | err = ovl_remove_and_whiteout(dentry, is_dir); |
Vivek Goyal | 1175b6b | 2016-07-01 16:34:28 -0400 | [diff] [blame] | 757 | revert_creds(old_cred); |
Miklos Szeredi | dbc816d | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 758 | if (!err) { |
| 759 | if (is_dir) |
| 760 | clear_nlink(dentry->d_inode); |
| 761 | else |
| 762 | drop_nlink(dentry->d_inode); |
| 763 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 764 | out_drop_write: |
| 765 | ovl_drop_write(dentry); |
| 766 | out: |
| 767 | return err; |
| 768 | } |
| 769 | |
| 770 | static int ovl_unlink(struct inode *dir, struct dentry *dentry) |
| 771 | { |
| 772 | return ovl_do_remove(dentry, false); |
| 773 | } |
| 774 | |
| 775 | static int ovl_rmdir(struct inode *dir, struct dentry *dentry) |
| 776 | { |
| 777 | return ovl_do_remove(dentry, true); |
| 778 | } |
| 779 | |
Miklos Szeredi | 370e55a | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 780 | static bool ovl_type_merge_or_lower(struct dentry *dentry) |
| 781 | { |
| 782 | enum ovl_path_type type = ovl_path_type(dentry); |
| 783 | |
| 784 | return OVL_TYPE_MERGE(type) || !OVL_TYPE_UPPER(type); |
| 785 | } |
| 786 | |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 787 | static bool ovl_can_move(struct dentry *dentry) |
| 788 | { |
| 789 | return ovl_redirect_dir(dentry->d_sb) || |
| 790 | !d_is_dir(dentry) || !ovl_type_merge_or_lower(dentry); |
| 791 | } |
| 792 | |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 793 | static char *ovl_get_redirect(struct dentry *dentry, bool samedir) |
| 794 | { |
| 795 | char *buf, *ret; |
| 796 | struct dentry *d, *tmp; |
Miklos Szeredi | 3ea22a7 | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 797 | int buflen = ovl_redirect_max + 1; |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 798 | |
| 799 | if (samedir) { |
| 800 | ret = kstrndup(dentry->d_name.name, dentry->d_name.len, |
| 801 | GFP_KERNEL); |
| 802 | goto out; |
| 803 | } |
| 804 | |
| 805 | buf = ret = kmalloc(buflen, GFP_TEMPORARY); |
| 806 | if (!buf) |
| 807 | goto out; |
| 808 | |
| 809 | buflen--; |
| 810 | buf[buflen] = '\0'; |
| 811 | for (d = dget(dentry); !IS_ROOT(d);) { |
| 812 | const char *name; |
| 813 | int thislen; |
| 814 | |
| 815 | spin_lock(&d->d_lock); |
| 816 | name = ovl_dentry_get_redirect(d); |
| 817 | if (name) { |
| 818 | thislen = strlen(name); |
| 819 | } else { |
| 820 | name = d->d_name.name; |
| 821 | thislen = d->d_name.len; |
| 822 | } |
| 823 | |
| 824 | /* If path is too long, fall back to userspace move */ |
| 825 | if (thislen + (name[0] != '/') > buflen) { |
| 826 | ret = ERR_PTR(-EXDEV); |
| 827 | spin_unlock(&d->d_lock); |
| 828 | goto out_put; |
| 829 | } |
| 830 | |
| 831 | buflen -= thislen; |
| 832 | memcpy(&buf[buflen], name, thislen); |
| 833 | tmp = dget_dlock(d->d_parent); |
| 834 | spin_unlock(&d->d_lock); |
| 835 | |
| 836 | dput(d); |
| 837 | d = tmp; |
| 838 | |
| 839 | /* Absolute redirect: finished */ |
| 840 | if (buf[buflen] == '/') |
| 841 | break; |
| 842 | buflen--; |
| 843 | buf[buflen] = '/'; |
| 844 | } |
| 845 | ret = kstrdup(&buf[buflen], GFP_KERNEL); |
| 846 | out_put: |
| 847 | dput(d); |
| 848 | kfree(buf); |
| 849 | out: |
| 850 | return ret ? ret : ERR_PTR(-ENOMEM); |
| 851 | } |
| 852 | |
| 853 | static int ovl_set_redirect(struct dentry *dentry, bool samedir) |
| 854 | { |
| 855 | int err; |
| 856 | const char *redirect = ovl_dentry_get_redirect(dentry); |
| 857 | |
| 858 | if (redirect && (samedir || redirect[0] == '/')) |
| 859 | return 0; |
| 860 | |
| 861 | redirect = ovl_get_redirect(dentry, samedir); |
| 862 | if (IS_ERR(redirect)) |
| 863 | return PTR_ERR(redirect); |
| 864 | |
Amir Goldstein | 21a2287 | 2017-05-17 00:12:41 +0300 | [diff] [blame] | 865 | err = ovl_check_setxattr(dentry, ovl_dentry_upper(dentry), |
| 866 | OVL_XATTR_REDIRECT, |
| 867 | redirect, strlen(redirect), -EXDEV); |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 868 | if (!err) { |
| 869 | spin_lock(&dentry->d_lock); |
| 870 | ovl_dentry_set_redirect(dentry, redirect); |
| 871 | spin_unlock(&dentry->d_lock); |
| 872 | } else { |
| 873 | kfree(redirect); |
Amir Goldstein | 21a2287 | 2017-05-17 00:12:41 +0300 | [diff] [blame] | 874 | pr_warn_ratelimited("overlay: failed to set redirect (%i)\n", err); |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 875 | /* Fall back to userspace copy-up */ |
| 876 | err = -EXDEV; |
| 877 | } |
| 878 | return err; |
| 879 | } |
| 880 | |
Miklos Szeredi | 6c02cb5 | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 881 | static int ovl_rename(struct inode *olddir, struct dentry *old, |
| 882 | struct inode *newdir, struct dentry *new, |
| 883 | unsigned int flags) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 884 | { |
| 885 | int err; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 886 | struct dentry *old_upperdir; |
| 887 | struct dentry *new_upperdir; |
| 888 | struct dentry *olddentry; |
| 889 | struct dentry *newdentry; |
| 890 | struct dentry *trap; |
| 891 | bool old_opaque; |
| 892 | bool new_opaque; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 893 | bool cleanup_whiteout = false; |
| 894 | bool overwrite = !(flags & RENAME_EXCHANGE); |
David Howells | e36cb0b | 2015-01-29 12:02:35 +0000 | [diff] [blame] | 895 | bool is_dir = d_is_dir(old); |
Miklos Szeredi | 370e55a | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 896 | bool new_is_dir = d_is_dir(new); |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 897 | bool samedir = olddir == newdir; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 898 | struct dentry *opaquedir = NULL; |
| 899 | const struct cred *old_cred = NULL; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 900 | |
| 901 | err = -EINVAL; |
| 902 | if (flags & ~(RENAME_EXCHANGE | RENAME_NOREPLACE)) |
| 903 | goto out; |
| 904 | |
| 905 | flags &= ~RENAME_NOREPLACE; |
| 906 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 907 | /* Don't copy up directory trees */ |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 908 | err = -EXDEV; |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 909 | if (!ovl_can_move(old)) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 910 | goto out; |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 911 | if (!overwrite && !ovl_can_move(new)) |
Miklos Szeredi | 370e55a | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 912 | goto out; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 913 | |
| 914 | err = ovl_want_write(old); |
| 915 | if (err) |
| 916 | goto out; |
| 917 | |
| 918 | err = ovl_copy_up(old); |
| 919 | if (err) |
| 920 | goto out_drop_write; |
| 921 | |
| 922 | err = ovl_copy_up(new->d_parent); |
| 923 | if (err) |
| 924 | goto out_drop_write; |
| 925 | if (!overwrite) { |
| 926 | err = ovl_copy_up(new); |
| 927 | if (err) |
| 928 | goto out_drop_write; |
| 929 | } |
| 930 | |
Vivek Goyal | 1175b6b | 2016-07-01 16:34:28 -0400 | [diff] [blame] | 931 | old_cred = ovl_override_creds(old->d_sb); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 932 | |
Miklos Szeredi | 370e55a | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 933 | if (overwrite && new_is_dir && ovl_type_merge_or_lower(new)) { |
Miklos Szeredi | a105d68 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 934 | opaquedir = ovl_check_empty_and_clear(new); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 935 | err = PTR_ERR(opaquedir); |
| 936 | if (IS_ERR(opaquedir)) { |
| 937 | opaquedir = NULL; |
| 938 | goto out_revert_creds; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | if (overwrite) { |
Miklos Szeredi | 2aff453 | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 943 | if (ovl_lower_positive(old)) { |
Miklos Szeredi | c412ce4 | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 944 | if (!ovl_dentry_is_whiteout(new)) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 945 | /* Whiteout source */ |
| 946 | flags |= RENAME_WHITEOUT; |
| 947 | } else { |
| 948 | /* Switch whiteouts */ |
| 949 | flags |= RENAME_EXCHANGE; |
| 950 | } |
Miklos Szeredi | c412ce4 | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 951 | } else if (is_dir && ovl_dentry_is_whiteout(new)) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 952 | flags |= RENAME_EXCHANGE; |
| 953 | cleanup_whiteout = true; |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | old_upperdir = ovl_dentry_upper(old->d_parent); |
| 958 | new_upperdir = ovl_dentry_upper(new->d_parent); |
| 959 | |
Amir Goldstein | ee1d6d37 | 2017-05-11 16:42:26 +0300 | [diff] [blame] | 960 | if (!samedir) { |
| 961 | /* |
| 962 | * When moving a merge dir or non-dir with copy up origin into |
Amir Goldstein | f3a1568 | 2017-05-24 15:29:33 +0300 | [diff] [blame^] | 963 | * a new parent, we are marking the new parent dir "impure". |
| 964 | * When ovl_iterate() iterates an "impure" upper dir, it will |
| 965 | * lookup the origin inodes of the entries to fill d_ino. |
Amir Goldstein | ee1d6d37 | 2017-05-11 16:42:26 +0300 | [diff] [blame] | 966 | */ |
Amir Goldstein | f3a1568 | 2017-05-24 15:29:33 +0300 | [diff] [blame^] | 967 | if (ovl_type_origin(old)) { |
Amir Goldstein | ee1d6d37 | 2017-05-11 16:42:26 +0300 | [diff] [blame] | 968 | err = ovl_set_impure(new->d_parent, new_upperdir); |
| 969 | if (err) |
| 970 | goto out_revert_creds; |
| 971 | } |
Amir Goldstein | f3a1568 | 2017-05-24 15:29:33 +0300 | [diff] [blame^] | 972 | if (!overwrite && ovl_type_origin(new)) { |
Amir Goldstein | ee1d6d37 | 2017-05-11 16:42:26 +0300 | [diff] [blame] | 973 | err = ovl_set_impure(old->d_parent, old_upperdir); |
| 974 | if (err) |
| 975 | goto out_revert_creds; |
| 976 | } |
| 977 | } |
| 978 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 979 | trap = lock_rename(new_upperdir, old_upperdir); |
| 980 | |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 981 | olddentry = lookup_one_len(old->d_name.name, old_upperdir, |
| 982 | old->d_name.len); |
| 983 | err = PTR_ERR(olddentry); |
| 984 | if (IS_ERR(olddentry)) |
| 985 | goto out_unlock; |
| 986 | |
| 987 | err = -ESTALE; |
| 988 | if (olddentry != ovl_dentry_upper(old)) |
| 989 | goto out_dput_old; |
| 990 | |
| 991 | newdentry = lookup_one_len(new->d_name.name, new_upperdir, |
| 992 | new->d_name.len); |
| 993 | err = PTR_ERR(newdentry); |
| 994 | if (IS_ERR(newdentry)) |
| 995 | goto out_dput_old; |
| 996 | |
Miklos Szeredi | 3ee23ff | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 997 | old_opaque = ovl_dentry_is_opaque(old); |
| 998 | new_opaque = ovl_dentry_is_opaque(new); |
| 999 | |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 1000 | err = -ESTALE; |
| 1001 | if (ovl_dentry_upper(new)) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1002 | if (opaquedir) { |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 1003 | if (newdentry != opaquedir) |
| 1004 | goto out_dput; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1005 | } else { |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 1006 | if (newdentry != ovl_dentry_upper(new)) |
| 1007 | goto out_dput; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1008 | } |
| 1009 | } else { |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 1010 | if (!d_is_negative(newdentry) && |
| 1011 | (!new_opaque || !ovl_is_whiteout(newdentry))) |
| 1012 | goto out_dput; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1013 | } |
| 1014 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1015 | if (olddentry == trap) |
| 1016 | goto out_dput; |
| 1017 | if (newdentry == trap) |
| 1018 | goto out_dput; |
| 1019 | |
Miklos Szeredi | 804032f | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 1020 | if (WARN_ON(olddentry->d_inode == newdentry->d_inode)) |
| 1021 | goto out_dput; |
| 1022 | |
Miklos Szeredi | 5cf5b47 | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 1023 | err = 0; |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 1024 | if (is_dir) { |
Miklos Szeredi | 5cf5b47 | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 1025 | if (ovl_type_merge_or_lower(old)) |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 1026 | err = ovl_set_redirect(old, samedir); |
Amir Goldstein | 97c684c | 2016-11-21 18:57:34 +0200 | [diff] [blame] | 1027 | else if (!old_opaque && ovl_type_merge(new->d_parent)) |
Amir Goldstein | 21a2287 | 2017-05-17 00:12:41 +0300 | [diff] [blame] | 1028 | err = ovl_set_opaque_xerr(old, olddentry, -EXDEV); |
Miklos Szeredi | 5cf5b47 | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 1029 | if (err) |
| 1030 | goto out_dput; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1031 | } |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 1032 | if (!overwrite && new_is_dir) { |
Miklos Szeredi | 5cf5b47 | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 1033 | if (ovl_type_merge_or_lower(new)) |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 1034 | err = ovl_set_redirect(new, samedir); |
Amir Goldstein | 97c684c | 2016-11-21 18:57:34 +0200 | [diff] [blame] | 1035 | else if (!new_opaque && ovl_type_merge(old->d_parent)) |
Amir Goldstein | 21a2287 | 2017-05-17 00:12:41 +0300 | [diff] [blame] | 1036 | err = ovl_set_opaque_xerr(new, newdentry, -EXDEV); |
Miklos Szeredi | 5cf5b47 | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 1037 | if (err) |
| 1038 | goto out_dput; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1039 | } |
| 1040 | |
Miklos Szeredi | 3ee23ff | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 1041 | err = ovl_do_rename(old_upperdir->d_inode, olddentry, |
| 1042 | new_upperdir->d_inode, newdentry, flags); |
| 1043 | if (err) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1044 | goto out_dput; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1045 | |
| 1046 | if (cleanup_whiteout) |
| 1047 | ovl_cleanup(old_upperdir->d_inode, newdentry); |
| 1048 | |
| 1049 | ovl_dentry_version_inc(old->d_parent); |
| 1050 | ovl_dentry_version_inc(new->d_parent); |
| 1051 | |
| 1052 | out_dput: |
| 1053 | dput(newdentry); |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 1054 | out_dput_old: |
| 1055 | dput(olddentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1056 | out_unlock: |
| 1057 | unlock_rename(new_upperdir, old_upperdir); |
| 1058 | out_revert_creds: |
Vivek Goyal | 1175b6b | 2016-07-01 16:34:28 -0400 | [diff] [blame] | 1059 | revert_creds(old_cred); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1060 | out_drop_write: |
| 1061 | ovl_drop_write(old); |
| 1062 | out: |
| 1063 | dput(opaquedir); |
| 1064 | return err; |
| 1065 | } |
| 1066 | |
| 1067 | const struct inode_operations ovl_dir_inode_operations = { |
| 1068 | .lookup = ovl_lookup, |
| 1069 | .mkdir = ovl_mkdir, |
| 1070 | .symlink = ovl_symlink, |
| 1071 | .unlink = ovl_unlink, |
| 1072 | .rmdir = ovl_rmdir, |
Miklos Szeredi | 6c02cb5 | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 1073 | .rename = ovl_rename, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1074 | .link = ovl_link, |
| 1075 | .setattr = ovl_setattr, |
| 1076 | .create = ovl_create, |
| 1077 | .mknod = ovl_mknod, |
| 1078 | .permission = ovl_permission, |
Miklos Szeredi | 5b71209 | 2017-05-05 11:38:58 +0200 | [diff] [blame] | 1079 | .getattr = ovl_getattr, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1080 | .listxattr = ovl_listxattr, |
Vivek Goyal | 39a25b2 | 2016-07-01 16:34:26 -0400 | [diff] [blame] | 1081 | .get_acl = ovl_get_acl, |
Miklos Szeredi | d719e8f | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 1082 | .update_time = ovl_update_time, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1083 | }; |