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
560verified on mount time to check that upper file handles are not stale.560verified on mount time to check that upper file handles are not stale.
561This verification may cause significant overhead in some cases.561This verification may cause significant overhead in some cases.
562 562
563Note: the mount options index=off,nfs_export=on are conflicting and will563Note: the mount options index=off,nfs_export=on are conflicting for a
564result in an error.564read-write mount and will result in an error.
565 565
566 566
567Testsuite567Testsuite
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
895 return err;895 return err;
896}896}
897 897
898int ovl_copy_up_flags(struct dentry *dentry, int flags)898static int ovl_copy_up_flags(struct dentry *dentry, int flags)
899{899{
900 int err = 0;900 int err = 0;
901 const struct cred *old_cred = ovl_override_creds(dentry->d_sb);901 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
476 if (IS_ERR_OR_NULL(this))476 if (IS_ERR_OR_NULL(this))
477 return this;477 return this;
478 478
479 if (WARN_ON(ovl_dentry_real_at(this, layer->idx) != real)) {479 if (ovl_dentry_real_at(this, layer->idx) != real) {
480 dput(this);480 dput(this);
481 this = ERR_PTR(-EIO);481 this = ERR_PTR(-EIO);
482 }482 }
fs/overlayfs/file.c+6−4
@@ -33,13 +33,16 @@ static char ovl_whatisit(struct inode *inode, struct inode *realinode) · 32 unmodified lines
33 return 'm';33 return 'm';
34}34}
35 35
36/* No atime modificaton nor notify on underlying */
37#define OVL_OPEN_FLAGS (O_NOATIME | FMODE_NONOTIFY)
38
36static struct file *ovl_open_realfile(const struct file *file,39static struct file *ovl_open_realfile(const struct file *file,
37 struct inode *realinode)40 struct inode *realinode)
38{41{
39 struct inode *inode = file_inode(file);42 struct inode *inode = file_inode(file);
40 struct file *realfile;43 struct file *realfile;
41 const struct cred *old_cred;44 const struct cred *old_cred;
42 int flags = file->f_flags | O_NOATIME | FMODE_NONOTIFY;45 int flags = file->f_flags | OVL_OPEN_FLAGS;
43 int acc_mode = ACC_MODE(flags);46 int acc_mode = ACC_MODE(flags);
44 int err;47 int err;
45 48
@@ -72,8 +75,7 @@ static int ovl_change_flags(struct file *file, unsigned int flags) · 26 unmodified lines
72 struct inode *inode = file_inode(file);75 struct inode *inode = file_inode(file);
73 int err;76 int err;
74 77
75 /* No atime modificaton on underlying */78 flags |= OVL_OPEN_FLAGS;
76 flags |= O_NOATIME | FMODE_NONOTIFY;
77 79
78 /* If some flag changed that cannot be changed then something's amiss */80 /* If some flag changed that cannot be changed then something's amiss */
79 if (WARN_ON((file->f_flags ^ flags) & ~OVL_SETFL_MASK))81 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
126 }128 }
127 129
128 /* Did the flags change since open? */130 /* 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))
130 return ovl_change_flags(real->file, file->f_flags);132 return ovl_change_flags(real->file, file->f_flags);
131 133
132 return 0;134 return 0;
fs/overlayfs/namei.c+6−9
@@ -389,7 +389,7 @@ invalid: · 388 unmodified lines
389}389}
390 390
391static int ovl_check_origin(struct ovl_fs *ofs, struct dentry *upperdentry,391static int ovl_check_origin(struct ovl_fs *ofs, struct dentry *upperdentry,
392 struct ovl_path **stackp, unsigned int *ctrp)392 struct ovl_path **stackp)
393{393{
394 struct ovl_fh *fh = ovl_get_fh(upperdentry, OVL_XATTR_ORIGIN);394 struct ovl_fh *fh = ovl_get_fh(upperdentry, OVL_XATTR_ORIGIN);
395 int err;395 int err;
@@ -406,10 +406,6 @@ static int ovl_check_origin(struct ovl_fs *ofs, struct dentry *upperdentry, · 10 unmodified lines
406 return err;406 return err;
407 }407 }
408 408
409 if (WARN_ON(*ctrp))
410 return -EIO;
411
412 *ctrp = 1;
413 return 0;409 return 0;
414}410}
415 411
@@ -861,8 +857,6 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, · 445 unmodified lines
861 goto out;857 goto out;
862 }858 }
863 if (upperdentry && !d.is_dir) {859 if (upperdentry && !d.is_dir) {
864 unsigned int origin_ctr = 0;
865
866 /*860 /*
867 * Lookup copy up origin by decoding origin file handle.861 * Lookup copy up origin by decoding origin file handle.
868 * We may get a disconnected dentry, which is fine,862 * 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
873 * number - it's the same as if we held a reference867 * number - it's the same as if we held a reference
874 * to a dentry in lower layer that was moved under us.868 * to a dentry in lower layer that was moved under us.
875 */869 */
876 err = ovl_check_origin(ofs, upperdentry, &origin_path,870 err = ovl_check_origin(ofs, upperdentry, &origin_path);
877 &origin_ctr);
878 if (err)871 if (err)
879 goto out_put_upper;872 goto out_put_upper;
880 873
@@ -1073,6 +1066,10 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, · 192 unmodified lines
1073 upperredirect = NULL;1066 upperredirect = NULL;
1074 goto out_free_oe;1067 goto out_free_oe;
1075 }1068 }
1069 err = ovl_check_metacopy_xattr(upperdentry);
1070 if (err < 0)
1071 goto out_free_oe;
1072 uppermetacopy = err;
1076 }1073 }
1077 1074
1078 if (upperdentry || ctr) {1075 if (upperdentry || ctr) {
fs/overlayfs/overlayfs.h+0−1
@@ -483,7 +483,6 @@ void ovl_aio_request_cache_destroy(void); · 482 unmodified lines
483/* copy_up.c */483/* copy_up.c */
484int ovl_copy_up(struct dentry *dentry);484int ovl_copy_up(struct dentry *dentry);
485int ovl_copy_up_with_data(struct dentry *dentry);485int ovl_copy_up_with_data(struct dentry *dentry);
486int ovl_copy_up_flags(struct dentry *dentry, int flags);
487int ovl_maybe_copy_up(struct dentry *dentry, int flags);486int ovl_maybe_copy_up(struct dentry *dentry, int flags);
488int ovl_copy_xattr(struct dentry *old, struct dentry *new);487int ovl_copy_xattr(struct dentry *old, struct dentry *new);
489int ovl_set_attr(struct dentry *upper, struct kstat *stat);488int 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
580 }580 }
581 }581 }
582 582
583 /* Workdir is useless in non-upper mount */583 /* Workdir/index are useless in non-upper mount */
584 if (!config->upperdir && config->workdir) {584 if (!config->upperdir) {
585 pr_info("option \"workdir=%s\" is useless in a non-upper mount, ignore\n",585 if (config->workdir) {
586 config->workdir);586 pr_info("option \"workdir=%s\" is useless in a non-upper mount, ignore\n",
587 kfree(config->workdir);587 config->workdir);
588 config->workdir = NULL;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;
589 }596 }
590 597
591 err = ovl_parse_redirect_mode(config, config->redirect_mode);598 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
622 629
623 /* Resolve nfs_export -> index dependency */630 /* Resolve nfs_export -> index dependency */
624 if (config->nfs_export && !config->index) {631 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) {
626 pr_err("conflicting options: nfs_export=on,index=off\n");636 pr_err("conflicting options: nfs_export=on,index=off\n");
627 return -EINVAL;637 return -EINVAL;
628 }638 } else if (index_opt) {
629 if (index_opt) {
630 /*639 /*
631 * There was an explicit index=off that resulted640 * There was an explicit index=off that resulted
632 * in this conflict.641 * in this conflict.
@@ -1352,8 +1361,15 @@ static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs, · 719 unmodified lines
1352 goto out;1361 goto out;
1353 }1362 }
1354 1363
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;
1355 ofs->indexdir = ovl_workdir_create(ofs, OVL_INDEXDIR_NAME, true);1369 ofs->indexdir = ovl_workdir_create(ofs, OVL_INDEXDIR_NAME, true);
1356 if (ofs->indexdir) {1370 if (ofs->indexdir) {
1371 ofs->workdir = dget(ofs->indexdir);
1372
1357 err = ovl_setup_trap(sb, ofs->indexdir, &ofs->indexdir_trap,1373 err = ovl_setup_trap(sb, ofs->indexdir, &ofs->indexdir_trap,
1358 "indexdir");1374 "indexdir");
1359 if (err)1375 if (err)
@@ -1396,6 +1412,18 @@ static bool ovl_lower_uuid_ok(struct ovl_fs *ofs, const uuid_t *uuid) · 36 unmodified lines
1396 if (!ofs->config.nfs_export && !ovl_upper_mnt(ofs))1412 if (!ofs->config.nfs_export && !ovl_upper_mnt(ofs))
1397 return true;1413 return true;
1398 1414
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
1399 for (i = 0; i < ofs->numfs; i++) {1427 for (i = 0; i < ofs->numfs; i++) {
1400 /*1428 /*
1401 * We use uuid to associate an overlay lower file handle with a1429 * 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
1493 if (err < 0)1521 if (err < 0)
1494 goto out;1522 goto out;
1495 1523
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 */
1496 err = ovl_setup_trap(sb, stack[i].dentry, &trap, "lowerdir");1531 err = ovl_setup_trap(sb, stack[i].dentry, &trap, "lowerdir");
1497 if (err)1532 if (err)
1498 goto out;1533 goto out;
1499 1534
1500 if (ovl_is_inuse(stack[i].dentry)) {1535 if (ovl_is_inuse(stack[i].dentry)) {
1501 err = ovl_report_in_use(ofs, "lowerdir");1536 err = ovl_report_in_use(ofs, "lowerdir");
1502 if (err)1537 if (err) {
1538 iput(trap);
1503 goto out;1539 goto out;
1540 }
1504 }1541 }
1505 1542
1506 mnt = clone_private_mount(&stack[i]);1543 mnt = clone_private_mount(&stack[i]);
@@ -1575,10 +1612,6 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb, · 68 unmodified lines
1575 if (!ofs->config.upperdir && numlower == 1) {1612 if (!ofs->config.upperdir && numlower == 1) {
1576 pr_err("at least 2 lowerdir are needed while upperdir nonexistent\n");1613 pr_err("at least 2 lowerdir are needed while upperdir nonexistent\n");
1577 return ERR_PTR(-EINVAL);1614 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;
1582 }1615 }
1583 1616
1584 stack = kcalloc(numlower, sizeof(struct path), GFP_KERNEL);1617 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
1842 if (!ovl_upper_mnt(ofs))1875 if (!ovl_upper_mnt(ofs))
1843 sb->s_flags |= SB_RDONLY;1876 sb->s_flags |= SB_RDONLY;
1844 1877
1845 if (!(ovl_force_readonly(ofs)) && ofs->config.index) {1878 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
1852 err = ovl_get_indexdir(sb, ofs, oe, &upperpath);1879 err = ovl_get_indexdir(sb, ofs, oe, &upperpath);
1853 if (err)1880 if (err)
1854 goto out_free_oe;1881 goto out_free_oe;
1855 1882
1856 /* Force r/o mount with no index dir */1883 /* Force r/o mount with no index dir */
1857 if (ofs->indexdir)1884 if (!ofs->indexdir)
1858 ofs->workdir = dget(ofs->indexdir);
1859 else
1860 sb->s_flags |= SB_RDONLY;1885 sb->s_flags |= SB_RDONLY;
1861 }1886 }
1862 1887

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