I was thinking of a more generalized overlayfs solution that detects if
file systems don't initialize the superblock uuid and overlayfs
improvises by generating the internal overlayfs uuid, something like:

diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index 698d112bdb17..da3faaf68d69 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -248,6 +248,7 @@ struct ovl_fh *ovl_encode_real_fh(struct dentry *real, bool 
is_upper)
        void *buf;
        int buflen = MAX_HANDLE_SZ;
        uuid_t *uuid = &real->d_sb->s_uuid;
+       static const uuid_t z_uuid;
 
        buf = kmalloc(buflen, GFP_KERNEL);
        if (!buf)
@@ -289,7 +290,22 @@ struct ovl_fh *ovl_encode_real_fh(struct dentry *real, 
bool is_upper)
        if (is_upper)
                fh->flags |= OVL_FH_FLAG_PATH_UPPER;
        fh->len = fh_len;
-       fh->uuid = *uuid;
+
+       if (uuid_equal(uuid, &z_uuid)) {
+               struct super_block *sb = real->d_sb;
+               u16 hash;
+
+               pr_warn("ovl_encode_real_fh: ZERO UUID, generating one from 
superblock\n");
+
+               memcpy(&fh->uuid.b[0], &sb->s_magic, 8);
+               memcpy(&fh->uuid.b[8], &sb->s_dev, 6);
+               hash = ((long)sb ^ (long)sb->s_fs_info) >> 12;
+               memcpy(&fh->uuid.b[14], &hash, 2);
+       } else {
+               fh->uuid = *uuid;
+       }
+

-- 
You received this bug notification because you are a member of Kernel
Packages, which is subscribed to linux in Ubuntu.
https://bugs.launchpad.net/bugs/1824407

Title:
  remount of multilower moved pivoted-root overlayfs root, results in
  I/O errors on some modified files

Status in linux package in Ubuntu:
  Confirmed
Status in linux-hwe package in Ubuntu:
  Invalid
Status in linux-hwe source package in Bionic:
  Confirmed

Bug description:
  1) Download focal subiquity pending image, or eoan release image
  2) boot, and press ESC and edit boot command line (F6 in bios, e in UEFI)
  3) After --- insert the following options

     break=top debug init=/bin/bash

  4) Continue boot (Enter in BIOS, ctrl+x in UEFI)
  5) in the initramfs execute:

      rm /scripts/casper-bottom/25adduser
      exit

  6) you will be dropped into pivoted root filesystem, before systemd is execed 
as pid one
  7) /run/initramfs/ will contain a debug log, showing how everything was 
mounted. Ie. cdrom mounted, squashfs losetup from there, then multilower 
overlay setup from them, moved to /root, and then pivot-root to /root done to 
finally end up as /. Underlying layers are moved into /cow for your convenience.

  8) At this point modifying zero-byte length files, that exist in the
  lowest layer, but not the middle one, in certain ways, will results in
  them to be corrupted, after / is remounted.

  9) Corruption examples

  (On both focal & eoan)

  cat /etc/.pwd.lock
  systemd-sysusers
  cat /etc/.pwd.lock
  mount -o remount /
  cat /etc/.pwd.lock
  overlayfs: invalid origin (etc/.pwd.lock, ftype=8000, origin ftype=4000)
  cat: /etc/.pwd.lock: Input/output error

  (Only on eoan)

  cat /etc/machine-id
  systemd-machine-id-setup
  cat /etc/machine-id
  mount -o remount /
  cat /etc/machine-id
  overlayfs: invalid origin (etc/machine-id, ftype=8000, origin ftype=4000)
  cat: /etc/machine-id: Input/output error

  Lots of things break once machine-id and .pwd.lock are corrupted. I.e.
  unable to dhcp, connect to dbus, add/remove/change users or groups,
  etc.

  We were unable to recreate the issue outside of booting things with
  casper. Ie. statically on a regular host machine without pivot-root.
  But hopefully booting to a quite state with nothing running is
  sufficient to reproduce this.

  Instead of booting with `bebroken init=/bin/bash` you can boot with
  `bebroken systemd.mask=systemd-remount-fs.service` this will complete
  the boot, with /etc/machine-id & .pwd.lock modified, meaning that
  remount of / will cause IO errors on those files.

  Currently, we are shipping two hacks in casper's 25adduser script to
  "rm" the offending files, and create them again on the upper rw layer.
  They then survive remount without i/o errors. However, we'd rather not
  ship those hacks, and have kernel overlay fixed to work correctly with
  multi-lower-dir and not corrupt files upon remounting /.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1824407/+subscriptions

-- 
Mailing list: https://launchpad.net/~kernel-packages
Post to     : kernel-packages@lists.launchpad.net
Unsubscribe : https://launchpad.net/~kernel-packages
More help   : https://help.launchpad.net/ListHelp

Reply via email to