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()
117 if (res == -ENODATA || res == -EOPNOTSUPP) in ovl_get_fh()
127 return ERR_PTR(-ENOMEM); in ovl_get_fh()
129 res = ovl_do_getxattr(ofs, dentry, ox, fh->buf, res); in ovl_get_fh()
133 err = ovl_check_fb_len(&fh->fb, res); in ovl_get_fh()
135 if (err == -ENODATA) in ovl_get_fh()
161 * Make sure that the stored uuid matches the uuid of the lower in ovl_decode_real_fh()
164 if (!uuid_equal(&fh->fb.uuid, &mnt->mnt_sb->s_uuid)) in ovl_decode_real_fh()
167 bytes = (fh->fb.len - offsetof(struct ovl_fb, fid)); in ovl_decode_real_fh()
168 real = exportfs_decode_fh(mnt, (struct fid *)fh->fb.fid, in ovl_decode_real_fh()
169 bytes >> 2, (int)fh->fb.type, in ovl_decode_real_fh()
173 * Treat stale file handle to lower file as "origin unknown". in ovl_decode_real_fh()
178 if (real == ERR_PTR(-ESTALE) && in ovl_decode_real_fh()
179 !(fh->fb.flags & OVL_FH_FLAG_PATH_UPPER)) in ovl_decode_real_fh()
203 if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { in ovl_lookup_positive_unlocked()
204 if (drop_negative && ret->d_lockref.count == 1) { in ovl_lookup_positive_unlocked()
205 spin_lock(&ret->d_lock); in ovl_lookup_positive_unlocked()
207 if (d_is_negative(ret) && ret->d_lockref.count == 1) in ovl_lookup_positive_unlocked()
209 spin_unlock(&ret->d_lock); in ovl_lookup_positive_unlocked()
212 ret = ERR_PTR(-ENOENT); in ovl_lookup_positive_unlocked()
230 if (err == -ENOENT || err == -ENAMETOOLONG) in ovl_lookup_single()
237 err = -EREMOTE; in ovl_lookup_single()
241 d->stop = d->opaque = true; in ovl_lookup_single()
248 if (last_element && d->metacopy && !d_is_reg(this)) { in ovl_lookup_single()
249 d->stop = true; in ovl_lookup_single()
253 if (d->is_dir || !last_element) { in ovl_lookup_single()
254 d->stop = true; in ovl_lookup_single()
257 err = ovl_check_metacopy_xattr(OVL_FS(d->sb), this); in ovl_lookup_single()
261 d->metacopy = err; in ovl_lookup_single()
262 d->stop = !d->metacopy; in ovl_lookup_single()
263 if (!d->metacopy || d->last) in ovl_lookup_single()
266 if (ovl_lookup_trap_inode(d->sb, this)) { in ovl_lookup_single()
268 err = -ELOOP; in ovl_lookup_single()
273 d->is_dir = true; in ovl_lookup_single()
274 if (d->last) in ovl_lookup_single()
277 if (ovl_is_opaquedir(d->sb, this)) { in ovl_lookup_single()
278 d->stop = true; in ovl_lookup_single()
280 d->opaque = true; in ovl_lookup_single()
305 size_t rem = d->name.len - 1; in ovl_lookup_layer()
309 if (d->name.name[0] != '/') in ovl_lookup_layer()
310 return ovl_lookup_single(base, d, d->name.name, d->name.len, in ovl_lookup_layer()
314 const char *s = d->name.name + d->name.len - rem; in ovl_lookup_layer()
316 size_t thislen = next - s; in ovl_lookup_layer()
320 if (WARN_ON(s[-1] != '/')) in ovl_lookup_layer()
321 return -EIO; in ovl_lookup_layer()
324 d->name.len - rem, next, &base, in ovl_lookup_layer()
333 rem -= thislen + 1; in ovl_lookup_layer()
335 if (WARN_ON(rem >= d->name.len)) in ovl_lookup_layer()
336 return -EIO; in ovl_lookup_layer()
349 for (i = 1; i < ofs->numlayer; i++) { in ovl_check_origin_fh()
351 * If lower fs uuid is not unique among lower fs we cannot match in ovl_check_origin_fh()
352 * fh->uuid to layer. in ovl_check_origin_fh()
354 if (ofs->layers[i].fsid && in ovl_check_origin_fh()
355 ofs->layers[i].fs->bad_uuid) in ovl_check_origin_fh()
358 origin = ovl_decode_real_fh(fh, ofs->layers[i].mnt, in ovl_check_origin_fh()
365 return -ESTALE; in ovl_check_origin_fh()
370 inode_wrong_type(d_inode(upperdentry), d_inode(origin)->i_mode)) in ovl_check_origin_fh()
377 return -ENOMEM; in ovl_check_origin_fh()
381 .layer = &ofs->layers[i] in ovl_check_origin_fh()
388 upperdentry, d_inode(upperdentry)->i_mode & S_IFMT, in ovl_check_origin_fh()
389 d_inode(origin)->i_mode & S_IFMT); in ovl_check_origin_fh()
391 return -EIO; in ovl_check_origin_fh()
407 if (err == -ESTALE) in ovl_check_origin()
417 * Return 0 on match, -ESTALE on mismatch, < 0 on error.
426 return -ENODATA; in ovl_verify_fh()
431 if (fh->fb.len != ofh->fb.len || memcmp(&fh->fb, &ofh->fb, fh->fb.len)) in ovl_verify_fh()
432 err = -ESTALE; in ovl_verify_fh()
444 * Return 0 on match, -ESTALE on mismatch, -ENODATA on no xattr, < 0 on error.
462 if (set && err == -ENODATA) in ovl_verify_set_fh()
463 err = ovl_do_setxattr(ofs, dentry, ox, fh->buf, fh->fb.len); in ovl_verify_set_fh()
475 inode ? inode->i_ino : 0, err); in ovl_verify_set_fh()
496 return upper ?: ERR_PTR(-ESTALE); in ovl_index_upper()
502 return ERR_PTR(-EIO); in ovl_index_upper()
510 * OVL_XATTR_ORIGIN and that origin file handle can be decoded to lower path.
511 * Return 0 on match, -ESTALE on mismatch or stale origin, < 0 on error.
525 err = -EINVAL; in ovl_verify_index()
526 if (index->d_name.len < sizeof(struct ovl_fb)*2) in ovl_verify_index()
529 err = -ENOMEM; in ovl_verify_index()
530 len = index->d_name.len / 2; in ovl_verify_index()
535 err = -EINVAL; in ovl_verify_index()
536 if (hex2bin(fh->buf, index->d_name.name, len)) in ovl_verify_index()
539 err = ovl_check_fb_len(&fh->fb, len); in ovl_verify_index()
555 if (d_is_dir(index) && !ofs->config.nfs_export) in ovl_verify_index()
560 * real upper dir. Non-dir index entries are hardlinks to the upper in ovl_verify_index()
561 * real inode. For non-dir index, we can read the copy up origin xattr in ovl_verify_index()
574 if (err == -ESTALE) in ovl_verify_index()
577 err = -ESTALE; in ovl_verify_index()
586 /* Check if non-dir index is orphan and don't warn before cleaning it */ in ovl_verify_index()
587 if (!d_is_dir(index) && d_inode(index)->i_nlink == 1) { in ovl_verify_index()
603 index, d_inode(index)->i_mode & S_IFMT, err); in ovl_verify_index()
608 index, d_inode(index)->i_mode & S_IFMT, in ovl_verify_index()
609 d_inode(index)->i_nlink); in ovl_verify_index()
610 err = -ENOENT; in ovl_verify_index()
618 n = kcalloc(fh->fb.len, 2, GFP_KERNEL); in ovl_get_index_name_fh()
620 return -ENOMEM; in ovl_get_index_name_fh()
622 s = bin2hex(n, fh->buf, fh->fb.len); in ovl_get_index_name_fh()
623 *name = (struct qstr) QSTR_INIT(n, s - n); in ovl_get_index_name_fh()
630 * Lookup in indexdir for the index entry of a lower real inode or a copy up
631 * origin inode. The index entry name is the hex representation of the lower
634 * If the index dentry in negative, then either no lower aliases have been
670 index = lookup_positive_unlocked(name.name, ofs->indexdir, name.len); in ovl_get_index_fh()
673 if (PTR_ERR(index) == -ENOENT) in ovl_get_index_fh()
679 err = -ESTALE; in ovl_get_index_fh()
681 err = -EIO; in ovl_get_index_fh()
702 index = lookup_positive_unlocked(name.name, ofs->indexdir, name.len); in ovl_lookup_index()
705 if (err == -ENOENT) { in ovl_lookup_index()
710 "overlayfs: mount with '-o index=off' to disable inodes index.\n", in ovl_lookup_index()
711 d_inode(origin)->i_ino, name.len, name.name, in ovl_lookup_index()
725 index = ERR_PTR(-ESTALE); in ovl_lookup_index()
728 inode_wrong_type(inode, d_inode(origin)->i_mode)) { in ovl_lookup_index()
731 * except for the case of a whiteout index. A whiteout in ovl_lookup_index()
732 * index should only exist if all lower aliases have been in ovl_lookup_index()
733 * unlinked, which means that finding a lower origin on lookup in ovl_lookup_index()
737 index, d_inode(index)->i_mode & S_IFMT, in ovl_lookup_index()
738 d_inode(origin)->i_mode & S_IFMT); in ovl_lookup_index()
750 if (err == -ESTALE) { in ovl_lookup_index()
770 index = ERR_PTR(-EIO); in ovl_lookup_index()
776 * Returns -1 if this is the last layer.
780 struct ovl_entry *oe = dentry->d_fsdata; in ovl_path_next()
785 if (path->dentry) in ovl_path_next()
786 return oe->numlower ? 1 : -1; in ovl_path_next()
789 BUG_ON(idx > oe->numlower); in ovl_path_next()
790 path->dentry = oe->lowerstack[idx - 1].dentry; in ovl_path_next()
791 path->mnt = oe->lowerstack[idx - 1].layer->mnt; in ovl_path_next()
793 return (idx < oe->numlower) ? idx + 1 : -1; in ovl_path_next()
798 struct dentry *lower, struct dentry *upper) in ovl_fix_origin() argument
809 err = ovl_set_origin(dentry, lower, upper); in ovl_fix_origin()
811 err = ovl_set_impure(dentry->d_parent, upper->d_parent); in ovl_fix_origin()
822 struct ovl_fs *ofs = dentry->d_sb->s_fs_info; in ovl_lookup()
823 struct ovl_entry *poe = dentry->d_parent->d_fsdata; in ovl_lookup()
824 struct ovl_entry *roe = dentry->d_sb->s_root->d_fsdata; in ovl_lookup()
838 .sb = dentry->d_sb, in ovl_lookup()
839 .name = dentry->d_name, in ovl_lookup()
843 .last = ofs->config.redirect_follow ? false : !poe->numlower, in ovl_lookup()
848 if (dentry->d_name.len > ofs->namelen) in ovl_lookup()
849 return ERR_PTR(-ENAMETOOLONG); in ovl_lookup()
851 old_cred = ovl_override_creds(dentry->d_sb); in ovl_lookup()
852 upperdir = ovl_dentry_upper(dentry->d_parent); in ovl_lookup()
858 if (upperdentry && upperdentry->d_flags & DCACHE_OP_REAL) { in ovl_lookup()
860 err = -EREMOTE; in ovl_lookup()
869 * connected dentry, that is not under any of the lower in ovl_lookup()
871 * number - it's the same as if we held a reference in ovl_lookup()
872 * to a dentry in lower layer that was moved under us. in ovl_lookup()
883 err = -ENOMEM; in ovl_lookup()
893 if (!d.stop && poe->numlower) { in ovl_lookup()
894 err = -ENOMEM; in ovl_lookup()
895 stack = kcalloc(ofs->numlayer - 1, sizeof(struct ovl_path), in ovl_lookup()
901 for (i = 0; !d.stop && i < poe->numlower; i++) { in ovl_lookup()
902 struct ovl_path lower = poe->lowerstack[i]; in ovl_lookup() local
904 if (!ofs->config.redirect_follow) in ovl_lookup()
905 d.last = i == poe->numlower - 1; in ovl_lookup()
907 d.last = lower.layer->idx == roe->numlower; in ovl_lookup()
909 err = ovl_lookup_layer(lower.dentry, &d, &this, false); in ovl_lookup()
916 if ((uppermetacopy || d.metacopy) && !ofs->config.metacopy) { in ovl_lookup()
918 err = -EPERM; in ovl_lookup()
925 * of lower dir and set upper parent "impure". in ovl_lookup()
927 if (upperdentry && !ctr && !ofs->noxattr && d.is_dir) { in ovl_lookup()
937 * lower dir that does not match a stored origin xattr. In any in ovl_lookup()
938 * case, only verified origin is used for index lookup. in ovl_lookup()
940 * For non-dir dentry, if index=on, then ensure origin in ovl_lookup()
945 ((d.is_dir && ovl_verify_lower(dentry->d_sb)) || in ovl_lookup()
946 (!d.is_dir && ofs->config.index && origin_path))) { in ovl_lookup()
960 * lower chain, except top most lower metacopy dentry. in ovl_lookup()
968 stack[ctr].layer = lower.layer; in ovl_lookup()
974 * a symlink into the lower layer without the permission checks. in ovl_lookup()
976 * comes from an USB drive). This can allow a non-readable file in ovl_lookup()
982 err = -EPERM; in ovl_lookup()
983 if (d.redirect && !ofs->config.redirect_follow) { in ovl_lookup()
995 i = lower.layer->idx - 1; in ovl_lookup()
1000 * For regular non-metacopy upper dentries, there is no lower in ovl_lookup()
1004 * For metacopy dentry, path based lookup will find lower dentries. in ovl_lookup()
1008 err = -EIO; in ovl_lookup()
1012 err = -EIO; in ovl_lookup()
1017 origin = origin_path->dentry; in ovl_lookup()
1022 * Always lookup index if there is no-upperdentry. in ovl_lookup()
1024 * For the case of upperdentry, we have set origin by now if it in ovl_lookup()
1027 * For directories, lookup index by lower inode and verify it matches in ovl_lookup()
1028 * upper inode. We only trust dir index if we verified that lower dir in ovl_lookup()
1034 * based dentry lookup in lower in this case. in ovl_lookup()
1043 if (origin && ovl_indexdir(dentry->d_sb) && in ovl_lookup()
1044 (!d.is_dir || ovl_index_all(dentry->d_sb))) { in ovl_lookup()
1054 err = -ENOMEM; in ovl_lookup()
1058 memcpy(oe->lowerstack, stack, sizeof(struct ovl_path) * ctr); in ovl_lookup()
1059 dentry->d_fsdata = oe; in ovl_lookup()
1088 stack[ctr - 1].dentry : NULL, in ovl_lookup()
1091 inode = ovl_get_inode(dentry->d_sb, &oip); in ovl_lookup()
1102 ovl_revert_creds(dentry->d_sb, old_cred); in ovl_lookup()
1104 dput(origin_path->dentry); in ovl_lookup()
1113 dentry->d_fsdata = NULL; in ovl_lookup()
1122 dput(origin_path->dentry); in ovl_lookup()
1129 ovl_revert_creds(dentry->d_sb, old_cred); in ovl_lookup()
1135 struct ovl_entry *poe = dentry->d_parent->d_fsdata; in ovl_lower_positive()
1136 const struct qstr *name = &dentry->d_name; in ovl_lower_positive()
1143 * If dentry is negative, then lower is positive iff this is a in ovl_lower_positive()
1146 if (!dentry->d_inode) in ovl_lower_positive()
1149 /* Negative upper -> positive lower */ in ovl_lower_positive()
1153 old_cred = ovl_override_creds(dentry->d_sb); in ovl_lower_positive()
1154 /* Positive upper -> have to look up lower to see whether it exists */ in ovl_lower_positive()
1155 for (i = 0; !done && !positive && i < poe->numlower; i++) { in ovl_lower_positive()
1157 struct dentry *lowerdir = poe->lowerstack[i].dentry; in ovl_lower_positive()
1159 this = lookup_positive_unlocked(name->name, lowerdir, in ovl_lower_positive()
1160 name->len); in ovl_lower_positive()
1163 case -ENOENT: in ovl_lower_positive()
1164 case -ENAMETOOLONG: in ovl_lower_positive()
1181 ovl_revert_creds(dentry->d_sb, old_cred); in ovl_lower_positive()