History

Merge tag 'ovl-fixes-5.8-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs into master

Pull overlayfs fixes from Miklos Szeredi: - fix a regression introduced in v4.20 in handling a regenerated squashfs lower layer - two regression fixes for this cycle, one of which is Oops inducing - miscellaneous issues * tag 'ovl-fixes-5.8-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs: ovl: fix lookup of indexed hardlinks with metacopy ovl: fix unneeded call to ovl_change_flags() ovl: fix mount option checks for nfs_export with no upperdir ovl: force read-only sb on failure to create index dir ovl: fix regression with re-formatted lower squashfs ovl: fix oops in ovl_indexdir_cleanup() with nfs_export=on ovl: relax WARN_ON() when decoding lower directory file handle ovl: remove not used argument in ovl_check_origin ovl: change ovl_copy_up_flags static ovl: inode reference leak in ovl_is_inuse true case.

Linus Torvalds committed 6 years ago

Commit 44fea372 parents 33b9108 4518dfc7 files · +65 −42Browse files

Unified · Split

7 files
  1. Documentation/filesystems/overlayfs.rst +2 −2
  2. fs/overlayfs/copy_up.c +1 −1
  3. fs/overlayfs/export.c +1 −1
  4. fs/overlayfs/file.c +6 −4
  5. fs/overlayfs/namei.c +6 −9
  6. fs/overlayfs/overlayfs.h +0 −1
  7. fs/overlayfs/super.c +49 −24
Documentation/filesystems/overlayfs.rst+2−2
@@ -560,8 +560,8 @@ When the NFS export feature is enabled, all directory index entries are · 559 unmodified lines
560560 verified on mount time to check that upper file handles are not stale.
561561 This verification may cause significant overhead in some cases.
562562
563−Note: the mount options index=off,nfs_export=on are conflicting and will
564−result in an error.
563+Note: the mount options index=off,nfs_export=on are conflicting for a
564+read-write mount and will result in an error.
565565
566566
567567 Testsuite
fs/overlayfs/copy_up.c+1−1
@@ -895,7 +895,7 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry, · 894 unmodified lines
895895 return err;
896896 }
897897
898−int ovl_copy_up_flags(struct dentry *dentry, int flags)
898+static int ovl_copy_up_flags(struct dentry *dentry, int flags)
899899 {
900900 int err = 0;
901901 const struct cred *old_cred = ovl_override_creds(dentry->d_sb);
fs/overlayfs/export.c+1−1
@@ -476,7 +476,7 @@ static struct dentry *ovl_lookup_real_inode(struct super_block *sb, · 475 unmodified lines
476476 if (IS_ERR_OR_NULL(this))
477477 return this;
478478
479− if (WARN_ON(ovl_dentry_real_at(this, layer->idx) != real)) {
479+ if (ovl_dentry_real_at(this, layer->idx) != real) {
480480 dput(this);
481481 this = ERR_PTR(-EIO);
482482 }
fs/overlayfs/file.c+6−4
@@ -33,13 +33,16 @@ static char ovl_whatisit(struct inode *inode, struct inode *realinode) · 32 unmodified lines
3333 return 'm';
3434 }
3535
36+/* No atime modificaton nor notify on underlying */
37+#define OVL_OPEN_FLAGS (O_NOATIME | FMODE_NONOTIFY)
38+
3639 static struct file *ovl_open_realfile(const struct file *file,
3740 struct inode *realinode)
3841 {
3942 struct inode *inode = file_inode(file);
4043 struct file *realfile;
4144 const struct cred *old_cred;
42− int flags = file->f_flags | O_NOATIME | FMODE_NONOTIFY;
45+ int flags = file->f_flags | OVL_OPEN_FLAGS;
4346 int acc_mode = ACC_MODE(flags);
4447 int err;
4548
@@ -72,8 +75,7 @@ static int ovl_change_flags(struct file *file, unsigned int flags) · 26 unmodified lines
7275 struct inode *inode = file_inode(file);
7376 int err;
7477
75− /* No atime modificaton on underlying */
76− flags |= O_NOATIME | FMODE_NONOTIFY;
78+ flags |= OVL_OPEN_FLAGS;
7779
7880 /* If some flag changed that cannot be changed then something's amiss */
7981 if (WARN_ON((file->f_flags ^ flags) & ~OVL_SETFL_MASK))
@@ -126,7 +128,7 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real, · 46 unmodified lines
126128 }
127129
128130 /* Did the flags change since open? */
129− if (unlikely((file->f_flags ^ real->file->f_flags) & ~O_NOATIME))
131+ if (unlikely((file->f_flags ^ real->file->f_flags) & ~OVL_OPEN_FLAGS))
130132 return ovl_change_flags(real->file, file->f_flags);
131133
132134 return 0;
fs/overlayfs/namei.c+6−9
@@ -389,7 +389,7 @@ invalid: · 388 unmodified lines
389389 }
390390
391391 static int ovl_check_origin(struct ovl_fs *ofs, struct dentry *upperdentry,
392− struct ovl_path **stackp, unsigned int *ctrp)
392+ struct ovl_path **stackp)
393393 {
394394 struct ovl_fh *fh = ovl_get_fh(upperdentry, OVL_XATTR_ORIGIN);
395395 int err;
@@ -406,10 +406,6 @@ static int ovl_check_origin(struct ovl_fs *ofs, struct dentry *upperdentry, · 10 unmodified lines
406406 return err;
407407 }
408408
409− if (WARN_ON(*ctrp))
410− return -EIO;
411−
412− *ctrp = 1;
413409 return 0;
414410 }
415411
@@ -861,8 +857,6 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, · 445 unmodified lines
861857 goto out;
862858 }
863859 if (upperdentry && !d.is_dir) {
864− unsigned int origin_ctr = 0;
865−
866860 /*
867861 * Lookup copy up origin by decoding origin file handle.
868862 * We may get a disconnected dentry, which is fine,
@@ -873,8 +867,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, · 4 unmodified lines
873867 * number - it's the same as if we held a reference
874868 * to a dentry in lower layer that was moved under us.
875869 */
876− err = ovl_check_origin(ofs, upperdentry, &origin_path,
877− &origin_ctr);
870+ err = ovl_check_origin(ofs, upperdentry, &origin_path);
878871 if (err)
879872 goto out_put_upper;
880873
@@ -1073,6 +1066,10 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, · 192 unmodified lines
10731066 upperredirect = NULL;
10741067 goto out_free_oe;
10751068 }
1069+ err = ovl_check_metacopy_xattr(upperdentry);
1070+ if (err < 0)
1071+ goto out_free_oe;
1072+ uppermetacopy = err;
10761073 }
10771074
10781075 if (upperdentry || ctr) {
fs/overlayfs/overlayfs.h+0−1
@@ -483,7 +483,6 @@ void ovl_aio_request_cache_destroy(void); · 482 unmodified lines
483483 /* copy_up.c */
484484 int ovl_copy_up(struct dentry *dentry);
485485 int ovl_copy_up_with_data(struct dentry *dentry);
486−int ovl_copy_up_flags(struct dentry *dentry, int flags);
487486 int ovl_maybe_copy_up(struct dentry *dentry, int flags);
488487 int ovl_copy_xattr(struct dentry *old, struct dentry *new);
489488 int ovl_set_attr(struct dentry *upper, struct kstat *stat);
fs/overlayfs/super.c+49−24
@@ -580,12 +580,19 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config) · 579 unmodified lines
580580 }
581581 }
582582
583− /* Workdir is useless in non-upper mount */
584− if (!config->upperdir && config->workdir) {
585− pr_info("option \"workdir=%s\" is useless in a non-upper mount, ignore\n",
586− config->workdir);
587− kfree(config->workdir);
588− config->workdir = NULL;
583+ /* Workdir/index are useless in non-upper mount */
584+ if (!config->upperdir) {
585+ if (config->workdir) {
586+ pr_info("option \"workdir=%s\" is useless in a non-upper mount, ignore\n",
587+ config->workdir);
588+ kfree(config->workdir);
589+ config->workdir = NULL;
590+ }
591+ if (config->index && index_opt) {
592+ pr_info("option \"index=on\" is useless in a non-upper mount, ignore\n");
593+ index_opt = false;
594+ }
595+ config->index = false;
589596 }
590597
591598 err = ovl_parse_redirect_mode(config, config->redirect_mode);
@@ -622,11 +629,13 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config) · 30 unmodified lines
622629
623630 /* Resolve nfs_export -> index dependency */
624631 if (config->nfs_export && !config->index) {
625− if (nfs_export_opt && index_opt) {
632+ if (!config->upperdir && config->redirect_follow) {
633+ pr_info("NFS export requires \"redirect_dir=nofollow\" on non-upper mount, falling back to nfs_export=off.\n");
634+ config->nfs_export = false;
635+ } else if (nfs_export_opt && index_opt) {
626636 pr_err("conflicting options: nfs_export=on,index=off\n");
627637 return -EINVAL;
628− }
629− if (index_opt) {
638+ } else if (index_opt) {
630639 /*
631640 * There was an explicit index=off that resulted
632641 * in this conflict.
@@ -1352,8 +1361,15 @@ static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs, · 719 unmodified lines
13521361 goto out;
13531362 }
13541363
1364+ /* index dir will act also as workdir */
1365+ iput(ofs->workdir_trap);
1366+ ofs->workdir_trap = NULL;
1367+ dput(ofs->workdir);
1368+ ofs->workdir = NULL;
13551369 ofs->indexdir = ovl_workdir_create(ofs, OVL_INDEXDIR_NAME, true);
13561370 if (ofs->indexdir) {
1371+ ofs->workdir = dget(ofs->indexdir);
1372+
13571373 err = ovl_setup_trap(sb, ofs->indexdir, &ofs->indexdir_trap,
13581374 "indexdir");
13591375 if (err)
@@ -1396,6 +1412,18 @@ static bool ovl_lower_uuid_ok(struct ovl_fs *ofs, const uuid_t *uuid) · 36 unmodified lines
13961412 if (!ofs->config.nfs_export && !ovl_upper_mnt(ofs))
13971413 return true;
13981414
1415+ /*
1416+ * We allow using single lower with null uuid for index and nfs_export
1417+ * for example to support those features with single lower squashfs.
1418+ * To avoid regressions in setups of overlay with re-formatted lower
1419+ * squashfs, do not allow decoding origin with lower null uuid unless
1420+ * user opted-in to one of the new features that require following the
1421+ * lower inode of non-dir upper.
1422+ */
1423+ if (!ofs->config.index && !ofs->config.metacopy && !ofs->config.xino &&
1424+ uuid_is_null(uuid))
1425+ return false;
1426+
13991427 for (i = 0; i < ofs->numfs; i++) {
14001428 /*
14011429 * We use uuid to associate an overlay lower file handle with a
@@ -1493,14 +1521,23 @@ static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs, · 91 unmodified lines
14931521 if (err < 0)
14941522 goto out;
14951523
1524+ /*
1525+ * Check if lower root conflicts with this overlay layers before
1526+ * checking if it is in-use as upperdir/workdir of "another"
1527+ * mount, because we do not bother to check in ovl_is_inuse() if
1528+ * the upperdir/workdir is in fact in-use by our
1529+ * upperdir/workdir.
1530+ */
14961531 err = ovl_setup_trap(sb, stack[i].dentry, &trap, "lowerdir");
14971532 if (err)
14981533 goto out;
14991534
15001535 if (ovl_is_inuse(stack[i].dentry)) {
15011536 err = ovl_report_in_use(ofs, "lowerdir");
1502− if (err)
1537+ if (err) {
1538+ iput(trap);
15031539 goto out;
1540+ }
15041541 }
15051542
15061543 mnt = clone_private_mount(&stack[i]);
@@ -1575,10 +1612,6 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb, · 68 unmodified lines
15751612 if (!ofs->config.upperdir && numlower == 1) {
15761613 pr_err("at least 2 lowerdir are needed while upperdir nonexistent\n");
15771614 return ERR_PTR(-EINVAL);
1578− } else if (!ofs->config.upperdir && ofs->config.nfs_export &&
1579− ofs->config.redirect_follow) {
1580− pr_warn("NFS export requires \"redirect_dir=nofollow\" on non-upper mount, falling back to nfs_export=off.\n");
1581− ofs->config.nfs_export = false;
15821615 }
15831616
15841617 stack = kcalloc(numlower, sizeof(struct path), GFP_KERNEL);
@@ -1842,21 +1875,13 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) · 257 unmodified lines
18421875 if (!ovl_upper_mnt(ofs))
18431876 sb->s_flags |= SB_RDONLY;
18441877
1845− if (!(ovl_force_readonly(ofs)) && ofs->config.index) {
1846− /* index dir will act also as workdir */
1847− dput(ofs->workdir);
1848− ofs->workdir = NULL;
1849− iput(ofs->workdir_trap);
1850− ofs->workdir_trap = NULL;
1851−
1878+ if (!ovl_force_readonly(ofs) && ofs->config.index) {
18521879 err = ovl_get_indexdir(sb, ofs, oe, &upperpath);
18531880 if (err)
18541881 goto out_free_oe;
18551882
18561883 /* Force r/o mount with no index dir */
1857− if (ofs->indexdir)
1858− ofs->workdir = dget(ofs->indexdir);
1859− else
1884+ if (!ofs->indexdir)
18601885 sb->s_flags |= SB_RDONLY;
18611886 }
18621887

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t