Skip to content

Commit 1795ca6

Browse files
committed
Revert "ovl: do not encode lower fh with upper sb_writers held"
This reverts commit 26423e1 which is commit 5b02bfc upstream. It is reported to part of a series that causes problems in the 6.6.y tree, so revert it at this point in time and it can come back later if still needed. Reported-by: Ignat Korchagin <ignat@cloudflare.com> Link: https://lore.kernel.org/r/ACD4D6CC-C4D5-4657-A805-03C34559046E@cloudflare.com Cc: Dmitry Safonov <dima@arista.com> Cc: Amir Goldstein <amir73il@gmail.com> Cc: Christian Brauner <brauner@kernel.org> Cc: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d1c53de commit 1795ca6

File tree

5 files changed

+42
-104
lines changed

5 files changed

+42
-104
lines changed

fs/overlayfs/copy_up.c

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -426,29 +426,29 @@ struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
426426
return ERR_PTR(err);
427427
}
428428

429-
struct ovl_fh *ovl_get_origin_fh(struct ovl_fs *ofs, struct dentry *origin)
429+
int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower,
430+
struct dentry *upper)
430431
{
432+
const struct ovl_fh *fh = NULL;
433+
int err;
434+
431435
/*
432436
* When lower layer doesn't support export operations store a 'null' fh,
433437
* so we can use the overlay.origin xattr to distignuish between a copy
434438
* up and a pure upper inode.
435439
*/
436-
if (!ovl_can_decode_fh(origin->d_sb))
437-
return NULL;
438-
439-
return ovl_encode_real_fh(ofs, origin, false);
440-
}
441-
442-
int ovl_set_origin_fh(struct ovl_fs *ofs, const struct ovl_fh *fh,
443-
struct dentry *upper)
444-
{
445-
int err;
440+
if (ovl_can_decode_fh(lower->d_sb)) {
441+
fh = ovl_encode_real_fh(ofs, lower, false);
442+
if (IS_ERR(fh))
443+
return PTR_ERR(fh);
444+
}
446445

447446
/*
448447
* Do not fail when upper doesn't support xattrs.
449448
*/
450449
err = ovl_check_setxattr(ofs, upper, OVL_XATTR_ORIGIN, fh->buf,
451450
fh ? fh->fb.len : 0, 0);
451+
kfree(fh);
452452

453453
/* Ignore -EPERM from setting "user.*" on symlink/special */
454454
return err == -EPERM ? 0 : err;
@@ -476,7 +476,7 @@ static int ovl_set_upper_fh(struct ovl_fs *ofs, struct dentry *upper,
476476
*
477477
* Caller must hold i_mutex on indexdir.
478478
*/
479-
static int ovl_create_index(struct dentry *dentry, const struct ovl_fh *fh,
479+
static int ovl_create_index(struct dentry *dentry, struct dentry *origin,
480480
struct dentry *upper)
481481
{
482482
struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
@@ -502,7 +502,7 @@ static int ovl_create_index(struct dentry *dentry, const struct ovl_fh *fh,
502502
if (WARN_ON(ovl_test_flag(OVL_INDEX, d_inode(dentry))))
503503
return -EIO;
504504

505-
err = ovl_get_index_name_fh(fh, &name);
505+
err = ovl_get_index_name(ofs, origin, &name);
506506
if (err)
507507
return err;
508508

@@ -541,7 +541,6 @@ struct ovl_copy_up_ctx {
541541
struct dentry *destdir;
542542
struct qstr destname;
543543
struct dentry *workdir;
544-
const struct ovl_fh *origin_fh;
545544
bool origin;
546545
bool indexed;
547546
bool metacopy;
@@ -638,7 +637,7 @@ static int ovl_copy_up_metadata(struct ovl_copy_up_ctx *c, struct dentry *temp)
638637
* hard link.
639638
*/
640639
if (c->origin) {
641-
err = ovl_set_origin_fh(ofs, c->origin_fh, temp);
640+
err = ovl_set_origin(ofs, c->lowerpath.dentry, temp);
642641
if (err)
643642
return err;
644643
}
@@ -750,7 +749,7 @@ static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)
750749
goto cleanup;
751750

752751
if (S_ISDIR(c->stat.mode) && c->indexed) {
753-
err = ovl_create_index(c->dentry, c->origin_fh, temp);
752+
err = ovl_create_index(c->dentry, c->lowerpath.dentry, temp);
754753
if (err)
755754
goto cleanup;
756755
}
@@ -862,8 +861,6 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
862861
{
863862
int err;
864863
struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
865-
struct dentry *origin = c->lowerpath.dentry;
866-
struct ovl_fh *fh = NULL;
867864
bool to_index = false;
868865

869866
/*
@@ -880,33 +877,25 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
880877
to_index = true;
881878
}
882879

883-
if (S_ISDIR(c->stat.mode) || c->stat.nlink == 1 || to_index) {
884-
fh = ovl_get_origin_fh(ofs, origin);
885-
if (IS_ERR(fh))
886-
return PTR_ERR(fh);
887-
888-
/* origin_fh may be NULL */
889-
c->origin_fh = fh;
880+
if (S_ISDIR(c->stat.mode) || c->stat.nlink == 1 || to_index)
890881
c->origin = true;
891-
}
892882

893883
if (to_index) {
894884
c->destdir = ovl_indexdir(c->dentry->d_sb);
895-
err = ovl_get_index_name(ofs, origin, &c->destname);
885+
err = ovl_get_index_name(ofs, c->lowerpath.dentry, &c->destname);
896886
if (err)
897-
goto out_free_fh;
887+
return err;
898888
} else if (WARN_ON(!c->parent)) {
899889
/* Disconnected dentry must be copied up to index dir */
900-
err = -EIO;
901-
goto out_free_fh;
890+
return -EIO;
902891
} else {
903892
/*
904893
* Mark parent "impure" because it may now contain non-pure
905894
* upper
906895
*/
907896
err = ovl_set_impure(c->parent, c->destdir);
908897
if (err)
909-
goto out_free_fh;
898+
return err;
910899
}
911900

912901
/* Should we copyup with O_TMPFILE or with workdir? */
@@ -938,8 +927,6 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
938927
out:
939928
if (to_index)
940929
kfree(c->destname.name);
941-
out_free_fh:
942-
kfree(fh);
943930
return err;
944931
}
945932

fs/overlayfs/namei.c

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -507,19 +507,6 @@ static int ovl_verify_fh(struct ovl_fs *ofs, struct dentry *dentry,
507507
return err;
508508
}
509509

510-
int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry,
511-
enum ovl_xattr ox, const struct ovl_fh *fh,
512-
bool is_upper, bool set)
513-
{
514-
int err;
515-
516-
err = ovl_verify_fh(ofs, dentry, ox, fh);
517-
if (set && err == -ENODATA)
518-
err = ovl_setxattr(ofs, dentry, ox, fh->buf, fh->fb.len);
519-
520-
return err;
521-
}
522-
523510
/*
524511
* Verify that @real dentry matches the file handle stored in xattr @name.
525512
*
@@ -528,9 +515,9 @@ int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry,
528515
*
529516
* Return 0 on match, -ESTALE on mismatch, -ENODATA on no xattr, < 0 on error.
530517
*/
531-
int ovl_verify_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry,
532-
enum ovl_xattr ox, struct dentry *real,
533-
bool is_upper, bool set)
518+
int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry,
519+
enum ovl_xattr ox, struct dentry *real, bool is_upper,
520+
bool set)
534521
{
535522
struct inode *inode;
536523
struct ovl_fh *fh;
@@ -543,7 +530,9 @@ int ovl_verify_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry,
543530
goto fail;
544531
}
545532

546-
err = ovl_verify_set_fh(ofs, dentry, ox, fh, is_upper, set);
533+
err = ovl_verify_fh(ofs, dentry, ox, fh);
534+
if (set && err == -ENODATA)
535+
err = ovl_setxattr(ofs, dentry, ox, fh->buf, fh->fb.len);
547536
if (err)
548537
goto fail;
549538

@@ -559,7 +548,6 @@ int ovl_verify_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry,
559548
goto out;
560549
}
561550

562-
563551
/* Get upper dentry from index */
564552
struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index,
565553
bool connected)
@@ -696,7 +684,7 @@ int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index)
696684
goto out;
697685
}
698686

699-
int ovl_get_index_name_fh(const struct ovl_fh *fh, struct qstr *name)
687+
static int ovl_get_index_name_fh(struct ovl_fh *fh, struct qstr *name)
700688
{
701689
char *n, *s;
702690

@@ -885,27 +873,20 @@ int ovl_path_next(int idx, struct dentry *dentry, struct path *path)
885873
static int ovl_fix_origin(struct ovl_fs *ofs, struct dentry *dentry,
886874
struct dentry *lower, struct dentry *upper)
887875
{
888-
const struct ovl_fh *fh;
889876
int err;
890877

891878
if (ovl_check_origin_xattr(ofs, upper))
892879
return 0;
893880

894-
fh = ovl_get_origin_fh(ofs, lower);
895-
if (IS_ERR(fh))
896-
return PTR_ERR(fh);
897-
898881
err = ovl_want_write(dentry);
899882
if (err)
900-
goto out;
883+
return err;
901884

902-
err = ovl_set_origin_fh(ofs, fh, upper);
885+
err = ovl_set_origin(ofs, lower, upper);
903886
if (!err)
904887
err = ovl_set_impure(dentry->d_parent, upper->d_parent);
905888

906889
ovl_drop_write(dentry);
907-
out:
908-
kfree(fh);
909890
return err;
910891
}
911892

fs/overlayfs/overlayfs.h

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -632,15 +632,11 @@ struct dentry *ovl_decode_real_fh(struct ovl_fs *ofs, struct ovl_fh *fh,
632632
int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected,
633633
struct dentry *upperdentry, struct ovl_path **stackp);
634634
int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry,
635-
enum ovl_xattr ox, const struct ovl_fh *fh,
636-
bool is_upper, bool set);
637-
int ovl_verify_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry,
638-
enum ovl_xattr ox, struct dentry *real,
639-
bool is_upper, bool set);
635+
enum ovl_xattr ox, struct dentry *real, bool is_upper,
636+
bool set);
640637
struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index,
641638
bool connected);
642639
int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index);
643-
int ovl_get_index_name_fh(const struct ovl_fh *fh, struct qstr *name);
644640
int ovl_get_index_name(struct ovl_fs *ofs, struct dentry *origin,
645641
struct qstr *name);
646642
struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh);
@@ -652,24 +648,17 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
652648
unsigned int flags);
653649
bool ovl_lower_positive(struct dentry *dentry);
654650

655-
static inline int ovl_verify_origin_fh(struct ovl_fs *ofs, struct dentry *upper,
656-
const struct ovl_fh *fh, bool set)
657-
{
658-
return ovl_verify_set_fh(ofs, upper, OVL_XATTR_ORIGIN, fh, false, set);
659-
}
660-
661651
static inline int ovl_verify_origin(struct ovl_fs *ofs, struct dentry *upper,
662652
struct dentry *origin, bool set)
663653
{
664-
return ovl_verify_origin_xattr(ofs, upper, OVL_XATTR_ORIGIN, origin,
665-
false, set);
654+
return ovl_verify_set_fh(ofs, upper, OVL_XATTR_ORIGIN, origin,
655+
false, set);
666656
}
667657

668658
static inline int ovl_verify_upper(struct ovl_fs *ofs, struct dentry *index,
669659
struct dentry *upper, bool set)
670660
{
671-
return ovl_verify_origin_xattr(ofs, index, OVL_XATTR_UPPER, upper,
672-
true, set);
661+
return ovl_verify_set_fh(ofs, index, OVL_XATTR_UPPER, upper, true, set);
673662
}
674663

675664
/* readdir.c */
@@ -834,9 +823,8 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *path, struct dentr
834823
int ovl_set_attr(struct ovl_fs *ofs, struct dentry *upper, struct kstat *stat);
835824
struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
836825
bool is_upper);
837-
struct ovl_fh *ovl_get_origin_fh(struct ovl_fs *ofs, struct dentry *origin);
838-
int ovl_set_origin_fh(struct ovl_fs *ofs, const struct ovl_fh *fh,
839-
struct dentry *upper);
826+
int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower,
827+
struct dentry *upper);
840828

841829
/* export.c */
842830
extern const struct export_operations ovl_export_operations;

fs/overlayfs/super.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -879,20 +879,15 @@ static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs,
879879
{
880880
struct vfsmount *mnt = ovl_upper_mnt(ofs);
881881
struct dentry *indexdir;
882-
struct dentry *origin = ovl_lowerstack(oe)->dentry;
883-
const struct ovl_fh *fh;
884882
int err;
885883

886-
fh = ovl_get_origin_fh(ofs, origin);
887-
if (IS_ERR(fh))
888-
return PTR_ERR(fh);
889-
890884
err = mnt_want_write(mnt);
891885
if (err)
892-
goto out_free_fh;
886+
return err;
893887

894888
/* Verify lower root is upper root origin */
895-
err = ovl_verify_origin_fh(ofs, upperpath->dentry, fh, true);
889+
err = ovl_verify_origin(ofs, upperpath->dentry,
890+
ovl_lowerstack(oe)->dentry, true);
896891
if (err) {
897892
pr_err("failed to verify upper root origin\n");
898893
goto out;
@@ -924,10 +919,9 @@ static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs,
924919
* directory entries.
925920
*/
926921
if (ovl_check_origin_xattr(ofs, ofs->indexdir)) {
927-
err = ovl_verify_origin_xattr(ofs, ofs->indexdir,
928-
OVL_XATTR_ORIGIN,
929-
upperpath->dentry, true,
930-
false);
922+
err = ovl_verify_set_fh(ofs, ofs->indexdir,
923+
OVL_XATTR_ORIGIN,
924+
upperpath->dentry, true, false);
931925
if (err)
932926
pr_err("failed to verify index dir 'origin' xattr\n");
933927
}
@@ -945,8 +939,6 @@ static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs,
945939

946940
out:
947941
mnt_drop_write(mnt);
948-
out_free_fh:
949-
kfree(fh);
950942
return err;
951943
}
952944

fs/overlayfs/util.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -976,18 +976,12 @@ static void ovl_cleanup_index(struct dentry *dentry)
976976
struct dentry *index = NULL;
977977
struct inode *inode;
978978
struct qstr name = { };
979-
bool got_write = false;
980979
int err;
981980

982981
err = ovl_get_index_name(ofs, lowerdentry, &name);
983982
if (err)
984983
goto fail;
985984

986-
err = ovl_want_write(dentry);
987-
if (err)
988-
goto fail;
989-
990-
got_write = true;
991985
inode = d_inode(upperdentry);
992986
if (!S_ISDIR(inode->i_mode) && inode->i_nlink != 1) {
993987
pr_warn_ratelimited("cleanup linked index (%pd2, ino=%lu, nlink=%u)\n",
@@ -1025,8 +1019,6 @@ static void ovl_cleanup_index(struct dentry *dentry)
10251019
goto fail;
10261020

10271021
out:
1028-
if (got_write)
1029-
ovl_drop_write(dentry);
10301022
kfree(name.name);
10311023
dput(index);
10321024
return;
@@ -1097,8 +1089,6 @@ void ovl_nlink_end(struct dentry *dentry)
10971089
{
10981090
struct inode *inode = d_inode(dentry);
10991091

1100-
ovl_drop_write(dentry);
1101-
11021092
if (ovl_test_flag(OVL_INDEX, inode) && inode->i_nlink == 0) {
11031093
const struct cred *old_cred;
11041094

0 commit comments

Comments
 (0)