Skip to content

kernel warnings about invalid overlay mounts #8265

Closed

Description

@sipsma

When running our integ tests, checking the kernel logs shows periodic warnings about invalid overlay mounts:

overlayfs: lowerdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.

I've seen this on my local machine and in CI. They don't happen every run, so it's likely some sort of race condition

This means that an overlay mount was just made where the upperdir=/workdir= option points to a directory that overlaps with a directory specified as the lowerdir= option in another existing overlay mount.

  • It's valid to use a dir as an upperdir, unmount it and then use it as a lowerdir, but it's not valid to have those mounts at the same time

In the past when I've seen this, the "undefined behavior" would manifest as things like doing ls on a directory, seeing a file, but then trying to open the file resulting in not found errors, etc.

Impact

It's unclear if/how these invalid mounts are impacting us at this time. So far, flakes that could have plausibly been explained by this have ended up having different root causes, but that's just so far.

There's at least a couple of scenarios that come to mind in terms of what could be happening. Some of them would be really nasty bugs, some would be relatively harmless (though still bugs):

  1. Straightforward - overlay mounts are being made that are just obviously invalid and using upperdirs + lowerdirs that overlay simultaneously.
    • Nasty bug, but at least should be relatively obvious
  2. Bind mount complications - you can do a bind mount sourced from an overlay mount. This does not create a duplicate overlay, but it essentially means that the overlay mount exists in multiple points on the fs tree and will still count as existing until all of those mountpoints have been unmounted
    • Nasty bug and would be extra hard to track down
  3. MNT_DETACH complications - this option to umount syscalls will result in essentially an asynchronous unmount. I think it means that an overlay mount could still "exist" in some sense and result in this kernel warning if any mounts are made after the umount call with conflicting lowerdir/upperdir/workdir options.
    • This would be the least devastating possibility since it becomes extra hard for any accesses to happen that would result in undefined behavior.

Dagger, buildkit and various containerd libraries all make mounts, so any or all of them together could be culprits.

Debugging/tooling

You can see the kernel logs by running dmesg anywhere on the host (dmesg -w will tail the logs).

My usual go-tos for debugging things like this have problems:

  1. Debug logs - there's so many places mounts are made across our code and our (transitive) deps that this would be tedious and error-prone to get real coverage of the actual mounts being made
  2. strace - introduces way too much performance overhead to really be viable in this case

The best option I've found so far is this ebpf-based program: https://github.com/iovisor/bcc/blob/master/tools/mountsnoop.py

  • It's typically available in package managers through a package like bpfcc-tools

Gerhard installed it in the sysadmin pod on every node in CI, though it requires access to the host kernel headers. One time it worked no changes (???) but typically you need to do something like this to stitch the kernel headers in:

mkdir /lib/modules
# The exact kernel version in this dir name may change from host to host as the nodes update to new versions
ln -s /host/lib/modules/5.10.223-211.872.amzn2.x86_64/ /lib/modules/5.10.223-211.872.amzn2.x86_64
ln -s /host/usr/src/kernels /usr/src/kernels

After that you can run mountsnoop-bpfcc and you will see every mount+unmount being made on the whole box.

This is an overwhelming amount of information, but in theory if we get its output when the kernel prints one of these warnings, we'll have the information needed to help track this down.

  • How straightforward it is to parse from there depends on exactly which scenario (listed above) we are hitting. It's highly likely writing some script to parse the output would be needed.

One huge gotcha with mountsnoop is that due to a stack size limitation in ebpf, mount options get cut off after 412 characters. Whether this ruins it entirely for what we are trying to debug is not clear yet; depends on how long our mount options get.

I'm not convinced this is gonna be the best way to debug all this, it's just a viable option I've found so far.

  • The next best I know of now would be to go through the tedious debug logging of every mount we make all over the codebase (and in buildkit + containerd libs)
  • Sure there's plenty more too

cc @jedevc @gerhard

Activity

  1. added
    kind/bug
    area/engine
    on Aug 28, 2024
  2. sipsma commented on Aug 28, 2024

    @sipsma
    ContributorAuthor

    Matias let me know there's a sysadmin pod on each node that has all the privileges needed + host mounted at /host (to get kernel headers), so I can actually run mountsnoop there in CI too.

    After opening shell in the pod:

    • apt update && apt install -y bpfcc-tools
    • mountsnoop-bpfcc
      • I'm surprised I didn't have to point to the kernel headers under /host, but it seems to work. Either it found them under /host somehow or there are kernel headers in the pod container that happen to work (not the case in alpine based pod containers) 🤷‍♂️
  3. sipsma commented on Sep 19, 2024

    @sipsma
    ContributorAuthor

    I had a random vague memory of this happening in the past and finally managed to dig it up in our GH issue history: #3785 (comment)

    I saw these messages back in 2022 too, so whatever this is, it potentially has been an issue for a very long time. That makes me suspect slightly more that the impact is closer to something like 3. in my list above since I'd have expected us or users to have experienced something more obviously broken for a very long time. Still unknown overall though, just felt worth noting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/enginekind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions