Commit Graph

900 Commits

Author SHA1 Message Date
Miklos Szeredi ba8894a0af ovl: remove unused forward declaration
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit a6eb9a4a69cc360b930dad9dc8513f8fd9b3577f
Author: Giuseppe Scrivano <gscrivan@redhat.com>
Date:   Mon Feb 10 13:07:55 2025 +0100

    ovl: remove unused forward declaration

    The ovl_get_verity_xattr() function was never added, only its declaration.

    Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
    Fixes: 184996e92e86 ("ovl: Validate verity xattr when resolving lowerdata")
    Reviewed-by: Amir Goldstein <amir73il@gmail.com>
    Reviewed-by: Alexander Larsson <alexl@redhat.com>
    Reviewed-by: Christian Brauner <brauner@kernel.org>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:37 +02:00
Miklos Szeredi 93e8172c31 ovl: don't allow datadir only
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit eb3a04a8516ee9b5174379306f94279fc90424c4
Author: Miklos Szeredi <mszeredi@redhat.com>
Date:   Mon Feb 10 15:11:22 2025 +0100

    ovl: don't allow datadir only

    In theory overlayfs could support upper layer directly referring to a data
    layer, but there's no current use case for this.

    Originally, when data-only layers were introduced, this wasn't allowed,
    only introduced by the "datadir+" feature, but without actually handling
    this case, resulting in an Oops.

    Fix by disallowing datadir without lowerdir.

    Reported-by: Giuseppe Scrivano <gscrivan@redhat.com>
    Fixes: 24e16e385f22 ("ovl: add support for appending lowerdirs one by one")
    Cc: <stable@vger.kernel.org> # v6.7
    Reviewed-by: Amir Goldstein <amir73il@gmail.com>
    Reviewed-by: Alexander Larsson <alexl@redhat.com>
    Reviewed-by: Christian Brauner <brauner@kernel.org>
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>

Originally, when data-only layers were introduced, this wasn't allowed,
only introduced by the "datadir+" feature, but without actually handling
this case, resulting in an Oops.

Fix by disallowing datadir without lowerdir.

Reported-by: Giuseppe Scrivano <gscrivan@redhat.com>
Fixes: 24e16e385f22 ("ovl: add support for appending lowerdirs one by one")
Cc: <stable@vger.kernel.org> # v6.7
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Alexander Larsson <alexl@redhat.com>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
(cherry picked from commit eb3a04a8516ee9b5174379306f94279fc90424c4)
2025-06-23 10:16:37 +02:00
Miklos Szeredi a3d49f650b ovl: fail if trusted xattrs are needed but caller lacks permission
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 6c4a5f96450415735c31ed70ff354f0ee5cbf67b
Author: Mike Baynton <mike@mbaynton.com>
Date:   Wed Jul 10 22:52:04 2024 -0500

    ovl: fail if trusted xattrs are needed but caller lacks permission

    Some overlayfs features require permission to read/write trusted.*
    xattrs. These include redirect_dir, verity, metacopy, and data-only
    layers. This patch adds additional validations at mount time to stop
    overlays from mounting in certain cases where the resulting mount would
    not function according to the user's expectations because they lack
    permission to access trusted.* xattrs (for example, not global root.)

    Similar checks in ovl_make_workdir() that disable features instead of
    failing are still relevant and used in cases where the resulting mount
    can still work "reasonably well." Generally, if the feature was enabled
    through kernel config or module option, any mount that worked before
    will still work the same; this applies to redirect_dir and metacopy. The
    user must explicitly request these features in order to generate a mount
    failure. Verity and data-only layers on the other hand must be explictly
    requested and have no "reasonable" disabled or degraded alternative, so
    mounts attempting either always fail.

    "lower data-only dirs require metacopy support" moved down in case
    userxattr is set, which disables metacopy.

    Cc: stable@vger.kernel.org # v6.6+
    Signed-off-by: Mike Baynton <mike@mbaynton.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:37 +02:00
Miklos Szeredi 0a650b5c92 ovl: properly handle large files in ovl_security_fileattr
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 3b6b99ef15ea37635604992ede9ebcccef38a239
Author: Oleksandr Tymoshenko <ovt@google.com>
Date:   Wed Oct 30 00:28:55 2024 +0000

    ovl: properly handle large files in ovl_security_fileattr

    dentry_open in ovl_security_fileattr fails for any file
    larger than 2GB if open method of the underlying filesystem
    calls generic_file_open (e.g. fusefs).

    The issue can be reproduce using the following script:
    (passthrough_ll is an example app from libfuse).

      $ D=/opt/test/mnt
      $ mkdir -p ${D}/{source,base,top/uppr,top/work,ovlfs}
      $ dd if=/dev/zero of=${D}/source/zero.bin bs=1G count=2
      $ passthrough_ll -o source=${D}/source ${D}/base
      $ mount -t overlay overlay \
          -olowerdir=${D}/base,upperdir=${D}/top/uppr,workdir=${D}/top/work \
          ${D}/ovlfs
      $ chmod 0777 ${D}/mnt/ovlfs/zero.bin

    Running this script results in "Value too large for defined data type"
    error message from chmod.

    Signed-off-by: Oleksandr Tymoshenko <ovt@google.com>
    Fixes: 72db82115d2b ("ovl: copy up sync/noatime fileattr flags")
    Cc: stable@vger.kernel.org # v5.15+
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:37 +02:00
Miklos Szeredi 0e5b52d6ae ovl: fix UAF in ovl_dentry_update_reval by moving dput() in ovl_link_up
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit c84e125fff2615b4d9c259e762596134eddd2f27
Author: Vasiliy Kovalev <kovalev@altlinux.org>
Date:   Sat Feb 15 00:51:48 2025 +0300

    ovl: fix UAF in ovl_dentry_update_reval by moving dput() in ovl_link_up

    The issue was caused by dput(upper) being called before
    ovl_dentry_update_reval(), while upper->d_flags was still
    accessed in ovl_dentry_remote().

    Move dput(upper) after its last use to prevent use-after-free.

    BUG: KASAN: slab-use-after-free in ovl_dentry_remote fs/overlayfs/util.c:162 [inline]
    BUG: KASAN: slab-use-after-free in ovl_dentry_update_reval+0xd2/0xf0 fs/overlayfs/util.c:167

    Call Trace:
     <TASK>
     __dump_stack lib/dump_stack.c:88 [inline]
     dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:114
     print_address_description mm/kasan/report.c:377 [inline]
     print_report+0xc3/0x620 mm/kasan/report.c:488
     kasan_report+0xd9/0x110 mm/kasan/report.c:601
     ovl_dentry_remote fs/overlayfs/util.c:162 [inline]
     ovl_dentry_update_reval+0xd2/0xf0 fs/overlayfs/util.c:167
     ovl_link_up fs/overlayfs/copy_up.c:610 [inline]
     ovl_copy_up_one+0x2105/0x3490 fs/overlayfs/copy_up.c:1170
     ovl_copy_up_flags+0x18d/0x200 fs/overlayfs/copy_up.c:1223
     ovl_rename+0x39e/0x18c0 fs/overlayfs/dir.c:1136
     vfs_rename+0xf84/0x20a0 fs/namei.c:4893
    ...
     </TASK>

    Fixes: b07d5cc93e1b ("ovl: update of dentry revalidate flags after copy up")
    Reported-by: syzbot+316db8a1191938280eb6@syzkaller.appspotmail.com
    Closes: https://syzkaller.appspot.com/bug?extid=316db8a1191938280eb6
    Signed-off-by: Vasiliy Kovalev <kovalev@altlinux.org>
    Link: https://lore.kernel.org/r/20250214215148.761147-1-kovalev@altlinux.org
    Reviewed-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:37 +02:00
Miklos Szeredi 71dcdd5f6f ovl: ovl_parse_param_lowerdir: Add missed '\n' for pr_err
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 441e36ef5b347d9ab4f54f7b54853266be687556
Author: Zhihao Cheng <chengzhihao1@huawei.com>
Date:   Fri Jul 5 09:15:10 2024 +0800

    ovl: ovl_parse_param_lowerdir: Add missed '\n' for pr_err

    Add '\n' for pr_err in function ovl_parse_param_lowerdir(), which
    ensures that error message is displayed at once.

    Fixes: b36a5780cb44 ("ovl: modify layer parameter parsing")
    Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
    Link: https://lore.kernel.org/r/20240705011510.794025-4-chengzhihao1@huawei.com
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:36 +02:00
Miklos Szeredi a002d04a6a ima: detect changes to the backing overlay file
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit b836c4d29f2744200b2af41e14bf50758dddc818
Author: Mimi Zohar <zohar@linux.ibm.com>
Date:   Wed Oct 18 14:47:02 2023 -0400

    ima: detect changes to the backing overlay file

    Commit 18b44bc5a672 ("ovl: Always reevaluate the file signature for
    IMA") forced signature re-evaulation on every file access.

    Instead of always re-evaluating the file's integrity, detect a change
    to the backing file, by comparing the cached file metadata with the
    backing file's metadata.  Verifying just the i_version has not changed
    is insufficient.  In addition save and compare the i_ino and s_dev
    as well.

    Reviewed-by: Amir Goldstein <amir73il@gmail.com>
    Tested-by: Eric Snowberg <eric.snowberg@oracle.com>
    Tested-by: Raul E Rangel <rrangel@chromium.org>
    Cc: stable@vger.kernel.org
    Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:36 +02:00
Miklos Szeredi 43962f4cef ovl: support encoding fid from inode with no alias
JIRA: https://issues.redhat.com/browse/RHEL-83562

CVE: CVE-2025-21654

commit c45beebfde34aa71afbc48b2c54cdda623515037
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Sun Jan 5 17:24:04 2025 +0100

    ovl: support encoding fid from inode with no alias

    Dmitry Safonov reported that a WARN_ON() assertion can be trigered by
    userspace when calling inotify_show_fdinfo() for an overlayfs watched
    inode, whose dentry aliases were discarded with drop_caches.

    The WARN_ON() assertion in inotify_show_fdinfo() was removed, because
    it is possible for encoding file handle to fail for other reason, but
    the impact of failing to encode an overlayfs file handle goes beyond
    this assertion.

    As shown in the LTP test case mentioned in the link below, failure to
    encode an overlayfs file handle from a non-aliased inode also leads to
    failure to report an fid with FAN_DELETE_SELF fanotify events.

    As Dmitry notes in his analyzis of the problem, ovl_encode_fh() fails
    if it cannot find an alias for the inode, but this failure can be fixed.
    ovl_encode_fh() seldom uses the alias and in the case of non-decodable
    file handles, as is often the case with fanotify fid info,
    ovl_encode_fh() never needs to use the alias to encode a file handle.

    Defer finding an alias until it is actually needed so ovl_encode_fh()
    will not fail in the common case of FAN_DELETE_SELF fanotify events.

    Fixes: 16aac5ad1fa9 ("ovl: support encoding non-decodable file handles")
    Reported-by: Dmitry Safonov <dima@arista.com>
    Closes: https://lore.kernel.org/linux-fsdevel/CAOQ4uxiie81voLZZi2zXS1BziXZCM24nXqPAxbu8kxXCUWdwOg@mail.gmail.com/
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Link: https://lore.kernel.org/r/20250105162404.357058-3-amir73il@gmail.com
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:36 +02:00
Miklos Szeredi 3a89391f92 ovl: pass realinode to ovl_encode_real_fh() instead of realdentry
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 07aeefae7ff44d80524375253980b1bdee2396b0
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Sun Jan 5 17:24:03 2025 +0100

    ovl: pass realinode to ovl_encode_real_fh() instead of realdentry

    We want to be able to encode an fid from an inode with no alias.

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Link: https://lore.kernel.org/r/20250105162404.357058-2-amir73il@gmail.com
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:36 +02:00
Miklos Szeredi 650423d0ec ovl: fix encoding fid for lower only root
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 004b8d1491b4bcbb7da1a3206d1e7e66822d47c6
Author: Miklos Szeredi <mszeredi@redhat.com>
Date:   Fri Jun 14 09:55:58 2024 +0200

    ovl: fix encoding fid for lower only root

    ovl_check_encode_origin() should return a positive number if the lower
    dentry is to be encoded, zero otherwise.  If there's no upper layer at all
    (read-only overlay), then it obviously needs to return positive.

    This was broken by commit 16aac5ad1fa9 ("ovl: support encoding
    non-decodable file handles"), which didn't take the lower-only
    configuration into account.

    Fix by checking the no-upper-layer case up-front.

    Reported-and-tested-by: Youzhong Yang <youzhong@gmail.com>
    Closes: https://lore.kernel.org/all/CADpNCvaBimi+zCYfRJHvCOhMih8OU0rmZkwLuh24MKKroRuT8Q@mail.gmail.com/
    Fixes: 16aac5ad1fa9 ("ovl: support encoding non-decodable file handles")
    Cc: <stable@vger.kernel.org> # v6.6
    Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:36 +02:00
Miklos Szeredi a44831ea14 ovl: fix wrong lowerdir number check for parameter Opt_lowerdir
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit ca76ac36bb6068866feca185045e7edf2a8f392f
Author: Zhihao Cheng <chengzhihao1@huawei.com>
Date:   Fri Jul 5 09:15:09 2024 +0800

    ovl: fix wrong lowerdir number check for parameter Opt_lowerdir

    The max count of lowerdir is OVL_MAX_STACK[500], which is broken by
    commit 37f32f526438("ovl: fix memory leak in ovl_parse_param()") for
    parameter Opt_lowerdir. Since commit 819829f0319a("ovl: refactor layer
    parsing helpers") and commit 24e16e385f22("ovl: add support for
    appending lowerdirs one by one") added check ovl_mount_dir_check() in
    function ovl_parse_param_lowerdir(), the 'ctx->nr' should be smaller
    than OVL_MAX_STACK, after commit 37f32f526438("ovl: fix memory leak in
    ovl_parse_param()") is applied, the 'ctx->nr' is updated before the
    check ovl_mount_dir_check(), which leads the max count of lowerdir
    to become 499 for parameter Opt_lowerdir.
    Fix it by replacing lower layers parsing code with the existing helper
    function ovl_parse_layer().

    Fixes: 37f32f526438 ("ovl: fix memory leak in ovl_parse_param()")
    Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
    Link: https://lore.kernel.org/r/20240705011510.794025-3-chengzhihao1@huawei.com
    Reviewed-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:36 +02:00
Miklos Szeredi d503539e05 ovl: pass string to ovl_parse_layer()
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 7eff3453cbd7e0bfc7524d59694119b5ca844778
Author: Christian Brauner <brauner@kernel.org>
Date:   Fri Jul 5 09:15:08 2024 +0800

    ovl: pass string to ovl_parse_layer()

    So it can be used for parsing the Opt_lowerdir.

    Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
    Link: https://lore.kernel.org/r/20240705011510.794025-2-chengzhihao1@huawei.com
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:36 +02:00
Miklos Szeredi f8f70ede95 ovl: fix dentry reference leak after changes to underlying layers
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 413ba91089c74207313b315e04cf381ffb5b20e4
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Sun Dec 17 11:08:52 2023 +0200

    ovl: fix dentry reference leak after changes to underlying layers

    syzbot excercised the forbidden practice of moving the workdir under
    lowerdir while overlayfs is mounted and tripped a dentry reference leak.

    Fixes: c63e56a4a652 ("ovl: do not open/llseek lower file with upper sb_writers held")
    Reported-and-tested-by: syzbot+8608bb4553edb8c78f41@syzkaller.appspotmail.com
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:36 +02:00
Miklos Szeredi 747b282c27 ovl: fix memory leak in ovl_parse_param()
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 37f32f52643869131ec01bb69bdf9f404f6109fb
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Sun Nov 12 10:11:25 2023 +0200

    ovl: fix memory leak in ovl_parse_param()

    On failure to parse parameters in ovl_parse_param_lowerdir(), it is
    necessary to update ctx->nr with the correct nr before using
    ovl_reset_lowerdirs() to release l->name.

    Reported-and-tested-by: syzbot+26eedf3631650972f17c@syzkaller.appspotmail.com
    Fixes: c835110b588a ("ovl: remove unused code in lowerdir param parsing")
    Co-authored-by: Edward Adam Davis <eadavis@qq.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:36 +02:00
Miklos Szeredi e61b7eaa42 ovl: fix misformatted comment
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit b28060db7172e6d8912d88b369123eb89e0d36b4
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Sun Nov 12 11:12:49 2023 +0200

    ovl: fix misformatted comment

    Remove misleading /** prefix from a regular comment.

    Reported-by: kernel test robot <lkp@intel.com>
    Closes: https://lore.kernel.org/oe-kbuild-all/202311121628.byHp8tkv-lkp@intel.com/
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:35 +02:00
Miklos Szeredi ef33278f28 ovl: add support for appending lowerdirs one by one
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 24e16e385f2272b1a9df51337a5c32d28a29c7ad
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Mon Oct 30 20:34:42 2023 +0200

    ovl: add support for appending lowerdirs one by one

    Add new mount options lowerdir+ and datadir+ that can be used to add
    layers to lower layers stack one by one.

    Unlike the legacy lowerdir mount option, special characters (i.e. colons
    and cammas) are not unescaped with these new mount options.

    The new mount options can be repeated to compose a large stack of lower
    layers, but they may not be mixed with the lagacy lowerdir mount option,
    because for displaying lower layers in mountinfo, we do not want to mix
    escaped with unescaped lower layers path syntax.

    Similar to data-only layer rules with the lowerdir mount option, the
    datadir+ option must follow at least one lowerdir+ option and the
    lowerdir+ option must not follow the datadir+ option.

    If the legacy lowerdir mount option follows lowerdir+ and datadir+
    mount options, it overrides them.  Sepcifically, calling:

      fsconfig(FSCONFIG_SET_STRING, "lowerdir", "", 0);

    can be used to reset previously setup lower layers.

    Suggested-by: Miklos Szeredi <miklos@szeredi.hu>
    Link: https://lore.kernel.org/r/CAJfpegt7VC94KkRtb1dfHG8+4OzwPBLYqhtc8=QFUxpFJE+=RQ@mail.gmail.com/
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:35 +02:00
Miklos Szeredi ed262c2e84 ovl: refactor layer parsing helpers
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 819829f0319a759e8a6ccb7e4f1113f3f9f07aa3
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Sun Oct 29 14:00:39 2023 +0200

    ovl: refactor layer parsing helpers

    In preparation for new mount options to add lowerdirs one by one,
    generalize ovl_parse_param_upperdir() into helper ovl_parse_layer()
    that will be used for parsing a single lower layers.

    Suggested-by: Miklos Szeredi <miklos@szeredi.hu>
    Link: https://lore.kernel.org/r/CAJfpegt7VC94KkRtb1dfHG8+4OzwPBLYqhtc8=QFUxpFJE+=RQ@mail.gmail.com/
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:35 +02:00
Miklos Szeredi 062a3e6f8b ovl: store and show the user provided lowerdir mount option
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 0cea4c097d97fdc89de488bd4202d0b087ccec58
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Sat Oct 28 11:25:30 2023 +0300

    ovl: store and show the user provided lowerdir mount option

    We are about to add new mount options for adding lowerdir one by one,
    but those mount options will not support escaping.

    For the existing case, where lowerdir mount option is provided as a colon
    separated list, store the user provided (possibly escaped) string and
    display it as is when showing the lowerdir mount option.

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:35 +02:00
Miklos Szeredi e12b5d71f8 ovl: remove unused code in lowerdir param parsing
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit c835110b588a750650988ca5000913c3c60d246b
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Sat Oct 28 12:07:45 2023 +0300

    ovl: remove unused code in lowerdir param parsing

    Commit beae836e9c61 ("ovl: temporarily disable appending lowedirs")
    removed the ability to append lowerdirs with syntax lowerdir=":<path>".
    Remove leftover code and comments that are irrelevant with lowerdir
    append mode disabled.

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:35 +02:00
Miklos Szeredi 35386c20af ovl: do not encode lower fh with upper sb_writers held
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 5b02bfc1e7e3811c5bf7f0fa626a0694d0dbbd77
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Wed Aug 16 16:47:59 2023 +0300

    ovl: do not encode lower fh with upper sb_writers held

    When lower fs is a nested overlayfs, calling encode_fh() on a lower
    directory dentry may trigger copy up and take sb_writers on the upper fs
    of the lower nested overlayfs.

    The lower nested overlayfs may have the same upper fs as this overlayfs,
    so nested sb_writers lock is illegal.

    Move all the callers that encode lower fh to before ovl_want_write().

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-06-23 10:16:04 +02:00
Miklos Szeredi fd5549bc4d ovl: do not open/llseek lower file with upper sb_writers held
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit c63e56a4a6523fcb1358e1878607d77a40b534bb
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Wed Aug 16 12:42:18 2023 +0300

    ovl: do not open/llseek lower file with upper sb_writers held

    overlayfs file open (ovl_maybe_lookup_lowerdata) and overlay file llseek
    take the ovl_inode_lock, without holding upper sb_writers.

    In case of nested lower overlay that uses same upper fs as this overlay,
    lockdep will warn about (possibly false positive) circular lock
    dependency when doing open/llseek of lower ovl file during copy up with
    our upper sb_writers held, because the locking ordering seems reverse to
    the locking order in ovl_copy_up_start():

    - lower ovl_inode_lock
    - upper sb_writers

    Let the copy up "transaction" keeps an elevated mnt write count on upper
    mnt, but leaves taking upper sb_writers to lower level helpers only when
    they actually need it.  This allows to avoid holding upper sb_writers
    during lower file open/llseek and prevents the lockdep warning.

    Minimizing the scope of upper sb_writers during copy up is also needed
    for fixing another possible deadlocks by a following patch.

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:38 +01:00
Miklos Szeredi 00aa7e8cc2 ovl: reorder ovl_want_write() after ovl_inode_lock()
JIRA: https://issues.redhat.com/browse/RHEL-83562

Conflicts: due to reordering of backports

commit 162d06444070c12827d604a2cb6b6bd98d48cbb0
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Thu Jul 20 12:51:21 2023 +0300

    ovl: reorder ovl_want_write() after ovl_inode_lock()

    Make the locking order of ovl_inode_lock() strictly between the two
    vfs stacked layers, i.e.:
    - ovl vfs locks: sb_writers, inode_lock, ...
    - ovl_inode_lock
    - upper vfs locks: sb_writers, inode_lock, ...

    To that effect, move ovl_want_write() into the helpers ovl_nlink_start()
    and ovl_copy_up_start which currently take the ovl_inode_lock() after
    ovl_want_write().

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:38 +01:00
Miklos Szeredi 9b3b995b52 ovl: split ovl_want_write() into two helpers
JIRA: https://issues.redhat.com/browse/RHEL-83562

Conflicts: not backported commit 3e15dcf77b23 ("fs: rename
__mnt_{want,drop}_write*() helpers")

commit d08d3b3c2caf6c482703bbc5efaa7b9ae95dea20
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Wed Aug 16 12:18:15 2023 +0300

    ovl: split ovl_want_write() into two helpers

    ovl_get_write_access() gets write access to upper mnt without taking
    freeze protection on upper sb and ovl_start_write() only takes freeze
    protection on upper sb.

    These helpers will be used to breakup the large ovl_want_write() scope
    during copy up into finer grained freeze protection scopes.

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:38 +01:00
Miklos Szeredi 243b43f017 ovl: add helper ovl_file_modified()
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit c002728f608183449673818076380124935e6b9b
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Wed Sep 27 13:43:44 2023 +0300

    ovl: add helper ovl_file_modified()

    A simple wrapper for updating ovl inode size/mtime, to conform
    with ovl_file_accessed().

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:38 +01:00
Miklos Szeredi 8373f5619a ovl: protect copying of realinode attributes to ovl inode
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit f7621b11e8acc8efa208c9420ff3ecb198b20e29
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Thu Aug 24 14:51:17 2023 +0300

    ovl: protect copying of realinode attributes to ovl inode

    ovl_copyattr() may be called concurrently from aio completion context
    without any lock and that could lead to overlay inode attributes getting
    permanently out of sync with real inode attributes.

    Use ovl inode spinlock to protect ovl_copyattr().

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:38 +01:00
Miklos Szeredi 21a6dee4c8 ovl: punt write aio completion to workqueue
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 389a4a4a19851211bb9c40d31c664591fb206f69
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Tue Aug 22 20:50:59 2023 +0300

    ovl: punt write aio completion to workqueue

    We want to protect concurrent updates of ovl inode size and mtime
    (i.e. ovl_copyattr()) from aio completion context.

    Punt write aio completion to a workqueue so that we can protect
    ovl_copyattr() with a spinlock.

    Export sb_init_dio_done_wq(), so that overlayfs can use its own
    dio workqueue to punt aio completions.

    Suggested-by: Jens Axboe <axboe@kernel.dk>
    Link: https://lore.kernel.org/r/8620dfd3-372d-4ae0-aa3f-2fe97dda1bca@kernel.dk/
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:38 +01:00
Miklos Szeredi 4ab9aa4571 ovl: propagate IOCB_APPEND flag on writes to realfile
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 5f034d34737e8c440bbbd13e5ef283793d841140
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Tue Aug 29 16:25:47 2023 +0300

    ovl: propagate IOCB_APPEND flag on writes to realfile

    If ovl file is opened O_APPEND, the underlying realfile is also
    opened O_APPEND, so it makes sense to propagate the IOCB_APPEND flags
    on sync writes to realfile, just as we do with aio writes.

    Effectively, because sync ovl writes are protected by inode lock,
    this change only makes a difference if the realfile is written to (size
    extending writes) from underneath overlayfs.  The behavior in this case
    is undefined, so it is ok if we change the behavior (to fail the ovl
    IOCB_APPEND write).

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:38 +01:00
Miklos Szeredi 382b0f49c1 ovl: use simpler function to convert iocb to rw flags
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit db5b5e83eee46ec5e3d685282c9e4f38946cb0ea
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Wed Sep 6 10:52:13 2023 +0300

    ovl: use simpler function to convert iocb to rw flags

    Overlayfs implements its own function to translate iocb flags into rw
    flags, so that they can be passed into another vfs call.

    With commit ce71bfea20 ("fs: align IOCB_* flags with RWF_* flags")
    Jens created a 1:1 matching between the iocb flags and rw flags,
    simplifying the conversion.

    Signed-off-by: Alessio Balsini <balsini@android.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi 323a9976c8 ovl: rely on SB_I_NOUMASK
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 2bc5e5e8167f2114976f00755b9a0c7f17d6f105
Author: Christian Brauner <brauner@kernel.org>
Date:   Thu Oct 12 17:36:57 2023 +0200

    ovl: rely on SB_I_NOUMASK

    In commit f61b9bb3f838 ("fs: add a new SB_I_NOUMASK flag") we added a
    new SB_I_NOUMASK flag that is used by filesystems like NFS to indicate
    that umask stripping is never supposed to be done in the vfs independent
    of whether or not POSIX ACLs are supported.

    Overlayfs falls into the same category as it raises SB_POSIXACL
    unconditionally to defer umask application to the upper filesystem.

    Now that we have SB_I_NOUMASK use that and make SB_POSIXACL properly
    conditional on whether or not the kernel does have support for it. This
    will enable use to turn IS_POSIXACL() into nop on kernels that don't
    have POSIX ACL support avoding bugs from missed umask stripping.

    Link: https://lore.kernel.org/r/20231012-einband-uferpromenade-80541a047a1f@brauner
    Acked-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi 3b84458fb9 ovl: temporarily disable appending lowedirs
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit beae836e9c61ee039e367a94b14f7fea08f0ad4c
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Sat Oct 14 22:30:04 2023 +0300

    ovl: temporarily disable appending lowedirs

    Kernel v6.5 converted overlayfs to new mount api.
    As an added bonus, it also added a feature to allow appending lowerdirs
    using lowerdir=:/lower2,lowerdir=::/data3 syntax.

    This new syntax has raised some concerns regarding escaping of colons.
    We decided to try and disable this syntax, which hasn't been in the wild
    for so long and introduce it again in 6.7 using explicit mount options
    lowerdir+=/lower2,datadir+=/data3.

    Suggested-by: Miklos Szeredi <miklos@szeredi.hu>
    Link: https://lore.kernel.org/r/CAJfpegsr3A4YgF2YBevWa6n3=AcP7hNndG6EPMu3ncvV-AM71A@mail.gmail.com/
    Fixes: b36a5780cb44 ("ovl: modify layer parameter parsing")
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi b895331c7b ovl: fix regression in showing lowerdir mount option
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 32db510708507f6133f496ff385cbd841d8f9098
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Wed Oct 11 17:07:03 2023 +0300

    ovl: fix regression in showing lowerdir mount option

    Before commit b36a5780cb44 ("ovl: modify layer parameter parsing"),
    spaces and commas in lowerdir mount option value used to be escaped using
    seq_show_option().

    In current upstream, when lowerdir value has a space, it is not escaped
    in /proc/mounts, e.g.:

      none /mnt overlay rw,relatime,lowerdir=l l,upperdir=u,workdir=w 0 0

    which results in broken output of the mount utility:

      none on /mnt type overlay (rw,relatime,lowerdir=l)

    Store the original lowerdir mount options before unescaping and show
    them using the same escaping used for seq_show_option() in addition to
    escaping the colon separator character.

    Fixes: b36a5780cb44 ("ovl: modify layer parameter parsing")
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi 55d96b182e ovl: fix regression in parsing of mount options with escaped comma
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit c34706acf40b43dd31f67c92c5a95d39666a1eb3
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Thu Oct 12 16:08:28 2023 +0300

    ovl: fix regression in parsing of mount options with escaped comma

    Ever since commit 91c7794713 ("ovl: allow filenames with comma"), the
    following example was legit overlayfs mount options:

      mount -t overlay overlay -o 'lowerdir=/tmp/a\,b/lower' /mnt

    The conversion to new mount api moved to using the common helper
    generic_parse_monolithic() and discarded the specialized ovl_next_opt()
    option separator.

    Bring back ovl_next_opt() and use vfs_parse_monolithic_sep() to fix the
    regression.

    Reported-by: Ryan Hendrickson <ryan.hendrickson@alum.mit.edu>
    Closes: https://lore.kernel.org/r/8da307fb-9318-cf78-8a27-ba5c5a0aef6d@alum.mit.edu/
    Fixes: 1784fbc2ed9c ("ovl: port to new mount api")
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi 79c94e3f8c overlayfs: move xattr tables to .rodata
JIRA: https://issues.redhat.com/browse/RHEL-83562

Conflicts: due to reordering of backports

commit 3d649a4a832ecfa48bf1f62972c1ddf0030785d3
Author: Wedson Almeida Filho <walmeida@microsoft.com>
Date:   Sat Sep 30 02:00:31 2023 -0300

    overlayfs: move xattr tables to .rodata

    This makes it harder for accidental or malicious changes to
    ovl_trusted_xattr_handlers or ovl_user_xattr_handlers at runtime.

    Cc: Miklos Szeredi <miklos@szeredi.hu>
    Cc: Amir Goldstein <amir73il@gmail.com>
    Cc: linux-unionfs@vger.kernel.org
    Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com>
    Link: https://lore.kernel.org/r/20230930050033.41174-28-wedsonaf@gmail.com
    Acked-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi 451badb132 ovl: fix NULL pointer defer when encoding non-decodable lower fid
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit c7242a45cb8cad5b6cd840fd4661315b45b1e841
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Tue Oct 3 09:21:27 2023 +0300

    ovl: fix NULL pointer defer when encoding non-decodable lower fid

    A wrong return value from ovl_check_encode_origin() would cause
    ovl_dentry_to_fid() to try to encode fid from NULL upper dentry.

    Reported-by: syzbot+2208f82282740c1c8915@syzkaller.appspotmail.com
    Fixes: 16aac5ad1fa9 ("ovl: support encoding non-decodable file handles")
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi a09d297490 ovl: make use of ->layers safe in rcu pathwalk
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit a535116d80339dbfe50b9b81b2f808c69eefbbc3
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Mon Oct 2 14:21:49 2023 +0300

    ovl: make use of ->layers safe in rcu pathwalk

    ovl_permission() accesses ->layers[...].mnt; we can't have ->layers
    freed without an RCU delay on fs shutdown.

    Fortunately, kern_unmount_array() that is used to drop those mounts
    does include an RCU delay, so freeing is delayed; unfortunately, the
    array passed to kern_unmount_array() is formed by mangling ->layers
    contents and that happens without any delays.

    The ->layers[...].name string entries are used to store the strings to
    display in "lowerdir=..." by ovl_show_options().  Those entries are not
    accessed in RCU walk.

    Move the name strings into a separate array ofs->config.lowerdirs and
    reuse the ofs->config.lowerdirs array as the temporary mount array to
    pass to kern_unmount_array().

    Reported-by: Al Viro <viro@zeniv.linux.org.uk>
    Link: https://lore.kernel.org/r/20231002023711.GP3389589@ZenIV/
    Acked-by: Miklos Szeredi <mszeredi@redhat.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi 11700a1453 ovl: fix file reference leak when submitting aio
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 8542f1712074f070ae90b64e6082d10d8e912e32
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Mon Oct 2 13:04:45 2023 +0300

    ovl: fix file reference leak when submitting aio

    Commit 724768a39374 ("ovl: fix incorrect fdput() on aio completion")
    took a refcount on real file before submitting aio, but forgot to
    avoid clearing FDPUT_FPUT from real.flags stack variable.
    This can result in a file reference leak.

    Fixes: 724768a39374 ("ovl: fix incorrect fdput() on aio completion")
    Reported-by: Gil Lev <contact@levgil.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi b76775023d overlayfs: set ctime when setting mtime and atime
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 03dbab3bba5f009d053635c729d1244f2c8bad38
Author: Jeff Layton <jlayton@kernel.org>
Date:   Wed Sep 13 09:33:12 2023 -0400

    overlayfs: set ctime when setting mtime and atime

    Nathan reported that he was seeing the new warning in
    setattr_copy_mgtime pop when starting podman containers. Overlayfs is
    trying to set the atime and mtime via notify_change without also
    setting the ctime.

    POSIX states that when the atime and mtime are updated via utimes() that
    we must also update the ctime to the current time. The situation with
    overlayfs copy-up is analogies, so add ATTR_CTIME to the bitmask.
    notify_change will fill in the value.

    Reported-by: Nathan Chancellor <nathan@kernel.org>
    Signed-off-by: Jeff Layton <jlayton@kernel.org>
    Tested-by: Nathan Chancellor <nathan@kernel.org>
    Acked-by: Christian Brauner <brauner@kernel.org>
    Acked-by: Amir Goldstein <amir73il@gmail.com>
    Message-Id: <20230913-ctime-v1-1-c6bc509cbc27@kernel.org>
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi da6bcd9471 ovl: fix incorrect fdput() on aio completion
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 724768a39374d35b70eaeae8dd87048a2ec7ae8e
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Tue Aug 22 20:50:59 2023 +0300

    ovl: fix incorrect fdput() on aio completion

    ovl_{read,write}_iter() always call fdput(real) to put one or zero
    refcounts of the real file, but for aio, whether it was submitted or not,
    ovl_aio_put() also calls fdput(), which is not balanced.  This is only a
    problem in the less common case when FDPUT_FPUT flag is set.

    To fix the problem use get_file() to take file refcount and use fput()
    instead of fdput() in ovl_aio_put().

    Fixes: 2406a307ac ("ovl: implement async IO routines")
    Cc: <stable@vger.kernel.org> # v5.6
    Reviewed-by: Miklos Szeredi <miklos@szeredi.hu>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi 6553d2416b ovl: use kiocb_{start,end}_write() helpers
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 8f7371268a4ba83e6bf3b73cf7484a2581f56d7b
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Thu Aug 17 17:13:36 2023 +0300

    ovl: use kiocb_{start,end}_write() helpers

    Use helpers instead of the open coded dance to silence lockdep warnings.

    Suggested-by: Jan Kara <jack@suse.cz>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Reviewed-by: Jan Kara <jack@suse.cz>
    Reviewed-by: Jens Axboe <axboe@kernel.dk>
    Message-Id: <20230817141337.1025891-7-amir73il@gmail.com>
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi b5dfe2f727 ovl: make consistent use of OVL_FS()
JIRA: https://issues.redhat.com/browse/RHEL-83562

Conflicts: due to reordering of backports

commit f01d08899fd7fa808ff9b8d33ca4882ab44d42fa
Author: Andrea Righi <andrea.righi@canonical.com>
Date:   Sun May 21 10:28:12 2023 +0200

    ovl: make consistent use of OVL_FS()

    Always use OVL_FS() to retrieve the corresponding struct ovl_fs from a
    struct super_block.

    Reviewed-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi 6bb49da0d0 ovl: auto generate uuid for new overlay filesystems
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit cbb44f0935974bba997f8db0458fac5739ae0009
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Fri Jul 7 11:26:29 2023 +0300

    ovl: auto generate uuid for new overlay filesystems

    Add a new mount option uuid=auto, which is the default.

    If a persistent UUID xattr is found it is used.

    Otherwise, an existing ovelrayfs with copied up subdirs in upper dir
    that was never mounted with uuid=on retains the null UUID.

    A new overlayfs with no copied up subdirs, generates the persistent UUID
    on first mount.

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:37 +01:00
Miklos Szeredi 217b1dc56d ovl: store persistent uuid/fsid with uuid=on
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit d9544c1b0d9e14a66936814dcc8a85861ea1b99f
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Fri Jul 7 11:20:41 2023 +0300

    ovl: store persistent uuid/fsid with uuid=on

    With uuid=on, store a persistent uuid in xattr on the upper dir to
    give the overlayfs instance a persistent identifier.

    This also makes f_fsid persistent and more reliable for reporting
    fid info in fanotify events.

    uuid=on is not supported on non-upper overlayfs or with upper fs
    that does not support xattrs.

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:36 +01:00
Miklos Szeredi 5e0d023db6 ovl: Handle verity during copy-up
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 0c71faf5a607c8744ccee702846970bdb1a8005f
Author: Alexander Larsson <alexl@redhat.com>
Date:   Wed Apr 19 13:58:45 2023 +0200

    ovl: Handle verity during copy-up

    During regular metacopy, if lowerdata file has fs-verity enabled, and
    the verity option is enabled, we add the digest to the metacopy xattr.

    If verity is required, and lowerdata does not have fs-verity enabled,
    fall back to full copy-up (or the generated metacopy would not
    validate).

    Signed-off-by: Alexander Larsson <alexl@redhat.com>
    Reviewed-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:36 +01:00
Miklos Szeredi 7da6ed38e9 ovl: Validate verity xattr when resolving lowerdata
JIRA: https://issues.redhat.com/browse/RHEL-83562

Conflicts: not backported commit cbb0b9d4bbcf ("fs: use a helper for
opening kernel internal files")

commit 184996e92e86c4a4224dc4aaee75b2ccd04b6e78
Author: Alexander Larsson <alexl@redhat.com>
Date:   Wed Jun 21 10:44:27 2023 +0200

    ovl: Validate verity xattr when resolving lowerdata

    The new digest field in the metacopy xattr is used during lookup to
    record whether the header contained a digest in the OVL_HAS_DIGEST
    flags.

    When accessing file data the first time, if OVL_HAS_DIGEST is set, we
    reload the metadata and check that the source lowerdata inode matches
    the specified digest in it (according to the enabled verity
    options). If the verity check passes we store this info in the inode
    flags as OVL_VERIFIED_DIGEST, so that we can avoid doing it again if
    the inode remains in memory.

    The verification is done in ovl_maybe_validate_verity() which needs to
    be called in the same places as ovl_maybe_lookup_lowerdata(), so there
    is a new ovl_verify_lowerdata() helper that calls these in the right
    order, and all current callers of ovl_maybe_lookup_lowerdata() are
    changed to call it instead.

    Signed-off-by: Alexander Larsson <alexl@redhat.com>
    Reviewed-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:36 +01:00
Miklos Szeredi 7b9c3b3e20 ovl: Add framework for verity support
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit ae8cba4033bc16e8a07792428a48a50710cc0f3c
Author: Alexander Larsson <alexl@redhat.com>
Date:   Wed Apr 19 13:44:21 2023 +0200

    ovl: Add framework for verity support

    This adds the scaffolding (docs, config, mount options) for supporting
    the new digest field in the metacopy xattr. This contains a fs-verity
    digest that need to match the fs-verity digest of the lowerdata
    file. The mount option "verity" specifies how this xattr is handled.

    If you enable verity ("verity=on") all existing xattrs are validated
    before use, and during metacopy we generate verity xattr in the upper
    metacopy file (if the source file has verity enabled). This means
    later accesses can guarantee that the same data is used.

    Additionally you can use "verity=require". In this mode all metacopy
    files must have a valid verity xattr. For this to work metadata
    copy-up must be able to create a verity xattr (so that later accesses
    are validated). Therefore, in this mode, if the lower data file
    doesn't have fs-verity enabled we fall back to a full copy rather than
    a metacopy.

    Actual implementation follows in a separate commit.

    Signed-off-by: Alexander Larsson <alexl@redhat.com>
    Reviewed-by: Amir Goldstein <amir73il@gmail.com>
    Acked-by: Eric Biggers <ebiggers@google.com>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:36 +01:00
Miklos Szeredi dfe5176379 ovl: add support for unique fsid per instance
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit b0504bfe1b8acdcfb5ef466581d930835ef3c49e
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Mon Jun 26 16:34:25 2023 +0300

    ovl: add support for unique fsid per instance

    The legacy behavior of ovl_statfs() reports the f_fsid filled by
    underlying upper fs. This fsid is not unique among overlayfs instances
    on the same upper fs.

    With mount option uuid=on, generate a non-persistent uuid per overlayfs
    instance and use it as the seed for f_fsid, similar to tmpfs.

    This is useful for reporting fanotify events with fid info from different
    instances of overlayfs over the same upper fs.

    The old behavior of null uuid and upper fs fsid is retained with the
    mount option uuid=null, which is the default.

    The mount option uuid=off that disables uuid checks in underlying layers
    also retains the legacy behavior.

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:36 +01:00
Miklos Szeredi 1f05671cb6 ovl: support encoding non-decodable file handles
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 16aac5ad1fa94894b798dd522c5c3a6a0628d7f0
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Sun Apr 23 19:02:04 2023 +0300

    ovl: support encoding non-decodable file handles

    When all layers support file handles, we support encoding non-decodable
    file handles (a.k.a. fid) even with nfs_export=off.

    When file handles do not need to be decoded, we do not need to copy up
    redirected lower directories on encode, and we encode also non-indexed
    upper with lower file handle, so fid will not change on copy up.

    This enables reporting fanotify events with file handles on overlayfs
    with default config/mount options.

    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:36 +01:00
Miklos Szeredi 6fe9d6379e ovl: Always reevaluate the file signature for IMA
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 18b44bc5a67275641fb26f2c54ba7eef80ac5950
Author: Eric Snowberg <eric.snowberg@oracle.com>
Date:   Tue Jul 25 17:56:46 2023 -0400

    ovl: Always reevaluate the file signature for IMA

    Commit db1d1e8b9867 ("IMA: use vfs_getattr_nosec to get the i_version")
    partially closed an IMA integrity issue when directly modifying a file
    on the lower filesystem.  If the overlay file is first opened by a user
    and later the lower backing file is modified by root, but the extended
    attribute is NOT updated, the signature validation succeeds with the old
    original signature.

    Update the super_block s_iflags to SB_I_IMA_UNVERIFIABLE_SIGNATURE to
    force signature reevaluation on every file access until a fine grained
    solution can be found.

    Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
    Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:36 +01:00
Miklos Szeredi 0aac0fd429 overlayfs: convert to ctime accessor functions
JIRA: https://issues.redhat.com/browse/RHEL-83562

commit 9aa7111523577e6cdbf9f8dbe68f51d95e616f48
Author: Jeff Layton <jlayton@kernel.org>
Date:   Wed Jul 5 15:01:31 2023 -0400

    overlayfs: convert to ctime accessor functions

    In later patches, we're going to change how the inode's ctime field is
    used. Switch to using accessor functions instead of raw accesses of
    inode->i_ctime.

    Reviewed-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Jeff Layton <jlayton@kernel.org>
    Reviewed-by: Jan Kara <jack@suse.cz>
    Message-Id: <20230705190309.579783-64-jlayton@kernel.org>
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:36 +01:00
Miklos Szeredi 8e8dae3907 ovl: move all parameter handling into params.{c,h}
JIRA: https://issues.redhat.com/browse/RHEL-83562

Conflicts: trivial whitespace conflict

commit 7fb7998b599a2e1f3744fbd34a3e7145da841ed1
Author: Christian Brauner <brauner@kernel.org>
Date:   Mon Jun 26 12:23:36 2023 +0200

    ovl: move all parameter handling into params.{c,h}

    While initially I thought that we couldn't move all new mount api
    handling into params.{c,h} it turns out it is possible. So this just
    moves a good chunk of code out of super.c and into params.{c,h}.

    Signed-off-by: Christian Brauner <brauner@kernel.org>
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2025-03-17 17:05:36 +01:00