1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * 4 * Copyright (C) 2011 Novell Inc. 5 */ 6 7 #include <linux/fs.h> 8 #include <linux/slab.h> 9 #include <linux/cred.h> 10 #include <linux/xattr.h> 11 #include <linux/ratelimit.h> 12 #include <linux/fiemap.h> 13 #include <linux/fileattr.h> 14 #include <linux/security.h> 15 #include <linux/namei.h> 16 #include <linux/posix_acl.h> 17 #include <linux/posix_acl_xattr.h> 18 #include "overlayfs.h" 19 20 21 int ovl_setattr(const struct mnt_idmap *idmap, struct dentry *dentry, 22 struct iattr *attr) 23 { 24 int err; 25 struct ovl_fs *ofs = OVL_FS(dentry->d_sb); 26 bool full_copy_up = false; 27 struct dentry *upperdentry; 28 29 err = setattr_prepare(idmap, dentry, attr); 30 if (err) 31 return err; 32 33 /* Rebase ownership from the mount idmap into overlay id space. */ 34 if (attr->ia_valid & ATTR_UID) 35 attr->ia_vfsuid = VFSUIDT_INIT(from_vfsuid(idmap, 36 i_user_ns(d_inode(dentry)), attr->ia_vfsuid)); 37 if (attr->ia_valid & ATTR_GID) 38 attr->ia_vfsgid = VFSGIDT_INIT(from_vfsgid(idmap, 39 i_user_ns(d_inode(dentry)), attr->ia_vfsgid)); 40 41 if (attr->ia_valid & ATTR_SIZE) { 42 /* Truncate should trigger data copy up as well */ 43 full_copy_up = true; 44 } 45 46 if (!full_copy_up) 47 err = ovl_copy_up(dentry); 48 else 49 err = ovl_copy_up_with_data(dentry); 50 if (!err) { 51 struct inode *winode = NULL; 52 53 upperdentry = ovl_dentry_upper(dentry); 54 55 if (attr->ia_valid & ATTR_SIZE) { 56 winode = d_inode(upperdentry); 57 err = get_write_access(winode); 58 if (err) 59 goto out; 60 } 61 62 if (attr->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID)) 63 attr->ia_valid &= ~ATTR_MODE; 64 65 /* 66 * We might have to translate ovl file into real file object 67 * once use cases emerge. For now, simply don't let underlying 68 * filesystem rely on attr->ia_file 69 */ 70 attr->ia_valid &= ~ATTR_FILE; 71 72 /* 73 * If open(O_TRUNC) is done, VFS calls ->setattr with ATTR_OPEN 74 * set. Overlayfs does not pass O_TRUNC flag to underlying 75 * filesystem during open -> do not pass ATTR_OPEN. This 76 * disables optimization in fuse which assumes open(O_TRUNC) 77 * already set file size to 0. But we never passed O_TRUNC to 78 * fuse. So by clearing ATTR_OPEN, fuse will be forced to send 79 * setattr request to server. 80 */ 81 attr->ia_valid &= ~ATTR_OPEN; 82 83 err = ovl_want_write(dentry); 84 if (err) 85 goto out_put_write; 86 87 inode_lock(upperdentry->d_inode); 88 with_ovl_creds(dentry->d_sb) 89 err = ovl_do_notify_change(ofs, upperdentry, attr); 90 if (!err) 91 ovl_copyattr(dentry->d_inode); 92 inode_unlock(upperdentry->d_inode); 93 ovl_drop_write(dentry); 94 95 out_put_write: 96 if (winode) 97 put_write_access(winode); 98 } 99 out: 100 return err; 101 } 102 103 static void ovl_map_dev_ino(struct dentry *dentry, struct kstat *stat, int fsid) 104 { 105 struct ovl_fs *ofs = OVL_FS(dentry->d_sb); 106 bool samefs = ovl_same_fs(ofs); 107 unsigned int xinobits = ovl_xino_bits(ofs); 108 unsigned int xinoshift = 64 - xinobits; 109 110 if (samefs) { 111 /* 112 * When all layers are on the same fs, all real inode 113 * number are unique, so we use the overlay st_dev, 114 * which is friendly to du -x. 115 */ 116 stat->dev = dentry->d_sb->s_dev; 117 return; 118 } else if (xinobits) { 119 /* 120 * All inode numbers of underlying fs should not be using the 121 * high xinobits, so we use high xinobits to partition the 122 * overlay st_ino address space. The high bits holds the fsid 123 * (upper fsid is 0). The lowest xinobit is reserved for mapping 124 * the non-persistent inode numbers range in case of overflow. 125 * This way all overlay inode numbers are unique and use the 126 * overlay st_dev. 127 */ 128 if (likely(!(stat->ino >> xinoshift))) { 129 stat->ino |= ((u64)fsid) << (xinoshift + 1); 130 stat->dev = dentry->d_sb->s_dev; 131 return; 132 } else if (ovl_xino_warn(ofs)) { 133 pr_warn_ratelimited("inode number too big (%pd2, ino=%llu, xinobits=%d)\n", 134 dentry, stat->ino, xinobits); 135 } 136 } 137 138 /* The inode could not be mapped to a unified st_ino address space */ 139 if (S_ISDIR(dentry->d_inode->i_mode)) { 140 /* 141 * Always use the overlay st_dev for directories, so 'find 142 * -xdev' will scan the entire overlay mount and won't cross the 143 * overlay mount boundaries. 144 * 145 * If not all layers are on the same fs the pair {real st_ino; 146 * overlay st_dev} is not unique, so use the non persistent 147 * overlay st_ino for directories. 148 */ 149 stat->dev = dentry->d_sb->s_dev; 150 stat->ino = dentry->d_inode->i_ino; 151 } else { 152 /* 153 * For non-samefs setup, if we cannot map all layers st_ino 154 * to a unified address space, we need to make sure that st_dev 155 * is unique per underlying fs, so we use the unique anonymous 156 * bdev assigned to the underlying fs. 157 */ 158 stat->dev = ofs->fs[fsid].pseudo_dev; 159 } 160 } 161 162 static inline int ovl_real_getattr_nosec(struct super_block *sb, 163 const struct path *path, 164 struct kstat *stat, u32 request_mask, 165 unsigned int flags) 166 { 167 with_ovl_creds(sb) 168 return vfs_getattr_nosec(path, stat, request_mask, flags); 169 } 170 171 int ovl_getattr(const struct mnt_idmap *idmap, const struct path *path, 172 struct kstat *stat, u32 request_mask, unsigned int flags) 173 { 174 struct dentry *dentry = path->dentry; 175 struct super_block *sb = dentry->d_sb; 176 enum ovl_path_type type; 177 struct path realpath; 178 struct inode *inode = d_inode(dentry); 179 bool is_dir = S_ISDIR(inode->i_mode); 180 int fsid = 0; 181 int err; 182 bool metacopy_blocks = false; 183 vfsuid_t vfsuid; 184 vfsgid_t vfsgid; 185 186 metacopy_blocks = ovl_is_metacopy_dentry(dentry); 187 188 type = ovl_path_real(dentry, &realpath); 189 err = ovl_real_getattr_nosec(sb, &realpath, stat, request_mask, flags); 190 if (err) 191 return err; 192 193 /* Report the effective immutable/append-only STATX flags */ 194 generic_fill_statx_attr(inode, stat); 195 196 /* 197 * For non-dir or same fs, we use st_ino of the copy up origin. 198 * This guaranties constant st_dev/st_ino across copy up. 199 * With xino feature and non-samefs, we use st_ino of the copy up 200 * origin masked with high bits that represent the layer id. 201 * 202 * If lower filesystem supports NFS file handles, this also guaranties 203 * persistent st_ino across mount cycle. 204 */ 205 if (!is_dir || ovl_same_dev(OVL_FS(dentry->d_sb))) { 206 if (!OVL_TYPE_UPPER(type)) { 207 fsid = ovl_layer_lower(dentry)->fsid; 208 } else if (OVL_TYPE_ORIGIN(type)) { 209 struct kstat lowerstat; 210 u32 lowermask = STATX_INO | STATX_BLOCKS | 211 (!is_dir ? STATX_NLINK : 0); 212 213 ovl_path_lower(dentry, &realpath); 214 err = ovl_real_getattr_nosec(sb, &realpath, &lowerstat, lowermask, flags); 215 if (err) 216 return err; 217 218 /* 219 * Lower hardlinks may be broken on copy up to different 220 * upper files, so we cannot use the lower origin st_ino 221 * for those different files, even for the same fs case. 222 * 223 * Similarly, several redirected dirs can point to the 224 * same dir on a lower layer. With the "verify_lower" 225 * feature, we do not use the lower origin st_ino, if 226 * we haven't verified that this redirect is unique. 227 * 228 * With inodes index enabled, it is safe to use st_ino 229 * of an indexed origin. The index validates that the 230 * upper hardlink is not broken and that a redirected 231 * dir is the only redirect to that origin. 232 */ 233 if (ovl_test_flag(OVL_INDEX, d_inode(dentry)) || 234 (!ovl_verify_lower(dentry->d_sb) && 235 (is_dir || lowerstat.nlink == 1))) { 236 fsid = ovl_layer_lower(dentry)->fsid; 237 stat->ino = lowerstat.ino; 238 } 239 240 /* 241 * If we are querying a metacopy dentry and lower 242 * dentry is data dentry, then use the blocks we 243 * queried just now. We don't have to do additional 244 * vfs_getattr(). If lower itself is metacopy, then 245 * additional vfs_getattr() is unavoidable. 246 */ 247 if (metacopy_blocks && 248 realpath.dentry == ovl_dentry_lowerdata(dentry)) { 249 stat->blocks = lowerstat.blocks; 250 metacopy_blocks = false; 251 } 252 } 253 254 if (metacopy_blocks) { 255 /* 256 * If lower is not same as lowerdata or if there was 257 * no origin on upper, we can end up here. 258 * With lazy lowerdata lookup, guess lowerdata blocks 259 * from size to avoid lowerdata lookup on stat(2). 260 */ 261 struct kstat lowerdatastat; 262 u32 lowermask = STATX_BLOCKS; 263 264 ovl_path_lowerdata(dentry, &realpath); 265 if (realpath.dentry) { 266 err = ovl_real_getattr_nosec(sb, &realpath, &lowerdatastat, 267 lowermask, flags); 268 if (err) 269 return err; 270 } else { 271 lowerdatastat.blocks = 272 round_up(stat->size, stat->blksize) >> 9; 273 } 274 stat->blocks = lowerdatastat.blocks; 275 } 276 } 277 278 ovl_map_dev_ino(dentry, stat, fsid); 279 280 /* 281 * It's probably not worth it to count subdirs to get the 282 * correct link count. nlink=1 seems to pacify 'find' and 283 * other utilities. 284 */ 285 if (is_dir && OVL_TYPE_MERGE(type)) 286 stat->nlink = 1; 287 288 /* 289 * Return the overlay inode nlinks for indexed upper inodes. 290 * Overlay inode nlink counts the union of the upper hardlinks 291 * and non-covered lower hardlinks. It does not include the upper 292 * index hardlink. 293 */ 294 if (!is_dir && ovl_test_flag(OVL_INDEX, d_inode(dentry))) 295 stat->nlink = dentry->d_inode->i_nlink; 296 297 /* Map ownership of the real inode through the overlay mount idmap. */ 298 vfsuid = make_vfsuid(idmap, i_user_ns(inode), stat->uid); 299 vfsgid = make_vfsgid(idmap, i_user_ns(inode), stat->gid); 300 stat->uid = vfsuid_into_kuid(vfsuid); 301 stat->gid = vfsgid_into_kgid(vfsgid); 302 303 return err; 304 } 305 306 int ovl_permission(const struct mnt_idmap *idmap, 307 struct inode *inode, int mask) 308 { 309 struct inode *upperinode = ovl_inode_upper(inode); 310 struct inode *realinode; 311 struct path realpath; 312 int err; 313 314 /* Careful in RCU walk mode */ 315 realinode = ovl_i_path_real(inode, &realpath); 316 if (!realinode) { 317 WARN_ON(!(mask & MAY_NOT_BLOCK)); 318 return -ECHILD; 319 } 320 321 /* 322 * Check overlay inode with the creds of task and underlying inode 323 * with creds of mounter 324 */ 325 err = generic_permission(idmap, inode, mask); 326 if (err) 327 return err; 328 329 if (!upperinode && 330 !special_file(realinode->i_mode) && mask & MAY_WRITE) { 331 mask &= ~(MAY_WRITE | MAY_APPEND); 332 /* Make sure mounter can read file for copy up later */ 333 mask |= MAY_READ; 334 } 335 336 with_ovl_creds(inode->i_sb) 337 return inode_permission(mnt_idmap(realpath.mnt), realinode, mask); 338 } 339 340 static const char *ovl_get_link(struct dentry *dentry, 341 struct inode *inode, 342 struct delayed_call *done) 343 { 344 if (!dentry) 345 return ERR_PTR(-ECHILD); 346 347 with_ovl_creds(dentry->d_sb) 348 return vfs_get_link(ovl_dentry_real(dentry), done); 349 } 350 351 #ifdef CONFIG_FS_POSIX_ACL 352 /* 353 * Apply the idmapping of the layer to POSIX ACLs. The caller must pass a clone 354 * of the POSIX ACLs retrieved from the lower layer to this function to not 355 * alter the POSIX ACLs for the underlying filesystem. 356 */ 357 static void ovl_idmap_posix_acl(const struct inode *realinode, 358 const struct mnt_idmap *idmap, 359 struct posix_acl *acl) 360 { 361 struct user_namespace *fs_userns = i_user_ns(realinode); 362 363 for (unsigned int i = 0; i < acl->a_count; i++) { 364 vfsuid_t vfsuid; 365 vfsgid_t vfsgid; 366 367 struct posix_acl_entry *e = &acl->a_entries[i]; 368 switch (e->e_tag) { 369 case ACL_USER: 370 vfsuid = make_vfsuid(idmap, fs_userns, e->e_uid); 371 e->e_uid = vfsuid_into_kuid(vfsuid); 372 break; 373 case ACL_GROUP: 374 vfsgid = make_vfsgid(idmap, fs_userns, e->e_gid); 375 e->e_gid = vfsgid_into_kgid(vfsgid); 376 break; 377 } 378 } 379 } 380 381 /* 382 * The @noperm argument is used to skip permission checking and is a temporary 383 * measure. Quoting Miklos from an earlier discussion: 384 * 385 * > So there are two paths to getting an acl: 386 * > 1) permission checking and 2) retrieving the value via getxattr(2). 387 * > This is a similar situation as reading a symlink vs. following it. 388 * > When following a symlink overlayfs always reads the link on the 389 * > underlying fs just as if it was a readlink(2) call, calling 390 * > security_inode_readlink() instead of security_inode_follow_link(). 391 * > This is logical: we are reading the link from the underlying storage, 392 * > and following it on overlayfs. 393 * > 394 * > Applying the same logic to acl: we do need to call the 395 * > security_inode_getxattr() on the underlying fs, even if just want to 396 * > check permissions on overlay. This is currently not done, which is an 397 * > inconsistency. 398 * > 399 * > Maybe adding the check to ovl_get_acl() is the right way to go, but 400 * > I'm a little afraid of a performance regression. Will look into that. 401 * 402 * Until we have made a decision allow this helper to take the @noperm 403 * argument. We should hopefully be able to remove it soon. 404 */ 405 struct posix_acl *ovl_get_acl_path(const struct path *path, 406 const char *acl_name, bool noperm) 407 { 408 struct posix_acl *real_acl, *clone; 409 const struct mnt_idmap *idmap; 410 struct inode *realinode = d_inode(path->dentry); 411 412 idmap = mnt_idmap(path->mnt); 413 414 if (noperm) 415 real_acl = get_inode_acl(realinode, posix_acl_type(acl_name)); 416 else 417 real_acl = vfs_get_acl(idmap, path->dentry, acl_name); 418 if (IS_ERR_OR_NULL(real_acl)) 419 return real_acl; 420 421 if (!is_idmapped_mnt(path->mnt)) 422 return real_acl; 423 424 /* 425 * We cannot alter the ACLs returned from the relevant layer as that 426 * would alter the cached values filesystem wide for the lower 427 * filesystem. Instead we can clone the ACLs and then apply the 428 * relevant idmapping of the layer. 429 */ 430 clone = posix_acl_clone(real_acl, GFP_KERNEL); 431 posix_acl_release(real_acl); /* release original acl */ 432 if (!clone) 433 return ERR_PTR(-ENOMEM); 434 435 ovl_idmap_posix_acl(realinode, idmap, clone); 436 return clone; 437 } 438 439 /* 440 * When the relevant layer is an idmapped mount we need to take the idmapping 441 * of the layer into account and translate any ACL_{GROUP,USER} values 442 * according to the idmapped mount. 443 * 444 * We cannot alter the ACLs returned from the relevant layer as that would 445 * alter the cached values filesystem wide for the lower filesystem. Instead we 446 * can clone the ACLs and then apply the relevant idmapping of the layer. 447 * 448 * This is obviously only relevant when idmapped layers are used. 449 */ 450 struct posix_acl *do_ovl_get_acl(const struct mnt_idmap *idmap, 451 struct inode *inode, int type, 452 bool rcu, bool noperm) 453 { 454 struct inode *realinode; 455 struct posix_acl *acl; 456 struct path realpath; 457 458 /* Careful in RCU walk mode */ 459 realinode = ovl_i_path_real(inode, &realpath); 460 if (!realinode) { 461 WARN_ON(!rcu); 462 return ERR_PTR(-ECHILD); 463 } 464 465 if (!IS_POSIXACL(realinode)) 466 return NULL; 467 468 if (rcu) { 469 /* 470 * If the layer is idmapped drop out of RCU path walk 471 * so we can clone the ACLs. 472 */ 473 if (is_idmapped_mnt(realpath.mnt)) 474 return ERR_PTR(-ECHILD); 475 476 acl = get_cached_acl_rcu(realinode, type); 477 } else { 478 with_ovl_creds(inode->i_sb) 479 acl = ovl_get_acl_path(&realpath, posix_acl_xattr_name(type), noperm); 480 } 481 482 return acl; 483 } 484 485 static int ovl_set_or_remove_acl(struct dentry *dentry, struct inode *inode, 486 struct posix_acl *acl, int type) 487 { 488 int err; 489 struct path realpath; 490 const char *acl_name; 491 struct ovl_fs *ofs = OVL_FS(dentry->d_sb); 492 struct dentry *upperdentry = ovl_dentry_upper(dentry); 493 struct dentry *realdentry = upperdentry ?: ovl_dentry_lower(dentry); 494 495 /* 496 * If ACL is to be removed from a lower file, check if it exists in 497 * the first place before copying it up. 498 */ 499 acl_name = posix_acl_xattr_name(type); 500 if (!acl && !upperdentry) { 501 struct posix_acl *real_acl; 502 503 ovl_path_lower(dentry, &realpath); 504 with_ovl_creds(dentry->d_sb) 505 real_acl = vfs_get_acl(mnt_idmap(realpath.mnt), realdentry, acl_name); 506 if (IS_ERR(real_acl)) { 507 err = PTR_ERR(real_acl); 508 goto out; 509 } 510 posix_acl_release(real_acl); 511 } 512 513 if (!upperdentry) { 514 err = ovl_copy_up(dentry); 515 if (err) 516 goto out; 517 518 realdentry = ovl_dentry_upper(dentry); 519 } 520 521 err = ovl_want_write(dentry); 522 if (err) 523 goto out; 524 525 with_ovl_creds(dentry->d_sb) { 526 if (acl) 527 err = ovl_do_set_acl(ofs, realdentry, acl_name, acl); 528 else 529 err = ovl_do_remove_acl(ofs, realdentry, acl_name); 530 } 531 ovl_drop_write(dentry); 532 533 /* copy c/mtime */ 534 ovl_copyattr(inode); 535 out: 536 return err; 537 } 538 539 int ovl_set_acl(const struct mnt_idmap *idmap, struct dentry *dentry, 540 struct posix_acl *acl, int type) 541 { 542 int err; 543 struct inode *inode = d_inode(dentry); 544 struct dentry *workdir = ovl_workdir(dentry); 545 struct inode *realinode = ovl_inode_real(inode); 546 547 if (!IS_POSIXACL(d_inode(workdir))) 548 return -EOPNOTSUPP; 549 if (!realinode->i_op->set_acl) 550 return -EOPNOTSUPP; 551 if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode)) 552 return acl ? -EACCES : 0; 553 if (!inode_owner_or_capable(idmap, inode)) 554 return -EPERM; 555 556 /* 557 * Check if sgid bit needs to be cleared (actual setacl operation will 558 * be done with mounter's capabilities and so that won't do it for us). 559 */ 560 if (unlikely(inode->i_mode & S_ISGID) && type == ACL_TYPE_ACCESS && 561 !in_group_or_capable(idmap, inode, 562 i_gid_into_vfsgid(idmap, inode))) { 563 struct iattr iattr = { .ia_valid = ATTR_KILL_SGID }; 564 565 err = ovl_setattr(&nop_mnt_idmap, dentry, &iattr); 566 if (err) 567 return err; 568 } 569 570 return ovl_set_or_remove_acl(dentry, inode, acl, type); 571 } 572 #endif 573 574 int ovl_update_time(struct inode *inode, enum fs_update_time type, 575 unsigned int flags) 576 { 577 if (type == FS_UPD_ATIME) { 578 struct ovl_fs *ofs = OVL_FS(inode->i_sb); 579 struct path upperpath = { 580 .mnt = ovl_upper_mnt(ofs), 581 .dentry = ovl_upperdentry_dereference(OVL_I(inode)), 582 }; 583 584 if (upperpath.dentry) { 585 if (flags & IOCB_NOWAIT) 586 return -EAGAIN; 587 touch_atime(&upperpath); 588 inode_set_atime_to_ts(inode, 589 inode_get_atime(d_inode(upperpath.dentry))); 590 } 591 } 592 return 0; 593 } 594 595 static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 596 u64 start, u64 len) 597 { 598 struct inode *realinode = ovl_inode_realdata(inode); 599 600 if (!realinode) 601 return -EIO; 602 603 if (!realinode->i_op->fiemap) 604 return -EOPNOTSUPP; 605 606 with_ovl_creds(inode->i_sb) 607 return realinode->i_op->fiemap(realinode, fieinfo, start, len); 608 } 609 610 /* 611 * Work around the fact that security_file_ioctl() takes a file argument. 612 * Introducing security_inode_fileattr_get/set() hooks would solve this issue 613 * properly. 614 */ 615 static int ovl_security_fileattr(const struct path *realpath, struct file_kattr *fa, 616 bool set) 617 { 618 struct file *file; 619 unsigned int cmd; 620 int err; 621 unsigned int flags; 622 623 flags = O_RDONLY; 624 if (force_o_largefile()) 625 flags |= O_LARGEFILE; 626 627 file = dentry_open(realpath, flags, current_cred()); 628 if (IS_ERR(file)) 629 return PTR_ERR(file); 630 631 if (set) 632 cmd = fa->fsx_valid ? FS_IOC_FSSETXATTR : FS_IOC_SETFLAGS; 633 else 634 cmd = fa->fsx_valid ? FS_IOC_FSGETXATTR : FS_IOC_GETFLAGS; 635 636 err = security_file_ioctl(file, cmd, 0); 637 fput(file); 638 639 return err; 640 } 641 642 int ovl_real_fileattr_set(const struct path *realpath, struct file_kattr *fa) 643 { 644 int err; 645 646 err = ovl_security_fileattr(realpath, fa, true); 647 if (err) 648 return err; 649 650 return vfs_fileattr_set(mnt_idmap(realpath->mnt), realpath->dentry, fa); 651 } 652 653 int ovl_fileattr_set(const struct mnt_idmap *idmap, 654 struct dentry *dentry, struct file_kattr *fa) 655 { 656 struct inode *inode = d_inode(dentry); 657 struct path upperpath; 658 unsigned int flags; 659 int err; 660 661 /* 662 * Lookup refuses a directory that does not agree with the casefold 663 * state of the mount. Only FS_IOC_SETFLAGS can ask for a change. 664 */ 665 if (S_ISDIR(inode->i_mode) && fa->flags_valid && 666 !!(fa->flags & FS_CASEFOLD_FL) != OVL_FS(inode->i_sb)->casefold) 667 return -EOPNOTSUPP; 668 669 err = ovl_copy_up(dentry); 670 if (!err) { 671 ovl_path_real(dentry, &upperpath); 672 673 err = ovl_want_write(dentry); 674 if (err) 675 goto out; 676 677 with_ovl_creds(inode->i_sb) { 678 /* 679 * Store immutable/append-only flags in xattr and clear them 680 * in upper fileattr (in case they were set by older kernel) 681 * so children of "ovl-immutable" directories lower aliases of 682 * "ovl-immutable" hardlinks could be copied up. 683 * Clear xattr when flags are cleared. 684 */ 685 err = ovl_set_protattr(inode, upperpath.dentry, fa); 686 if (!err) 687 err = ovl_real_fileattr_set(&upperpath, fa); 688 } 689 ovl_drop_write(dentry); 690 691 /* 692 * Merge real inode flags with inode flags read from 693 * overlay.protattr xattr 694 */ 695 flags = ovl_inode_real(inode)->i_flags & OVL_COPY_I_FLAGS_MASK; 696 697 BUILD_BUG_ON(OVL_PROT_I_FLAGS_MASK & ~OVL_COPY_I_FLAGS_MASK); 698 flags |= inode->i_flags & OVL_PROT_I_FLAGS_MASK; 699 inode_set_flags(inode, flags, OVL_COPY_I_FLAGS_MASK); 700 701 /* Update ctime */ 702 ovl_copyattr(inode); 703 } 704 out: 705 return err; 706 } 707 708 /* Convert inode protection flags to fileattr flags */ 709 static void ovl_fileattr_prot_flags(struct inode *inode, struct file_kattr *fa) 710 { 711 BUILD_BUG_ON(OVL_PROT_FS_FLAGS_MASK & ~FS_COMMON_FL); 712 BUILD_BUG_ON(OVL_PROT_FSX_FLAGS_MASK & ~FS_XFLAG_COMMON); 713 714 if (inode->i_flags & S_APPEND) { 715 fa->flags |= FS_APPEND_FL; 716 fa->fsx_xflags |= FS_XFLAG_APPEND; 717 } 718 if (inode->i_flags & S_IMMUTABLE) { 719 fa->flags |= FS_IMMUTABLE_FL; 720 fa->fsx_xflags |= FS_XFLAG_IMMUTABLE; 721 } 722 } 723 724 int ovl_real_fileattr_get(const struct path *realpath, struct file_kattr *fa) 725 { 726 int err; 727 728 err = ovl_security_fileattr(realpath, fa, false); 729 if (err) 730 return err; 731 732 err = vfs_fileattr_get(realpath->dentry, fa); 733 if (err == -ENOIOCTLCMD) 734 err = -ENOTTY; 735 return err; 736 } 737 738 int ovl_fileattr_get(struct dentry *dentry, struct file_kattr *fa) 739 { 740 struct inode *inode = d_inode(dentry); 741 struct path realpath; 742 int err; 743 744 ovl_path_real(dentry, &realpath); 745 746 with_ovl_creds(inode->i_sb) 747 err = ovl_real_fileattr_get(&realpath, fa); 748 ovl_fileattr_prot_flags(inode, fa); 749 750 return err; 751 } 752 753 static const struct inode_operations ovl_file_inode_operations = { 754 .setattr = ovl_setattr, 755 .permission = ovl_permission, 756 .getattr = ovl_getattr, 757 .listxattr = ovl_listxattr, 758 .get_inode_acl = ovl_get_inode_acl, 759 .get_acl = ovl_get_acl, 760 .set_acl = ovl_set_acl, 761 .update_time = ovl_update_time, 762 .fiemap = ovl_fiemap, 763 .fileattr_get = ovl_fileattr_get, 764 .fileattr_set = ovl_fileattr_set, 765 }; 766 767 static const struct inode_operations ovl_symlink_inode_operations = { 768 .setattr = ovl_setattr, 769 .get_link = ovl_get_link, 770 .getattr = ovl_getattr, 771 .listxattr = ovl_listxattr, 772 .update_time = ovl_update_time, 773 }; 774 775 static const struct inode_operations ovl_special_inode_operations = { 776 .setattr = ovl_setattr, 777 .permission = ovl_permission, 778 .getattr = ovl_getattr, 779 .listxattr = ovl_listxattr, 780 .get_inode_acl = ovl_get_inode_acl, 781 .get_acl = ovl_get_acl, 782 .set_acl = ovl_set_acl, 783 .update_time = ovl_update_time, 784 }; 785 786 static const struct address_space_operations ovl_aops = { 787 /* For O_DIRECT dentry_open() checks f_mapping->a_ops->direct_IO */ 788 .direct_IO = noop_direct_IO, 789 }; 790 791 /* 792 * It is possible to stack overlayfs instance on top of another 793 * overlayfs instance as lower layer. We need to annotate the 794 * stackable i_mutex locks according to stack level of the super 795 * block instance. An overlayfs instance can never be in stack 796 * depth 0 (there is always a real fs below it). An overlayfs 797 * inode lock will use the lockdep annotation ovl_i_mutex_key[depth]. 798 * 799 * For example, here is a snip from /proc/lockdep_chains after 800 * dir_iterate of nested overlayfs: 801 * 802 * [...] &ovl_i_mutex_dir_key[depth] (stack_depth=2) 803 * [...] &ovl_i_mutex_dir_key[depth]#2 (stack_depth=1) 804 * [...] &type->i_mutex_dir_key (stack_depth=0) 805 * 806 * Locking order w.r.t ovl_want_write() is important for nested overlayfs. 807 * 808 * This chain is valid: 809 * - inode->i_rwsem (inode_lock[2]) 810 * - OVL_I(inode)->lock (ovl_inode_lock[2]) 811 * - upper_mnt->mnt_sb->s_writers (ovl_want_write[0]) 812 * - OVL_I(lowerinode)->lock (ovl_inode_lock[1]) 813 * 814 * And this chain is valid: 815 * - inode->i_rwsem (inode_lock[2]) 816 * - OVL_I(inode)->lock (ovl_inode_lock[2]) 817 * - lowerinode->i_rwsem (inode_lock[1]) 818 * - OVL_I(lowerinode)->lock (ovl_inode_lock[1]) 819 * 820 * But lowerinode->i_rwsem SHOULD NOT be acquired while ovl_want_write() is 821 * held, because it is in reverse order of the non-nested case using the same 822 * upper fs: 823 * - inode->i_rwsem (inode_lock[1]) 824 * - OVL_I(inode)->lock (ovl_inode_lock[1]) 825 * - upper_mnt->mnt_sb->s_writers (ovl_want_write[0]) 826 */ 827 828 static inline void ovl_lockdep_annotate_inode_mutex_key(struct inode *inode) 829 { 830 #ifdef CONFIG_LOCKDEP 831 static struct lock_class_key ovl_i_mutex_key[OVL_MAX_NESTING]; 832 static struct lock_class_key ovl_i_mutex_dir_key[OVL_MAX_NESTING]; 833 static struct lock_class_key ovl_i_lock_key[OVL_MAX_NESTING]; 834 835 int depth = inode->i_sb->s_stack_depth - 1; 836 837 if (WARN_ON_ONCE(depth < 0 || depth >= OVL_MAX_NESTING)) 838 depth = 0; 839 840 if (S_ISDIR(inode->i_mode)) 841 lockdep_set_class(&inode->i_rwsem, &ovl_i_mutex_dir_key[depth]); 842 else 843 lockdep_set_class(&inode->i_rwsem, &ovl_i_mutex_key[depth]); 844 845 lockdep_set_class(&OVL_I(inode)->lock, &ovl_i_lock_key[depth]); 846 #endif 847 } 848 849 static void ovl_next_ino(struct inode *inode) 850 { 851 struct ovl_fs *ofs = OVL_FS(inode->i_sb); 852 853 inode->i_ino = atomic_long_inc_return(&ofs->last_ino); 854 if (unlikely(!inode->i_ino)) 855 inode->i_ino = atomic_long_inc_return(&ofs->last_ino); 856 } 857 858 static void ovl_map_ino(struct inode *inode, unsigned long ino, int fsid) 859 { 860 struct ovl_fs *ofs = OVL_FS(inode->i_sb); 861 int xinobits = ovl_xino_bits(ofs); 862 unsigned int xinoshift = 64 - xinobits; 863 864 /* 865 * When d_ino is consistent with st_ino (samefs or i_ino has enough 866 * bits to encode layer), set the same value used for st_ino to i_ino, 867 * so inode number exposed via /proc/locks and a like will be 868 * consistent with d_ino and st_ino values. An i_ino value inconsistent 869 * with d_ino also causes nfsd readdirplus to fail. 870 */ 871 inode->i_ino = ino; 872 if (ovl_same_fs(ofs)) { 873 return; 874 } else if (xinobits && likely(!(ino >> xinoshift))) { 875 inode->i_ino |= (unsigned long)fsid << (xinoshift + 1); 876 return; 877 } 878 879 /* 880 * For directory inodes on non-samefs with xino disabled or xino 881 * overflow, we allocate a non-persistent inode number, to be used for 882 * resolving st_ino collisions in ovl_map_dev_ino(). 883 * 884 * To avoid ino collision with legitimate xino values from upper 885 * layer (fsid 0), use the lowest xinobit to map the non 886 * persistent inode numbers to the unified st_ino address space. 887 */ 888 if (S_ISDIR(inode->i_mode)) { 889 ovl_next_ino(inode); 890 if (xinobits) { 891 inode->i_ino &= ~0UL >> xinobits; 892 inode->i_ino |= 1UL << xinoshift; 893 } 894 } 895 } 896 897 void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip, 898 unsigned long ino, int fsid) 899 { 900 struct inode *realinode; 901 struct ovl_inode *oi = OVL_I(inode); 902 903 oi->__upperdentry = oip->upperdentry; 904 oi->oe = oip->oe; 905 oi->redirect = oip->redirect; 906 oi->lowerdata_redirect = oip->lowerdata_redirect; 907 908 realinode = ovl_inode_real(inode); 909 ovl_copyattr(inode); 910 ovl_copyflags(realinode, inode); 911 ovl_map_ino(inode, ino, fsid); 912 } 913 914 static void ovl_fill_inode(struct inode *inode, umode_t mode, dev_t rdev) 915 { 916 inode->i_mode = mode; 917 inode->i_flags |= S_NOCMTIME; 918 #ifdef CONFIG_FS_POSIX_ACL 919 inode->i_acl = inode->i_default_acl = ACL_DONT_CACHE; 920 #endif 921 922 ovl_lockdep_annotate_inode_mutex_key(inode); 923 924 switch (mode & S_IFMT) { 925 case S_IFREG: 926 inode->i_op = &ovl_file_inode_operations; 927 inode->i_fop = &ovl_file_operations; 928 inode->i_mapping->a_ops = &ovl_aops; 929 break; 930 931 case S_IFDIR: 932 inode->i_op = &ovl_dir_inode_operations; 933 inode->i_fop = &ovl_dir_operations; 934 break; 935 936 case S_IFLNK: 937 inode->i_op = &ovl_symlink_inode_operations; 938 break; 939 940 default: 941 inode->i_op = &ovl_special_inode_operations; 942 init_special_inode(inode, mode, rdev); 943 break; 944 } 945 } 946 947 /* 948 * With inodes index enabled, an overlay inode nlink counts the union of upper 949 * hardlinks and non-covered lower hardlinks. During the lifetime of a non-pure 950 * upper inode, the following nlink modifying operations can happen: 951 * 952 * 1. Lower hardlink copy up 953 * 2. Upper hardlink created, unlinked or renamed over 954 * 3. Lower hardlink whiteout or renamed over 955 * 956 * For the first, copy up case, the union nlink does not change, whether the 957 * operation succeeds or fails, but the upper inode nlink may change. 958 * Therefore, before copy up, we store the union nlink value relative to the 959 * lower inode nlink in the index inode xattr .overlay.nlink. 960 * 961 * For the second, upper hardlink case, the union nlink should be incremented 962 * or decremented IFF the operation succeeds, aligned with nlink change of the 963 * upper inode. Therefore, before link/unlink/rename, we store the union nlink 964 * value relative to the upper inode nlink in the index inode. 965 * 966 * For the last, lower cover up case, we simplify things by preceding the 967 * whiteout or cover up with copy up. This makes sure that there is an index 968 * upper inode where the nlink xattr can be stored before the copied up upper 969 * entry is unlink. 970 */ 971 #define OVL_NLINK_ADD_UPPER (1 << 0) 972 973 /* 974 * On-disk format for indexed nlink: 975 * 976 * nlink relative to the upper inode - "U[+-]NUM" 977 * nlink relative to the lower inode - "L[+-]NUM" 978 */ 979 980 static int ovl_set_nlink_common(struct dentry *dentry, 981 struct dentry *realdentry, const char *format) 982 { 983 struct inode *inode = d_inode(dentry); 984 struct inode *realinode = d_inode(realdentry); 985 char buf[13]; 986 int len; 987 988 len = snprintf(buf, sizeof(buf), format, 989 (int) (inode->i_nlink - realinode->i_nlink)); 990 991 if (WARN_ON(len >= sizeof(buf))) 992 return -EIO; 993 994 return ovl_setxattr(OVL_FS(inode->i_sb), ovl_dentry_upper(dentry), 995 OVL_XATTR_NLINK, buf, len); 996 } 997 998 int ovl_set_nlink_upper(struct dentry *dentry) 999 { 1000 return ovl_set_nlink_common(dentry, ovl_dentry_upper(dentry), "U%+i"); 1001 } 1002 1003 int ovl_set_nlink_lower(struct dentry *dentry) 1004 { 1005 return ovl_set_nlink_common(dentry, ovl_dentry_lower(dentry), "L%+i"); 1006 } 1007 1008 unsigned int ovl_get_nlink(struct ovl_fs *ofs, struct dentry *lowerdentry, 1009 struct dentry *upperdentry, bool indexed, 1010 unsigned int fallback) 1011 { 1012 int nlink_diff; 1013 int nlink; 1014 char buf[13]; 1015 int err; 1016 1017 if (!lowerdentry || !upperdentry) 1018 return fallback; 1019 1020 /* 1021 * A lower inode with one link is not indexed on copy up, unless all 1022 * files are indexed for NFS export. If the caller found an index entry, 1023 * then the xattr holds the union nlink, whatever the lower nlink is. 1024 */ 1025 if (!indexed && d_inode(lowerdentry)->i_nlink == 1) 1026 return fallback; 1027 1028 err = ovl_getxattr_upper(ofs, upperdentry, OVL_XATTR_NLINK, 1029 &buf, sizeof(buf) - 1); 1030 if (err < 0) 1031 goto fail; 1032 1033 buf[err] = '\0'; 1034 if ((buf[0] != 'L' && buf[0] != 'U') || 1035 (buf[1] != '+' && buf[1] != '-')) 1036 goto fail; 1037 1038 err = kstrtoint(buf + 1, 10, &nlink_diff); 1039 if (err < 0) 1040 goto fail; 1041 1042 nlink = d_inode(buf[0] == 'L' ? lowerdentry : upperdentry)->i_nlink; 1043 nlink += nlink_diff; 1044 1045 if (nlink <= 0) 1046 goto fail; 1047 1048 return nlink; 1049 1050 fail: 1051 pr_warn_ratelimited("failed to get index nlink (%pd2, err=%i)\n", 1052 upperdentry, err); 1053 return fallback; 1054 } 1055 1056 struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev) 1057 { 1058 struct inode *inode; 1059 1060 inode = new_inode(sb); 1061 if (inode) 1062 ovl_fill_inode(inode, mode, rdev); 1063 1064 return inode; 1065 } 1066 1067 static int ovl_inode_test(struct inode *inode, void *data) 1068 { 1069 return inode->i_private == data; 1070 } 1071 1072 static int ovl_inode_set(struct inode *inode, void *data) 1073 { 1074 inode->i_private = data; 1075 return 0; 1076 } 1077 1078 static bool ovl_verify_inode(struct inode *inode, struct dentry *lowerdentry, 1079 struct dentry *upperdentry, bool strict) 1080 { 1081 /* 1082 * For directories, @strict verify from lookup path performs consistency 1083 * checks, so NULL lower/upper in dentry must match NULL lower/upper in 1084 * inode. Non @strict verify from NFS handle decode path passes NULL for 1085 * 'unknown' lower/upper. 1086 */ 1087 if (S_ISDIR(inode->i_mode) && strict) { 1088 /* Real lower dir moved to upper layer under us? */ 1089 if (!lowerdentry && ovl_inode_lower(inode)) 1090 return false; 1091 1092 /* Lookup of an uncovered redirect origin? */ 1093 if (!upperdentry && ovl_inode_upper(inode)) 1094 return false; 1095 } 1096 1097 /* 1098 * Allow non-NULL lower inode in ovl_inode even if lowerdentry is NULL. 1099 * This happens when finding a copied up overlay inode for a renamed 1100 * or hardlinked overlay dentry and lower dentry cannot be followed 1101 * by origin because lower fs does not support file handles. 1102 */ 1103 if (lowerdentry && ovl_inode_lower(inode) != d_inode(lowerdentry)) 1104 return false; 1105 1106 /* 1107 * Allow non-NULL __upperdentry in inode even if upperdentry is NULL. 1108 * This happens when finding a lower alias for a copied up hard link. 1109 */ 1110 if (upperdentry && ovl_inode_upper(inode) != d_inode(upperdentry)) 1111 return false; 1112 1113 return true; 1114 } 1115 1116 struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real, 1117 bool is_upper) 1118 { 1119 struct inode *inode, *key = d_inode(real); 1120 1121 inode = ilookup5(sb, (unsigned long) key, ovl_inode_test, key); 1122 if (!inode) 1123 return NULL; 1124 1125 if (!ovl_verify_inode(inode, is_upper ? NULL : real, 1126 is_upper ? real : NULL, false)) { 1127 iput(inode); 1128 return ERR_PTR(-ESTALE); 1129 } 1130 1131 return inode; 1132 } 1133 1134 bool ovl_lookup_trap_inode(struct super_block *sb, struct dentry *dir) 1135 { 1136 struct inode *key = d_inode(dir); 1137 struct inode *trap; 1138 bool res; 1139 1140 trap = ilookup5(sb, (unsigned long) key, ovl_inode_test, key); 1141 if (!trap) 1142 return false; 1143 1144 res = IS_DEADDIR(trap) && !ovl_inode_upper(trap) && 1145 !ovl_inode_lower(trap); 1146 1147 iput(trap); 1148 return res; 1149 } 1150 1151 /* 1152 * Create an inode cache entry for layer root dir, that will intentionally 1153 * fail ovl_verify_inode(), so any lookup that will find some layer root 1154 * will fail. 1155 */ 1156 struct inode *ovl_get_trap_inode(struct super_block *sb, struct dentry *dir) 1157 { 1158 struct inode *key = d_inode(dir); 1159 struct inode *trap; 1160 1161 if (!d_is_dir(dir)) 1162 return ERR_PTR(-ENOTDIR); 1163 1164 trap = iget5_locked(sb, (unsigned long) key, ovl_inode_test, 1165 ovl_inode_set, key); 1166 if (!trap) 1167 return ERR_PTR(-ENOMEM); 1168 1169 if (!(inode_state_read_once(trap) & I_NEW)) { 1170 /* Conflicting layer roots? */ 1171 iput(trap); 1172 return ERR_PTR(-ELOOP); 1173 } 1174 1175 trap->i_mode = S_IFDIR; 1176 trap->i_flags = S_DEAD; 1177 unlock_new_inode(trap); 1178 1179 return trap; 1180 } 1181 1182 /* 1183 * Does overlay inode need to be hashed by lower inode? 1184 */ 1185 static bool ovl_hash_bylower(struct super_block *sb, struct dentry *upper, 1186 struct dentry *lower, bool index) 1187 { 1188 struct ovl_fs *ofs = OVL_FS(sb); 1189 1190 /* No, if pure upper */ 1191 if (!lower) 1192 return false; 1193 1194 /* Yes, if already indexed */ 1195 if (index) 1196 return true; 1197 1198 /* Yes, if won't be copied up */ 1199 if (!ovl_upper_mnt(ofs)) 1200 return true; 1201 1202 /* No, if lower hardlink is or will be broken on copy up */ 1203 if ((upper || !ovl_indexdir(sb)) && 1204 !d_is_dir(lower) && d_inode(lower)->i_nlink > 1) 1205 return false; 1206 1207 /* No, if non-indexed upper with NFS export */ 1208 if (ofs->config.nfs_export && upper) 1209 return false; 1210 1211 /* Otherwise, hash by lower inode for fsnotify */ 1212 return true; 1213 } 1214 1215 static struct inode *ovl_iget5(struct super_block *sb, struct inode *newinode, 1216 struct inode *key) 1217 { 1218 return newinode ? inode_insert5(newinode, (unsigned long) key, 1219 ovl_inode_test, ovl_inode_set, key) : 1220 iget5_locked(sb, (unsigned long) key, 1221 ovl_inode_test, ovl_inode_set, key); 1222 } 1223 1224 struct inode *ovl_get_inode(struct super_block *sb, 1225 struct ovl_inode_params *oip) 1226 { 1227 struct ovl_fs *ofs = OVL_FS(sb); 1228 struct dentry *upperdentry = oip->upperdentry; 1229 struct ovl_path *lowerpath = ovl_lowerpath(oip->oe); 1230 struct inode *realinode = upperdentry ? d_inode(upperdentry) : NULL; 1231 struct inode *inode; 1232 struct dentry *lowerdentry = lowerpath ? lowerpath->dentry : NULL; 1233 struct path realpath = { 1234 .dentry = upperdentry ?: lowerdentry, 1235 .mnt = upperdentry ? ovl_upper_mnt(ofs) : lowerpath->layer->mnt, 1236 }; 1237 bool bylower = ovl_hash_bylower(sb, upperdentry, lowerdentry, 1238 oip->index); 1239 int fsid = bylower ? lowerpath->layer->fsid : 0; 1240 bool is_dir; 1241 unsigned long ino = 0; 1242 int err = oip->newinode ? -EEXIST : -ENOMEM; 1243 1244 if (!realinode) 1245 realinode = d_inode(lowerdentry); 1246 1247 /* 1248 * Copy up origin (lower) may exist for non-indexed upper, but we must 1249 * not use lower as hash key if this is a broken hardlink. 1250 */ 1251 is_dir = S_ISDIR(realinode->i_mode); 1252 if (upperdentry || bylower) { 1253 struct inode *key = d_inode(bylower ? lowerdentry : 1254 upperdentry); 1255 unsigned int nlink = is_dir ? 1 : realinode->i_nlink; 1256 1257 inode = ovl_iget5(sb, oip->newinode, key); 1258 if (!inode) 1259 goto out_err; 1260 if (!(inode_state_read_once(inode) & I_NEW)) { 1261 /* 1262 * Verify that the underlying files stored in the inode 1263 * match those in the dentry. 1264 */ 1265 if (!ovl_verify_inode(inode, lowerdentry, upperdentry, 1266 true)) { 1267 iput(inode); 1268 err = -ESTALE; 1269 goto out_err; 1270 } 1271 1272 dput(upperdentry); 1273 ovl_free_entry(oip->oe); 1274 kfree(oip->redirect); 1275 kfree(oip->lowerdata_redirect); 1276 goto out; 1277 } 1278 1279 /* Recalculate nlink for non-dir due to indexing */ 1280 if (!is_dir) 1281 nlink = ovl_get_nlink(ofs, lowerdentry, upperdentry, 1282 oip->index, nlink); 1283 set_nlink(inode, nlink); 1284 ino = key->i_ino; 1285 } else { 1286 /* Lower hardlink that will be broken on copy up */ 1287 inode = new_inode(sb); 1288 if (!inode) { 1289 err = -ENOMEM; 1290 goto out_err; 1291 } 1292 ino = realinode->i_ino; 1293 fsid = lowerpath->layer->fsid; 1294 } 1295 ovl_fill_inode(inode, realinode->i_mode, realinode->i_rdev); 1296 ovl_inode_init(inode, oip, ino, fsid); 1297 WARN_ON_ONCE(is_dir && !!IS_CASEFOLDED(inode) != ofs->casefold); 1298 1299 if (upperdentry && ovl_is_impuredir(sb, upperdentry)) 1300 ovl_set_flag(OVL_IMPURE, inode); 1301 1302 if (oip->index) 1303 ovl_set_flag(OVL_INDEX, inode); 1304 1305 if (bylower) 1306 ovl_set_flag(OVL_CONST_INO, inode); 1307 1308 /* Check for non-merge dir that may have whiteouts */ 1309 if (is_dir) { 1310 if (((upperdentry && lowerdentry) || ovl_numlower(oip->oe) > 1) || 1311 ovl_path_check_origin_xattr(ofs, &realpath)) { 1312 ovl_set_flag(OVL_WHITEOUTS, inode); 1313 } 1314 } 1315 1316 /* Check for immutable/append-only inode flags in xattr */ 1317 if (upperdentry) 1318 ovl_check_protattr(inode, upperdentry); 1319 1320 if (inode_state_read_once(inode) & I_NEW) 1321 unlock_new_inode(inode); 1322 out: 1323 return inode; 1324 1325 out_err: 1326 pr_warn_ratelimited("failed to get inode (%i)\n", err); 1327 inode = ERR_PTR(err); 1328 goto out; 1329 } 1330