Lines Matching +full:lower +full:- +full:case
1 // SPDX-License-Identifier: GPL-2.0-only
34 struct ovl_fs *ofs = OVL_FS(d->sb); in ovl_check_redirect()
44 * that will stop further lookup in lower layers (d->stop=true) in ovl_check_redirect()
46 * element and that should force continue lookup in lower in ovl_check_redirect()
47 * layers (reset d->stop). in ovl_check_redirect()
49 d->stop = false; in ovl_check_redirect()
53 memcpy(buf, d->name.name, prelen); in ovl_check_redirect()
57 kfree(d->redirect); in ovl_check_redirect()
58 d->redirect = buf; in ovl_check_redirect()
59 d->name.name = d->redirect; in ovl_check_redirect()
60 d->name.len = strlen(d->redirect); in ovl_check_redirect()
68 * A non-dir origin may be disconnected, which is fine, because in ovl_acceptable()
79 return is_subdir(dentry, ((struct vfsmount *)ctx)->mnt_root); in ovl_acceptable()
86 * Return -ENODATA for "origin unknown".
91 if (fb_len < sizeof(struct ovl_fb) || fb_len < fb->len) in ovl_check_fb_len()
92 return -EINVAL; in ovl_check_fb_len()
94 if (fb->magic != OVL_FH_MAGIC) in ovl_check_fb_len()
95 return -EINVAL; in ovl_check_fb_len()
98 if (fb->version > OVL_FH_VERSION || fb->flags & ~OVL_FH_FLAG_ALL) in ovl_check_fb_len()
99 return -ENODATA; in ovl_check_fb_len()
102 if (!(fb->flags & OVL_FH_FLAG_ANY_ENDIAN) && in ovl_check_fb_len()
103 (fb->flags & OVL_FH_FLAG_BIG_ENDIAN) != OVL_FH_FLAG_CPU_ENDIAN) in ovl_check_fb_len()
104 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_getxattr_upper(ofs, upperdentry, 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()
164 * Make sure that the stored uuid matches the uuid of the lower in ovl_decode_real_fh()
166 * In case of uuid=off option just make sure that stored uuid is null. in ovl_decode_real_fh()
168 if (ofs->config.uuid ? !uuid_equal(&fh->fb.uuid, &mnt->mnt_sb->s_uuid) : in ovl_decode_real_fh()
169 !uuid_is_null(&fh->fb.uuid)) in ovl_decode_real_fh()
172 bytes = (fh->fb.len - offsetof(struct ovl_fb, fid)); in ovl_decode_real_fh()
173 real = exportfs_decode_fh(mnt, (struct fid *)fh->fb.fid, in ovl_decode_real_fh()
174 bytes >> 2, (int)fh->fb.type, in ovl_decode_real_fh()
178 * Treat stale file handle to lower file as "origin unknown". in ovl_decode_real_fh()
183 if (real == ERR_PTR(-ESTALE) && in ovl_decode_real_fh()
184 !(fh->fb.flags & OVL_FH_FLAG_PATH_UPPER)) in ovl_decode_real_fh()
207 struct dentry *ret = lookup_one_unlocked(mnt_user_ns(d->mnt), name, base, len); in ovl_lookup_positive_unlocked()
209 if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { in ovl_lookup_positive_unlocked()
210 if (drop_negative && ret->d_lockref.count == 1) { in ovl_lookup_positive_unlocked()
211 spin_lock(&ret->d_lock); in ovl_lookup_positive_unlocked()
213 if (d_is_negative(ret) && ret->d_lockref.count == 1) in ovl_lookup_positive_unlocked()
215 spin_unlock(&ret->d_lock); in ovl_lookup_positive_unlocked()
218 ret = ERR_PTR(-ENOENT); in ovl_lookup_positive_unlocked()
237 if (err == -ENOENT || err == -ENAMETOOLONG) in ovl_lookup_single()
244 err = -EREMOTE; in ovl_lookup_single()
248 d->stop = d->opaque = true; in ovl_lookup_single()
255 if (last_element && d->metacopy && !d_is_reg(this)) { in ovl_lookup_single()
256 d->stop = true; in ovl_lookup_single()
261 path.mnt = d->mnt; in ovl_lookup_single()
263 if (d->is_dir || !last_element) { in ovl_lookup_single()
264 d->stop = true; in ovl_lookup_single()
267 err = ovl_check_metacopy_xattr(OVL_FS(d->sb), &path); in ovl_lookup_single()
271 d->metacopy = err; in ovl_lookup_single()
272 d->stop = !d->metacopy; in ovl_lookup_single()
273 if (!d->metacopy || d->last) in ovl_lookup_single()
276 if (ovl_lookup_trap_inode(d->sb, this)) { in ovl_lookup_single()
278 err = -ELOOP; in ovl_lookup_single()
283 d->is_dir = true; in ovl_lookup_single()
284 if (d->last) in ovl_lookup_single()
287 if (ovl_is_opaquedir(OVL_FS(d->sb), &path)) { in ovl_lookup_single()
288 d->stop = true; in ovl_lookup_single()
290 d->opaque = true; in ovl_lookup_single()
315 size_t rem = d->name.len - 1; in ovl_lookup_layer()
319 if (d->name.name[0] != '/') in ovl_lookup_layer()
320 return ovl_lookup_single(base, d, d->name.name, d->name.len, in ovl_lookup_layer()
324 const char *s = d->name.name + d->name.len - rem; in ovl_lookup_layer()
326 size_t thislen = next - s; in ovl_lookup_layer()
330 if (WARN_ON(s[-1] != '/')) in ovl_lookup_layer()
331 return -EIO; in ovl_lookup_layer()
334 d->name.len - rem, next, &base, in ovl_lookup_layer()
343 rem -= thislen + 1; in ovl_lookup_layer()
345 if (WARN_ON(rem >= d->name.len)) in ovl_lookup_layer()
346 return -EIO; in ovl_lookup_layer()
359 for (i = 1; i < ofs->numlayer; i++) { in ovl_check_origin_fh()
361 * If lower fs uuid is not unique among lower fs we cannot match in ovl_check_origin_fh()
362 * fh->uuid to layer. in ovl_check_origin_fh()
364 if (ofs->layers[i].fsid && in ovl_check_origin_fh()
365 ofs->layers[i].fs->bad_uuid) in ovl_check_origin_fh()
368 origin = ovl_decode_real_fh(ofs, fh, ofs->layers[i].mnt, in ovl_check_origin_fh()
375 return -ESTALE; in ovl_check_origin_fh()
380 inode_wrong_type(d_inode(upperdentry), d_inode(origin)->i_mode)) in ovl_check_origin_fh()
387 return -ENOMEM; in ovl_check_origin_fh()
391 .layer = &ofs->layers[i] in ovl_check_origin_fh()
398 upperdentry, d_inode(upperdentry)->i_mode & S_IFMT, in ovl_check_origin_fh()
399 d_inode(origin)->i_mode & S_IFMT); in ovl_check_origin_fh()
401 return -ESTALE; in ovl_check_origin_fh()
417 if (err == -ESTALE) in ovl_check_origin()
427 * Return 0 on match, -ESTALE on mismatch, < 0 on error.
436 return -ENODATA; in ovl_verify_fh()
441 if (fh->fb.len != ofh->fb.len || memcmp(&fh->fb, &ofh->fb, fh->fb.len)) in ovl_verify_fh()
442 err = -ESTALE; in ovl_verify_fh()
454 * Return 0 on match, -ESTALE on mismatch, -ENODATA on no xattr, < 0 on error.
472 if (set && err == -ENODATA) in ovl_verify_set_fh()
473 err = ovl_setxattr(ofs, dentry, ox, fh->buf, fh->fb.len); in ovl_verify_set_fh()
485 inode ? inode->i_ino : 0, err); in ovl_verify_set_fh()
506 return upper ?: ERR_PTR(-ESTALE); in ovl_index_upper()
512 return ERR_PTR(-EIO); in ovl_index_upper()
520 * OVL_XATTR_ORIGIN and that origin file handle can be decoded to lower path.
521 * Return 0 on match, -ESTALE on mismatch or stale origin, < 0 on error.
535 err = -EINVAL; in ovl_verify_index()
536 if (index->d_name.len < sizeof(struct ovl_fb)*2) in ovl_verify_index()
539 err = -ENOMEM; in ovl_verify_index()
540 len = index->d_name.len / 2; in ovl_verify_index()
545 err = -EINVAL; in ovl_verify_index()
546 if (hex2bin(fh->buf, index->d_name.name, len)) in ovl_verify_index()
549 err = ovl_check_fb_len(&fh->fb, len); in ovl_verify_index()
565 if (d_is_dir(index) && !ofs->config.nfs_export) in ovl_verify_index()
570 * real upper dir. Non-dir index entries are hardlinks to the upper in ovl_verify_index()
571 * real inode. For non-dir index, we can read the copy up origin xattr in ovl_verify_index()
584 if (err == -ESTALE) in ovl_verify_index()
587 err = -ESTALE; in ovl_verify_index()
596 /* Check if non-dir index is orphan and don't warn before cleaning it */ in ovl_verify_index()
597 if (!d_is_dir(index) && d_inode(index)->i_nlink == 1) { in ovl_verify_index()
613 index, d_inode(index)->i_mode & S_IFMT, err); in ovl_verify_index()
618 index, d_inode(index)->i_mode & S_IFMT, in ovl_verify_index()
619 d_inode(index)->i_nlink); in ovl_verify_index()
620 err = -ENOENT; in ovl_verify_index()
628 n = kcalloc(fh->fb.len, 2, GFP_KERNEL); in ovl_get_index_name_fh()
630 return -ENOMEM; in ovl_get_index_name_fh()
632 s = bin2hex(n, fh->buf, fh->fb.len); in ovl_get_index_name_fh()
633 *name = (struct qstr) QSTR_INIT(n, s - n); in ovl_get_index_name_fh()
640 * Lookup in indexdir for the index entry of a lower real inode or a copy up
641 * origin inode. The index entry name is the hex representation of the lower
644 * If the index dentry in negative, then either no lower aliases have been
681 index = lookup_positive_unlocked(name.name, ofs->indexdir, name.len); in ovl_get_index_fh()
684 if (PTR_ERR(index) == -ENOENT) in ovl_get_index_fh()
690 err = -ESTALE; in ovl_get_index_fh()
692 err = -EIO; in ovl_get_index_fh()
714 ofs->indexdir, name.len); in ovl_lookup_index()
717 if (err == -ENOENT) { in ovl_lookup_index()
722 "overlayfs: mount with '-o index=off' to disable inodes index.\n", in ovl_lookup_index()
723 d_inode(origin)->i_ino, name.len, name.name, in ovl_lookup_index()
737 index = ERR_PTR(-ESTALE); in ovl_lookup_index()
740 inode_wrong_type(inode, d_inode(origin)->i_mode)) { in ovl_lookup_index()
743 * except for the case of a whiteout index. A whiteout in ovl_lookup_index()
744 * index should only exist if all lower aliases have been in ovl_lookup_index()
745 * unlinked, which means that finding a lower origin on lookup in ovl_lookup_index()
749 index, d_inode(index)->i_mode & S_IFMT, in ovl_lookup_index()
750 d_inode(origin)->i_mode & S_IFMT); in ovl_lookup_index()
762 if (err == -ESTALE) { in ovl_lookup_index()
782 index = ERR_PTR(-EIO); in ovl_lookup_index()
788 * Returns -1 if this is the last layer.
792 struct ovl_entry *oe = dentry->d_fsdata; in ovl_path_next()
797 if (path->dentry) in ovl_path_next()
798 return oe->numlower ? 1 : -1; in ovl_path_next()
801 BUG_ON(idx > oe->numlower); in ovl_path_next()
802 path->dentry = oe->lowerstack[idx - 1].dentry; in ovl_path_next()
803 path->mnt = oe->lowerstack[idx - 1].layer->mnt; in ovl_path_next()
805 return (idx < oe->numlower) ? idx + 1 : -1; in ovl_path_next()
810 struct dentry *lower, struct dentry *upper) in ovl_fix_origin() argument
821 err = ovl_set_origin(ofs, lower, upper); in ovl_fix_origin()
823 err = ovl_set_impure(dentry->d_parent, upper->d_parent); in ovl_fix_origin()
834 struct ovl_fs *ofs = dentry->d_sb->s_fs_info; in ovl_lookup()
835 struct ovl_entry *poe = dentry->d_parent->d_fsdata; in ovl_lookup()
836 struct ovl_entry *roe = dentry->d_sb->s_root->d_fsdata; in ovl_lookup()
850 .sb = dentry->d_sb, in ovl_lookup()
851 .name = dentry->d_name, in ovl_lookup()
855 .last = ofs->config.redirect_follow ? false : !poe->numlower, in ovl_lookup()
860 if (dentry->d_name.len > ofs->namelen) in ovl_lookup()
861 return ERR_PTR(-ENAMETOOLONG); in ovl_lookup()
863 old_cred = ovl_override_creds(dentry->d_sb); in ovl_lookup()
864 upperdir = ovl_dentry_upper(dentry->d_parent); in ovl_lookup()
871 if (upperdentry && upperdentry->d_flags & DCACHE_OP_REAL) { in ovl_lookup()
873 err = -EREMOTE; in ovl_lookup()
882 * connected dentry, that is not under any of the lower in ovl_lookup()
884 * number - it's the same as if we held a reference in ovl_lookup()
885 * to a dentry in lower layer that was moved under us. in ovl_lookup()
896 err = -ENOMEM; in ovl_lookup()
906 if (!d.stop && poe->numlower) { in ovl_lookup()
907 err = -ENOMEM; in ovl_lookup()
908 stack = kcalloc(ofs->numlayer - 1, sizeof(struct ovl_path), in ovl_lookup()
914 for (i = 0; !d.stop && i < poe->numlower; i++) { in ovl_lookup()
915 struct ovl_path lower = poe->lowerstack[i]; in ovl_lookup() local
917 if (!ofs->config.redirect_follow) in ovl_lookup()
918 d.last = i == poe->numlower - 1; in ovl_lookup()
920 d.last = lower.layer->idx == roe->numlower; in ovl_lookup()
922 d.mnt = lower.layer->mnt; in ovl_lookup()
923 err = ovl_lookup_layer(lower.dentry, &d, &this, false); in ovl_lookup()
930 if ((uppermetacopy || d.metacopy) && !ofs->config.metacopy) { in ovl_lookup()
932 err = -EPERM; in ovl_lookup()
939 * of lower dir and set upper parent "impure". in ovl_lookup()
941 if (upperdentry && !ctr && !ofs->noxattr && d.is_dir) { in ovl_lookup()
951 * lower dir that does not match a stored origin xattr. In any in ovl_lookup()
952 * case, only verified origin is used for index lookup. in ovl_lookup()
954 * For non-dir dentry, if index=on, then ensure origin in ovl_lookup()
959 ((d.is_dir && ovl_verify_lower(dentry->d_sb)) || in ovl_lookup()
960 (!d.is_dir && ofs->config.index && origin_path))) { in ovl_lookup()
974 * lower chain, except top most lower metacopy dentry. in ovl_lookup()
982 stack[ctr].layer = lower.layer; in ovl_lookup()
988 * a symlink into the lower layer without the permission checks. in ovl_lookup()
990 * comes from an USB drive). This can allow a non-readable file in ovl_lookup()
996 err = -EPERM; in ovl_lookup()
997 if (d.redirect && !ofs->config.redirect_follow) { in ovl_lookup()
1009 i = lower.layer->idx - 1; in ovl_lookup()
1014 * For regular non-metacopy upper dentries, there is no lower in ovl_lookup()
1018 * For metacopy dentry, path based lookup will find lower dentries. in ovl_lookup()
1022 pr_warn_ratelimited("metacopy with no lower data found - abort lookup (%pd2)\n", in ovl_lookup()
1024 err = -EIO; in ovl_lookup()
1028 err = -EIO; in ovl_lookup()
1033 origin = origin_path->dentry; in ovl_lookup()
1038 * Always lookup index if there is no-upperdentry. in ovl_lookup()
1040 * For the case of upperdentry, we have set origin by now if it in ovl_lookup()
1043 * For directories, lookup index by lower inode and verify it matches in ovl_lookup()
1044 * upper inode. We only trust dir index if we verified that lower dir in ovl_lookup()
1050 * based dentry lookup in lower in this case. in ovl_lookup()
1059 if (origin && ovl_indexdir(dentry->d_sb) && in ovl_lookup()
1060 (!d.is_dir || ovl_index_all(dentry->d_sb))) { in ovl_lookup()
1070 err = -ENOMEM; in ovl_lookup()
1074 memcpy(oe->lowerstack, stack, sizeof(struct ovl_path) * ctr); in ovl_lookup()
1075 dentry->d_fsdata = oe; in ovl_lookup()
1108 stack[ctr - 1].dentry : NULL, in ovl_lookup()
1111 inode = ovl_get_inode(dentry->d_sb, &oip); in ovl_lookup()
1124 dput(origin_path->dentry); in ovl_lookup()
1133 dentry->d_fsdata = NULL; in ovl_lookup()
1142 dput(origin_path->dentry); in ovl_lookup()
1155 struct ovl_entry *poe = dentry->d_parent->d_fsdata; in ovl_lower_positive()
1156 const struct qstr *name = &dentry->d_name; in ovl_lower_positive()
1163 * If dentry is negative, then lower is positive iff this is a in ovl_lower_positive()
1166 if (!dentry->d_inode) in ovl_lower_positive()
1169 /* Negative upper -> positive lower */ in ovl_lower_positive()
1173 old_cred = ovl_override_creds(dentry->d_sb); in ovl_lower_positive()
1174 /* Positive upper -> have to look up lower to see whether it exists */ in ovl_lower_positive()
1175 for (i = 0; !done && !positive && i < poe->numlower; i++) { in ovl_lower_positive()
1177 struct dentry *lowerdir = poe->lowerstack[i].dentry; in ovl_lower_positive()
1179 this = lookup_one_positive_unlocked(mnt_user_ns(poe->lowerstack[i].layer->mnt), in ovl_lower_positive()
1180 name->name, lowerdir, name->len); in ovl_lower_positive()
1183 case -ENOENT: in ovl_lower_positive()
1184 case -ENAMETOOLONG: in ovl_lower_positive()