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

1 // SPDX-License-Identifier: GPL-2.0-only
37 struct ovl_fs *ofs = OVL_FS(d->sb); in ovl_check_redirect()
39 d->absolute_redirect = false; in ovl_check_redirect()
45 d->absolute_redirect = true; in ovl_check_redirect()
49 * that will stop further lookup in lower layers (d->stop=true) in ovl_check_redirect()
51 * element and that should force continue lookup in lower in ovl_check_redirect()
52 * layers (reset d->stop). in ovl_check_redirect()
54 d->stop = false; in ovl_check_redirect()
58 memcpy(buf, d->name.name, prelen); in ovl_check_redirect()
62 kfree(d->redirect); in ovl_check_redirect()
63 d->redirect = buf; in ovl_check_redirect()
64 d->name.name = d->redirect; in ovl_check_redirect()
65 d->name.len = strlen(d->redirect); in ovl_check_redirect()
73 * A non-dir origin may be disconnected, which is fine, because in ovl_acceptable()
84 return is_subdir(dentry, ((struct vfsmount *)ctx)->mnt_root); in ovl_acceptable()
91 * Return -ENODATA for "origin unknown".
96 if (fb_len < sizeof(struct ovl_fb) || fb_len < fb->len) in ovl_check_fb_len()
97 return -EINVAL; in ovl_check_fb_len()
99 if (fb->magic != OVL_FH_MAGIC) in ovl_check_fb_len()
100 return -EINVAL; in ovl_check_fb_len()
103 if (fb->version > OVL_FH_VERSION || fb->flags & ~OVL_FH_FLAG_ALL) in ovl_check_fb_len()
104 return -ENODATA; in ovl_check_fb_len()
107 if (!(fb->flags & OVL_FH_FLAG_ANY_ENDIAN) && in ovl_check_fb_len()
108 (fb->flags & OVL_FH_FLAG_BIG_ENDIAN) != OVL_FH_FLAG_CPU_ENDIAN) in ovl_check_fb_len()
109 return -ENODATA; in ovl_check_fb_len()
122 if (res == -ENODATA || res == -EOPNOTSUPP) in ovl_get_fh()
132 return ERR_PTR(-ENOMEM); in ovl_get_fh()
134 res = ovl_getxattr_upper(ofs, upperdentry, ox, fh->buf, res); in ovl_get_fh()
138 err = ovl_check_fb_len(&fh->fb, res); in ovl_get_fh()
140 if (err == -ENODATA) in ovl_get_fh()
169 * Make sure that the stored uuid matches the uuid of the lower in ovl_decode_real_fh()
171 * In case of uuid=off option just make sure that stored uuid is null. in ovl_decode_real_fh()
174 !uuid_equal(&fh->fb.uuid, &mnt->mnt_sb->s_uuid) : in ovl_decode_real_fh()
175 !uuid_is_null(&fh->fb.uuid)) in ovl_decode_real_fh()
178 bytes = (fh->fb.len - offsetof(struct ovl_fb, fid)); in ovl_decode_real_fh()
179 real = exportfs_decode_fh(mnt, (struct fid *)fh->fb.fid, in ovl_decode_real_fh()
180 bytes >> 2, (int)fh->fb.type, in ovl_decode_real_fh()
184 * Treat stale file handle to lower file as "origin unknown". in ovl_decode_real_fh()
189 if (real == ERR_PTR(-ESTALE) && in ovl_decode_real_fh()
190 !(fh->fb.flags & OVL_FH_FLAG_PATH_UPPER)) in ovl_decode_real_fh()
208 struct dentry *ret = lookup_one_unlocked(mnt_idmap(d->layer->mnt), name, in ovl_lookup_positive_unlocked()
211 if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { in ovl_lookup_positive_unlocked()
212 if (drop_negative && ret->d_lockref.count == 1) { in ovl_lookup_positive_unlocked()
213 spin_lock(&ret->d_lock); in ovl_lookup_positive_unlocked()
215 if (d_is_negative(ret) && ret->d_lockref.count == 1) in ovl_lookup_positive_unlocked()
217 spin_unlock(&ret->d_lock); in ovl_lookup_positive_unlocked()
220 ret = ERR_PTR(-ENOENT); in ovl_lookup_positive_unlocked()
230 struct ovl_fs *ofs = OVL_FS(d->sb); in ovl_lookup_single()
235 bool is_upper = d->layer->idx == 0; in ovl_lookup_single()
242 if (err == -ENOENT || err == -ENAMETOOLONG) in ovl_lookup_single()
249 err = -EREMOTE; in ovl_lookup_single()
254 path.mnt = d->layer->mnt; in ovl_lookup_single()
256 d->stop = d->opaque = true; in ovl_lookup_single()
263 if (last_element && d->metacopy && !d_is_reg(this)) { in ovl_lookup_single()
264 d->stop = true; in ovl_lookup_single()
269 if (d->is_dir || !last_element) { in ovl_lookup_single()
270 d->stop = true; in ovl_lookup_single()
277 d->metacopy = err; in ovl_lookup_single()
278 d->stop = !d->metacopy; in ovl_lookup_single()
279 if (!d->metacopy || d->last) in ovl_lookup_single()
282 if (ovl_lookup_trap_inode(d->sb, this)) { in ovl_lookup_single()
284 err = -ELOOP; in ovl_lookup_single()
289 d->is_dir = true; in ovl_lookup_single()
290 if (d->last) in ovl_lookup_single()
296 d->xwhiteouts = true; in ovl_lookup_single()
297 ovl_layer_set_xwhiteouts(ofs, d->layer); in ovl_lookup_single()
299 d->stop = true; in ovl_lookup_single()
301 d->opaque = true; in ovl_lookup_single()
326 size_t rem = d->name.len - 1; in ovl_lookup_layer()
330 if (d->name.name[0] != '/') in ovl_lookup_layer()
331 return ovl_lookup_single(base, d, d->name.name, d->name.len, in ovl_lookup_layer()
335 const char *s = d->name.name + d->name.len - rem; in ovl_lookup_layer()
337 size_t thislen = next - s; in ovl_lookup_layer()
341 if (WARN_ON(s[-1] != '/')) in ovl_lookup_layer()
342 return -EIO; in ovl_lookup_layer()
345 d->name.len - rem, next, &base, in ovl_lookup_layer()
354 rem -= thislen + 1; in ovl_lookup_layer()
356 if (WARN_ON(rem >= d->name.len)) in ovl_lookup_layer()
357 return -EIO; in ovl_lookup_layer()
369 err = vfs_path_lookup(layer->mnt->mnt_root, layer->mnt, redirect, in ovl_lookup_data_layer()
373 dentry, redirect, layer->idx, err); in ovl_lookup_data_layer()
378 err = -EREMOTE; in ovl_lookup_data_layer()
379 if (ovl_dentry_weird(datapath->dentry)) in ovl_lookup_data_layer()
382 err = -ENOENT; in ovl_lookup_data_layer()
383 /* Only regular file is acceptable as lower data */ in ovl_lookup_data_layer()
384 if (!d_is_reg(datapath->dentry)) in ovl_lookup_data_layer()
395 /* Lookup in data-only layers by absolute redirect to layer root */
399 struct ovl_fs *ofs = OVL_FS(dentry->d_sb); in ovl_lookup_data_layers()
402 int err = -ENOENT; in ovl_lookup_data_layers()
405 layer = &ofs->layers[ofs->numlayer - ofs->numdatalayer]; in ovl_lookup_data_layers()
406 for (i = 0; i < ofs->numdatalayer; i++, layer++) { in ovl_lookup_data_layers()
410 lowerdata->dentry = datapath.dentry; in ovl_lookup_data_layers()
411 lowerdata->layer = layer; in ovl_lookup_data_layers()
427 * If lower fs uuid is not unique among lower fs we cannot match in ovl_check_origin_fh()
428 * fh->uuid to layer. in ovl_check_origin_fh()
430 if (ofs->layers[i].fsid && in ovl_check_origin_fh()
431 ofs->layers[i].fs->bad_uuid) in ovl_check_origin_fh()
434 origin = ovl_decode_real_fh(ofs, fh, ofs->layers[i].mnt, in ovl_check_origin_fh()
441 return -ESTALE; in ovl_check_origin_fh()
446 inode_wrong_type(d_inode(upperdentry), d_inode(origin)->i_mode)) in ovl_check_origin_fh()
453 return -ENOMEM; in ovl_check_origin_fh()
457 .layer = &ofs->layers[i] in ovl_check_origin_fh()
464 upperdentry, d_inode(upperdentry)->i_mode & S_IFMT, in ovl_check_origin_fh()
465 d_inode(origin)->i_mode & S_IFMT); in ovl_check_origin_fh()
467 return -ESTALE; in ovl_check_origin_fh()
483 if (err == -ESTALE) in ovl_check_origin()
493 * Return 0 on match, -ESTALE on mismatch, < 0 on error.
502 return -ENODATA; in ovl_verify_fh()
507 if (fh->fb.len != ofh->fb.len || memcmp(&fh->fb, &ofh->fb, fh->fb.len)) in ovl_verify_fh()
508 err = -ESTALE; in ovl_verify_fh()
521 if (set && err == -ENODATA) in ovl_verify_set_fh()
522 err = ovl_setxattr(ofs, dentry, ox, fh->buf, fh->fb.len); in ovl_verify_set_fh()
533 * Return 0 on match, -ESTALE on mismatch, -ENODATA on no xattr, < 0 on error.
562 inode ? inode->i_ino : 0, err); in ovl_verify_origin_xattr()
585 return upper ?: ERR_PTR(-ESTALE); in ovl_index_upper()
591 return ERR_PTR(-EIO); in ovl_index_upper()
599 * OVL_XATTR_ORIGIN and that origin file handle can be decoded to lower path.
600 * Return 0 on match, -ESTALE on mismatch or stale origin, < 0 on error.
614 err = -EINVAL; in ovl_verify_index()
615 if (index->d_name.len < sizeof(struct ovl_fb)*2) in ovl_verify_index()
618 err = -ENOMEM; in ovl_verify_index()
619 len = index->d_name.len / 2; in ovl_verify_index()
624 err = -EINVAL; in ovl_verify_index()
625 if (hex2bin(fh->buf, index->d_name.name, len)) in ovl_verify_index()
628 err = ovl_check_fb_len(&fh->fb, len); in ovl_verify_index()
644 if (d_is_dir(index) && !ofs->config.nfs_export) in ovl_verify_index()
649 * real upper dir. Non-dir index entries are hardlinks to the upper in ovl_verify_index()
650 * real inode. For non-dir index, we can read the copy up origin xattr in ovl_verify_index()
663 if (err == -ESTALE) in ovl_verify_index()
666 err = -ESTALE; in ovl_verify_index()
675 /* Check if non-dir index is orphan and don't warn before cleaning it */ in ovl_verify_index()
676 if (!d_is_dir(index) && d_inode(index)->i_nlink == 1) { in ovl_verify_index()
692 index, d_inode(index)->i_mode & S_IFMT, err); in ovl_verify_index()
697 index, d_inode(index)->i_mode & S_IFMT, in ovl_verify_index()
698 d_inode(index)->i_nlink); in ovl_verify_index()
699 err = -ENOENT; in ovl_verify_index()
707 n = kcalloc(fh->fb.len, 2, GFP_KERNEL); in ovl_get_index_name_fh()
709 return -ENOMEM; in ovl_get_index_name_fh()
711 s = bin2hex(n, fh->buf, fh->fb.len); in ovl_get_index_name_fh()
712 *name = (struct qstr) QSTR_INIT(n, s - n); in ovl_get_index_name_fh()
719 * Lookup in indexdir for the index entry of a lower real inode or a copy up
720 * origin inode. The index entry name is the hex representation of the lower
723 * If the index dentry in negative, then either no lower aliases have been
760 index = lookup_positive_unlocked(name.name, ofs->workdir, name.len); in ovl_get_index_fh()
763 if (PTR_ERR(index) == -ENOENT) in ovl_get_index_fh()
769 err = -ESTALE; in ovl_get_index_fh()
771 err = -EIO; in ovl_get_index_fh()
793 ofs->workdir, name.len); in ovl_lookup_index()
796 if (err == -ENOENT) { in ovl_lookup_index()
801 "overlayfs: mount with '-o index=off' to disable inodes index.\n", in ovl_lookup_index()
802 d_inode(origin)->i_ino, name.len, name.name, in ovl_lookup_index()
816 index = ERR_PTR(-ESTALE); in ovl_lookup_index()
819 inode_wrong_type(inode, d_inode(origin)->i_mode)) { in ovl_lookup_index()
822 * except for the case of a whiteout index. A whiteout in ovl_lookup_index()
823 * index should only exist if all lower aliases have been in ovl_lookup_index()
824 * unlinked, which means that finding a lower origin on lookup in ovl_lookup_index()
828 index, d_inode(index)->i_mode & S_IFMT, in ovl_lookup_index()
829 d_inode(origin)->i_mode & S_IFMT); in ovl_lookup_index()
841 if (err == -ESTALE) { in ovl_lookup_index()
861 index = ERR_PTR(-EIO); in ovl_lookup_index()
867 * Returns -1 if this is the last layer.
878 if (path->dentry) { in ovl_path_next()
879 *layer = &OVL_FS(dentry->d_sb)->layers[0]; in ovl_path_next()
880 return ovl_numlower(oe) ? 1 : -1; in ovl_path_next()
885 path->dentry = lowerstack[idx - 1].dentry; in ovl_path_next()
886 *layer = lowerstack[idx - 1].layer; in ovl_path_next()
887 path->mnt = (*layer)->mnt; in ovl_path_next()
889 return (idx < ovl_numlower(oe)) ? idx + 1 : -1; in ovl_path_next()
894 struct dentry *lower, struct dentry *upper) in ovl_fix_origin() argument
902 fh = ovl_get_origin_fh(ofs, lower); in ovl_fix_origin()
912 err = ovl_set_impure(dentry->d_parent, upper->d_parent); in ovl_fix_origin()
922 struct ovl_fs *ofs = OVL_FS(dentry->d_sb); in ovl_maybe_validate_verity()
927 if (!ofs->config.verity_mode || in ovl_maybe_validate_verity()
933 if (ofs->config.verity_mode == OVL_VERITY_REQUIRE) { in ovl_maybe_validate_verity()
936 return -EIO; in ovl_maybe_validate_verity()
943 return -EIO; in ovl_maybe_validate_verity()
947 return -EIO; in ovl_maybe_validate_verity()
956 old_cred = ovl_override_creds(dentry->d_sb); in ovl_maybe_validate_verity()
983 return -EIO; in ovl_maybe_lookup_lowerdata()
994 old_cred = ovl_override_creds(dentry->d_sb); in ovl_maybe_lookup_lowerdata()
1032 struct ovl_fs *ofs = OVL_FS(dentry->d_sb); in ovl_lookup()
1033 struct ovl_entry *poe = OVL_E(dentry->d_parent); in ovl_lookup()
1034 struct ovl_entry *roe = OVL_E(dentry->d_sb->s_root); in ovl_lookup()
1049 .sb = dentry->d_sb, in ovl_lookup()
1050 .name = dentry->d_name, in ovl_lookup()
1059 if (dentry->d_name.len > ofs->namelen) in ovl_lookup()
1060 return ERR_PTR(-ENAMETOOLONG); in ovl_lookup()
1062 old_cred = ovl_override_creds(dentry->d_sb); in ovl_lookup()
1063 upperdir = ovl_dentry_upper(dentry->d_parent); in ovl_lookup()
1065 d.layer = &ofs->layers[0]; in ovl_lookup()
1070 if (upperdentry && upperdentry->d_flags & DCACHE_OP_REAL) { in ovl_lookup()
1072 err = -EREMOTE; in ovl_lookup()
1081 * connected dentry, that is not under any of the lower in ovl_lookup()
1083 * number - it's the same as if we held a reference in ovl_lookup()
1084 * to a dentry in lower layer that was moved under us. in ovl_lookup()
1096 err = -ENOMEM; in ovl_lookup()
1107 err = -ENOMEM; in ovl_lookup()
1108 stack = ovl_stack_alloc(ofs->numlayer - 1); in ovl_lookup()
1114 struct ovl_path lower = ovl_lowerstack(poe)[i]; in ovl_lookup() local
1117 d.last = i == ovl_numlower(poe) - 1; in ovl_lookup()
1118 else if (d.is_dir || !ofs->numdatalayer) in ovl_lookup()
1119 d.last = lower.layer->idx == ovl_numlower(roe); in ovl_lookup()
1121 d.layer = lower.layer; in ovl_lookup()
1122 err = ovl_lookup_layer(lower.dentry, &d, &this, false); in ovl_lookup()
1129 if ((uppermetacopy || d.metacopy) && !ofs->config.metacopy) { in ovl_lookup()
1131 err = -EPERM; in ovl_lookup()
1138 * of lower dir and set upper parent "impure". in ovl_lookup()
1140 if (upperdentry && !ctr && !ofs->noxattr && d.is_dir) { in ovl_lookup()
1150 * lower dir that does not match a stored origin xattr. In any in ovl_lookup()
1151 * case, only verified origin is used for index lookup. in ovl_lookup()
1153 * For non-dir dentry, if index=on, then ensure origin in ovl_lookup()
1158 ((d.is_dir && ovl_verify_lower(dentry->d_sb)) || in ovl_lookup()
1159 (!d.is_dir && ofs->config.index && origin_path))) { in ovl_lookup()
1176 * lower chain, except top most lower metacopy dentry. in ovl_lookup()
1184 stack[ctr].layer = lower.layer; in ovl_lookup()
1190 * a symlink into the lower layer without the permission checks. in ovl_lookup()
1192 * comes from an USB drive). This can allow a non-readable file in ovl_lookup()
1198 err = -EPERM; in ovl_lookup()
1211 i = lower.layer->idx - 1; in ovl_lookup()
1215 /* Defer lookup of lowerdata in data-only layers to first access */ in ovl_lookup()
1216 if (d.metacopy && ctr && ofs->numdatalayer && d.absolute_redirect) { in ovl_lookup()
1222 * For regular non-metacopy upper dentries, there is no lower in ovl_lookup()
1226 * For metacopy dentry, path based lookup will find lower dentries. in ovl_lookup()
1230 pr_warn_ratelimited("metacopy with no lower data found - abort lookup (%pd2)\n", in ovl_lookup()
1232 err = -EIO; in ovl_lookup()
1236 err = -EIO; in ovl_lookup()
1241 origin = origin_path->dentry; in ovl_lookup()
1246 * Always lookup index if there is no-upperdentry. in ovl_lookup()
1248 * For the case of upperdentry, we have set origin by now if it in ovl_lookup()
1251 * For directories, lookup index by lower inode and verify it matches in ovl_lookup()
1252 * upper inode. We only trust dir index if we verified that lower dir in ovl_lookup()
1258 * based dentry lookup in lower in this case. in ovl_lookup()
1267 if (origin && ovl_indexdir(dentry->d_sb) && in ovl_lookup()
1268 (!d.is_dir || ovl_index_all(dentry->d_sb))) { in ovl_lookup()
1279 err = -ENOMEM; in ovl_lookup()
1301 * assignment of happens only if upperdentry is non-NULL, and in ovl_lookup()
1326 if (ctr > 1 && !d.is_dir && !stack[ctr - 1].dentry) { in ovl_lookup()
1330 inode = ovl_get_inode(dentry->d_sb, &oip); in ovl_lookup()
1345 dput(origin_path->dentry); in ovl_lookup()
1360 dput(origin_path->dentry); in ovl_lookup()
1373 struct ovl_entry *poe = OVL_E(dentry->d_parent); in ovl_lower_positive()
1374 const struct qstr *name = &dentry->d_name; in ovl_lower_positive()
1381 * If dentry is negative, then lower is positive iff this is a in ovl_lower_positive()
1384 if (!dentry->d_inode) in ovl_lower_positive()
1387 /* Negative upper -> positive lower */ in ovl_lower_positive()
1391 old_cred = ovl_override_creds(dentry->d_sb); in ovl_lower_positive()
1392 /* Positive upper -> have to look up lower to see whether it exists */ in ovl_lower_positive()
1398 mnt_idmap(parentpath->layer->mnt), in ovl_lower_positive()
1399 name->name, parentpath->dentry, name->len); in ovl_lower_positive()
1402 case -ENOENT: in ovl_lower_positive()
1403 case -ENAMETOOLONG: in ovl_lower_positive()
1417 .mnt = parentpath->layer->mnt, in ovl_lower_positive()
1419 positive = !ovl_path_is_whiteout(OVL_FS(dentry->d_sb), &path); in ovl_lower_positive()