Lines Matching +full:lower +full:- +full:case

1 // SPDX-License-Identifier: GPL-2.0-only
33 struct ovl_fs *ofs = OVL_FS(d->sb); in ovl_check_redirect()
43 * that will stop further lookup in lower layers (d->stop=true) in ovl_check_redirect()
45 * element and that should force continue lookup in lower in ovl_check_redirect()
46 * layers (reset d->stop). in ovl_check_redirect()
48 d->stop = false; in ovl_check_redirect()
52 memcpy(buf, d->name.name, prelen); in ovl_check_redirect()
56 kfree(d->redirect); in ovl_check_redirect()
57 d->redirect = buf; in ovl_check_redirect()
58 d->name.name = d->redirect; in ovl_check_redirect()
59 d->name.len = strlen(d->redirect); in ovl_check_redirect()
67 * A non-dir origin may be disconnected, which is fine, because in ovl_acceptable()
78 return is_subdir(dentry, ((struct vfsmount *)ctx)->mnt_root); in ovl_acceptable()
85 * Return -ENODATA for "origin unknown".
90 if (fb_len < sizeof(struct ovl_fb) || fb_len < fb->len) in ovl_check_fb_len()
91 return -EINVAL; in ovl_check_fb_len()
93 if (fb->magic != OVL_FH_MAGIC) in ovl_check_fb_len()
94 return -EINVAL; in ovl_check_fb_len()
97 if (fb->version > OVL_FH_VERSION || fb->flags & ~OVL_FH_FLAG_ALL) in ovl_check_fb_len()
98 return -ENODATA; in ovl_check_fb_len()
101 if (!(fb->flags & OVL_FH_FLAG_ANY_ENDIAN) && in ovl_check_fb_len()
102 (fb->flags & OVL_FH_FLAG_BIG_ENDIAN) != OVL_FH_FLAG_CPU_ENDIAN) in ovl_check_fb_len()
103 return -ENODATA; in ovl_check_fb_len()
116 if (res == -ENODATA || res == -EOPNOTSUPP) in ovl_get_fh()
126 return ERR_PTR(-ENOMEM); in ovl_get_fh()
128 res = ovl_do_getxattr(ofs, dentry, ox, fh->buf, res); in ovl_get_fh()
132 err = ovl_check_fb_len(&fh->fb, res); in ovl_get_fh()
134 if (err == -ENODATA) in ovl_get_fh()
163 * Make sure that the stored uuid matches the uuid of the lower in ovl_decode_real_fh()
165 * In case of uuid=off option just make sure that stored uuid is null. in ovl_decode_real_fh()
167 if (ofs->config.uuid ? !uuid_equal(&fh->fb.uuid, &mnt->mnt_sb->s_uuid) : in ovl_decode_real_fh()
168 !uuid_is_null(&fh->fb.uuid)) in ovl_decode_real_fh()
171 bytes = (fh->fb.len - offsetof(struct ovl_fb, fid)); in ovl_decode_real_fh()
172 real = exportfs_decode_fh(mnt, (struct fid *)fh->fb.fid, in ovl_decode_real_fh()
173 bytes >> 2, (int)fh->fb.type, in ovl_decode_real_fh()
177 * Treat stale file handle to lower file as "origin unknown". in ovl_decode_real_fh()
182 if (real == ERR_PTR(-ESTALE) && in ovl_decode_real_fh()
183 !(fh->fb.flags & OVL_FH_FLAG_PATH_UPPER)) in ovl_decode_real_fh()
207 if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { in ovl_lookup_positive_unlocked()
208 if (drop_negative && ret->d_lockref.count == 1) { in ovl_lookup_positive_unlocked()
209 spin_lock(&ret->d_lock); in ovl_lookup_positive_unlocked()
211 if (d_is_negative(ret) && ret->d_lockref.count == 1) in ovl_lookup_positive_unlocked()
213 spin_unlock(&ret->d_lock); in ovl_lookup_positive_unlocked()
216 ret = ERR_PTR(-ENOENT); in ovl_lookup_positive_unlocked()
234 if (err == -ENOENT || err == -ENAMETOOLONG) in ovl_lookup_single()
241 err = -EREMOTE; in ovl_lookup_single()
245 d->stop = d->opaque = true; in ovl_lookup_single()
252 if (last_element && d->metacopy && !d_is_reg(this)) { in ovl_lookup_single()
253 d->stop = true; in ovl_lookup_single()
257 if (d->is_dir || !last_element) { in ovl_lookup_single()
258 d->stop = true; in ovl_lookup_single()
261 err = ovl_check_metacopy_xattr(OVL_FS(d->sb), this); in ovl_lookup_single()
265 d->metacopy = err; in ovl_lookup_single()
266 d->stop = !d->metacopy; in ovl_lookup_single()
267 if (!d->metacopy || d->last) in ovl_lookup_single()
270 if (ovl_lookup_trap_inode(d->sb, this)) { in ovl_lookup_single()
272 err = -ELOOP; in ovl_lookup_single()
277 d->is_dir = true; in ovl_lookup_single()
278 if (d->last) in ovl_lookup_single()
281 if (ovl_is_opaquedir(d->sb, this)) { in ovl_lookup_single()
282 d->stop = true; in ovl_lookup_single()
284 d->opaque = true; in ovl_lookup_single()
309 size_t rem = d->name.len - 1; in ovl_lookup_layer()
313 if (d->name.name[0] != '/') in ovl_lookup_layer()
314 return ovl_lookup_single(base, d, d->name.name, d->name.len, in ovl_lookup_layer()
318 const char *s = d->name.name + d->name.len - rem; in ovl_lookup_layer()
320 size_t thislen = next - s; in ovl_lookup_layer()
324 if (WARN_ON(s[-1] != '/')) in ovl_lookup_layer()
325 return -EIO; in ovl_lookup_layer()
328 d->name.len - rem, next, &base, in ovl_lookup_layer()
337 rem -= thislen + 1; in ovl_lookup_layer()
339 if (WARN_ON(rem >= d->name.len)) in ovl_lookup_layer()
340 return -EIO; in ovl_lookup_layer()
353 for (i = 1; i < ofs->numlayer; i++) { in ovl_check_origin_fh()
355 * If lower fs uuid is not unique among lower fs we cannot match in ovl_check_origin_fh()
356 * fh->uuid to layer. in ovl_check_origin_fh()
358 if (ofs->layers[i].fsid && in ovl_check_origin_fh()
359 ofs->layers[i].fs->bad_uuid) in ovl_check_origin_fh()
362 origin = ovl_decode_real_fh(ofs, fh, ofs->layers[i].mnt, in ovl_check_origin_fh()
369 return -ESTALE; in ovl_check_origin_fh()
374 inode_wrong_type(d_inode(upperdentry), d_inode(origin)->i_mode)) in ovl_check_origin_fh()
381 return -ENOMEM; in ovl_check_origin_fh()
385 .layer = &ofs->layers[i] in ovl_check_origin_fh()
392 upperdentry, d_inode(upperdentry)->i_mode & S_IFMT, in ovl_check_origin_fh()
393 d_inode(origin)->i_mode & S_IFMT); in ovl_check_origin_fh()
395 return -ESTALE; in ovl_check_origin_fh()
411 if (err == -ESTALE) in ovl_check_origin()
421 * Return 0 on match, -ESTALE on mismatch, < 0 on error.
430 return -ENODATA; in ovl_verify_fh()
435 if (fh->fb.len != ofh->fb.len || memcmp(&fh->fb, &ofh->fb, fh->fb.len)) in ovl_verify_fh()
436 err = -ESTALE; in ovl_verify_fh()
448 * Return 0 on match, -ESTALE on mismatch, -ENODATA on no xattr, < 0 on error.
466 if (set && err == -ENODATA) in ovl_verify_set_fh()
467 err = ovl_do_setxattr(ofs, dentry, ox, fh->buf, fh->fb.len); in ovl_verify_set_fh()
479 inode ? inode->i_ino : 0, err); in ovl_verify_set_fh()
500 return upper ?: ERR_PTR(-ESTALE); in ovl_index_upper()
506 return ERR_PTR(-EIO); in ovl_index_upper()
514 * OVL_XATTR_ORIGIN and that origin file handle can be decoded to lower path.
515 * Return 0 on match, -ESTALE on mismatch or stale origin, < 0 on error.
529 err = -EINVAL; in ovl_verify_index()
530 if (index->d_name.len < sizeof(struct ovl_fb)*2) in ovl_verify_index()
533 err = -ENOMEM; in ovl_verify_index()
534 len = index->d_name.len / 2; in ovl_verify_index()
539 err = -EINVAL; in ovl_verify_index()
540 if (hex2bin(fh->buf, index->d_name.name, len)) in ovl_verify_index()
543 err = ovl_check_fb_len(&fh->fb, len); in ovl_verify_index()
559 if (d_is_dir(index) && !ofs->config.nfs_export) in ovl_verify_index()
564 * real upper dir. Non-dir index entries are hardlinks to the upper in ovl_verify_index()
565 * real inode. For non-dir index, we can read the copy up origin xattr in ovl_verify_index()
578 if (err == -ESTALE) in ovl_verify_index()
581 err = -ESTALE; in ovl_verify_index()
590 /* Check if non-dir index is orphan and don't warn before cleaning it */ in ovl_verify_index()
591 if (!d_is_dir(index) && d_inode(index)->i_nlink == 1) { in ovl_verify_index()
607 index, d_inode(index)->i_mode & S_IFMT, err); in ovl_verify_index()
612 index, d_inode(index)->i_mode & S_IFMT, in ovl_verify_index()
613 d_inode(index)->i_nlink); in ovl_verify_index()
614 err = -ENOENT; in ovl_verify_index()
622 n = kcalloc(fh->fb.len, 2, GFP_KERNEL); in ovl_get_index_name_fh()
624 return -ENOMEM; in ovl_get_index_name_fh()
626 s = bin2hex(n, fh->buf, fh->fb.len); in ovl_get_index_name_fh()
627 *name = (struct qstr) QSTR_INIT(n, s - n); in ovl_get_index_name_fh()
634 * Lookup in indexdir for the index entry of a lower real inode or a copy up
635 * origin inode. The index entry name is the hex representation of the lower
638 * If the index dentry in negative, then either no lower aliases have been
675 index = lookup_positive_unlocked(name.name, ofs->indexdir, name.len); in ovl_get_index_fh()
678 if (PTR_ERR(index) == -ENOENT) in ovl_get_index_fh()
684 err = -ESTALE; in ovl_get_index_fh()
686 err = -EIO; in ovl_get_index_fh()
707 index = lookup_positive_unlocked(name.name, ofs->indexdir, name.len); in ovl_lookup_index()
710 if (err == -ENOENT) { in ovl_lookup_index()
715 "overlayfs: mount with '-o index=off' to disable inodes index.\n", in ovl_lookup_index()
716 d_inode(origin)->i_ino, name.len, name.name, in ovl_lookup_index()
730 index = ERR_PTR(-ESTALE); in ovl_lookup_index()
733 inode_wrong_type(inode, d_inode(origin)->i_mode)) { in ovl_lookup_index()
736 * except for the case of a whiteout index. A whiteout in ovl_lookup_index()
737 * index should only exist if all lower aliases have been in ovl_lookup_index()
738 * unlinked, which means that finding a lower origin on lookup in ovl_lookup_index()
742 index, d_inode(index)->i_mode & S_IFMT, in ovl_lookup_index()
743 d_inode(origin)->i_mode & S_IFMT); in ovl_lookup_index()
755 if (err == -ESTALE) { in ovl_lookup_index()
775 index = ERR_PTR(-EIO); in ovl_lookup_index()
781 * Returns -1 if this is the last layer.
785 struct ovl_entry *oe = dentry->d_fsdata; in ovl_path_next()
790 if (path->dentry) in ovl_path_next()
791 return oe->numlower ? 1 : -1; in ovl_path_next()
794 BUG_ON(idx > oe->numlower); in ovl_path_next()
795 path->dentry = oe->lowerstack[idx - 1].dentry; in ovl_path_next()
796 path->mnt = oe->lowerstack[idx - 1].layer->mnt; in ovl_path_next()
798 return (idx < oe->numlower) ? idx + 1 : -1; in ovl_path_next()
803 struct dentry *lower, struct dentry *upper) in ovl_fix_origin() argument
814 err = ovl_set_origin(ofs, lower, upper); in ovl_fix_origin()
816 err = ovl_set_impure(dentry->d_parent, upper->d_parent); in ovl_fix_origin()
827 struct ovl_fs *ofs = dentry->d_sb->s_fs_info; in ovl_lookup()
828 struct ovl_entry *poe = dentry->d_parent->d_fsdata; in ovl_lookup()
829 struct ovl_entry *roe = dentry->d_sb->s_root->d_fsdata; in ovl_lookup()
843 .sb = dentry->d_sb, in ovl_lookup()
844 .name = dentry->d_name, in ovl_lookup()
848 .last = ofs->config.redirect_follow ? false : !poe->numlower, in ovl_lookup()
853 if (dentry->d_name.len > ofs->namelen) in ovl_lookup()
854 return ERR_PTR(-ENAMETOOLONG); in ovl_lookup()
856 old_cred = ovl_override_creds(dentry->d_sb); in ovl_lookup()
857 upperdir = ovl_dentry_upper(dentry->d_parent); in ovl_lookup()
863 if (upperdentry && upperdentry->d_flags & DCACHE_OP_REAL) { in ovl_lookup()
865 err = -EREMOTE; in ovl_lookup()
874 * connected dentry, that is not under any of the lower in ovl_lookup()
876 * number - it's the same as if we held a reference in ovl_lookup()
877 * to a dentry in lower layer that was moved under us. in ovl_lookup()
888 err = -ENOMEM; in ovl_lookup()
898 if (!d.stop && poe->numlower) { in ovl_lookup()
899 err = -ENOMEM; in ovl_lookup()
900 stack = kcalloc(ofs->numlayer - 1, sizeof(struct ovl_path), in ovl_lookup()
906 for (i = 0; !d.stop && i < poe->numlower; i++) { in ovl_lookup()
907 struct ovl_path lower = poe->lowerstack[i]; in ovl_lookup() local
909 if (!ofs->config.redirect_follow) in ovl_lookup()
910 d.last = i == poe->numlower - 1; in ovl_lookup()
912 d.last = lower.layer->idx == roe->numlower; in ovl_lookup()
914 err = ovl_lookup_layer(lower.dentry, &d, &this, false); in ovl_lookup()
921 if ((uppermetacopy || d.metacopy) && !ofs->config.metacopy) { in ovl_lookup()
923 err = -EPERM; in ovl_lookup()
930 * of lower dir and set upper parent "impure". in ovl_lookup()
932 if (upperdentry && !ctr && !ofs->noxattr && d.is_dir) { in ovl_lookup()
942 * lower dir that does not match a stored origin xattr. In any in ovl_lookup()
943 * case, only verified origin is used for index lookup. in ovl_lookup()
945 * For non-dir dentry, if index=on, then ensure origin in ovl_lookup()
950 ((d.is_dir && ovl_verify_lower(dentry->d_sb)) || in ovl_lookup()
951 (!d.is_dir && ofs->config.index && origin_path))) { in ovl_lookup()
965 * lower chain, except top most lower metacopy dentry. in ovl_lookup()
973 stack[ctr].layer = lower.layer; in ovl_lookup()
979 * a symlink into the lower layer without the permission checks. in ovl_lookup()
981 * comes from an USB drive). This can allow a non-readable file in ovl_lookup()
987 err = -EPERM; in ovl_lookup()
988 if (d.redirect && !ofs->config.redirect_follow) { in ovl_lookup()
1000 i = lower.layer->idx - 1; in ovl_lookup()
1005 * For regular non-metacopy upper dentries, there is no lower in ovl_lookup()
1009 * For metacopy dentry, path based lookup will find lower dentries. in ovl_lookup()
1013 pr_warn_ratelimited("metacopy with no lower data found - abort lookup (%pd2)\n", in ovl_lookup()
1015 err = -EIO; in ovl_lookup()
1019 err = -EIO; in ovl_lookup()
1024 origin = origin_path->dentry; in ovl_lookup()
1029 * Always lookup index if there is no-upperdentry. in ovl_lookup()
1031 * For the case of upperdentry, we have set origin by now if it in ovl_lookup()
1034 * For directories, lookup index by lower inode and verify it matches in ovl_lookup()
1035 * upper inode. We only trust dir index if we verified that lower dir in ovl_lookup()
1041 * based dentry lookup in lower in this case. in ovl_lookup()
1050 if (origin && ovl_indexdir(dentry->d_sb) && in ovl_lookup()
1051 (!d.is_dir || ovl_index_all(dentry->d_sb))) { in ovl_lookup()
1061 err = -ENOMEM; in ovl_lookup()
1065 memcpy(oe->lowerstack, stack, sizeof(struct ovl_path) * ctr); in ovl_lookup()
1066 dentry->d_fsdata = oe; in ovl_lookup()
1095 stack[ctr - 1].dentry : NULL, in ovl_lookup()
1098 inode = ovl_get_inode(dentry->d_sb, &oip); in ovl_lookup()
1111 dput(origin_path->dentry); in ovl_lookup()
1120 dentry->d_fsdata = NULL; in ovl_lookup()
1129 dput(origin_path->dentry); in ovl_lookup()
1142 struct ovl_entry *poe = dentry->d_parent->d_fsdata; in ovl_lower_positive()
1143 const struct qstr *name = &dentry->d_name; in ovl_lower_positive()
1150 * If dentry is negative, then lower is positive iff this is a in ovl_lower_positive()
1153 if (!dentry->d_inode) in ovl_lower_positive()
1156 /* Negative upper -> positive lower */ in ovl_lower_positive()
1160 old_cred = ovl_override_creds(dentry->d_sb); in ovl_lower_positive()
1161 /* Positive upper -> have to look up lower to see whether it exists */ in ovl_lower_positive()
1162 for (i = 0; !done && !positive && i < poe->numlower; i++) { in ovl_lower_positive()
1164 struct dentry *lowerdir = poe->lowerstack[i].dentry; in ovl_lower_positive()
1166 this = lookup_positive_unlocked(name->name, lowerdir, in ovl_lower_positive()
1167 name->len); in ovl_lower_positive()
1170 case -ENOENT: in ovl_lower_positive()
1171 case -ENAMETOOLONG: in ovl_lower_positive()