Skip to content

core: always read /proc/self/mountinfo, never /etc/mtab - #2978

Closed
marineam wants to merge 1 commit into
systemd:masterfrom
marineam:mtab
Closed

marineam wants to merge 1 commit into
systemd:masterfrom
marineam:mtab

Conversation

@marineam

@marineam marineam commented Apr 7, 2016

Copy link
Copy Markdown
Contributor

Passing NULL for the filename to mnt_table_parse_mtab allows libmount to
pick either /etc/mtab or /proc/self/mountinfo depending on whether
/etc/mtab is a regular file or not. Normally it is a symlink but when
booting with an empty /etc the symlink won't be created until tmpfiles
runs. Combined with 6f20f85 which re-enables writing to /etc/mtab we
now have systemd reading an incomplete mount table until tmpfiles runs.

Whether or not this is a problem is inherently racy but can cause mount
units to be marked as dead. Later if the unit is activated it may fail.
CoreOS has hit this bug a couple times over with usr.mount.

Relatedly, util-linux introduced the --enable-libmount-force-mountinfo
configure option as an alternative work-around for this sort of
situation. Considering that option is not enabled by default and systemd
should never read /etc/mtab regardless of util-linux's build config we
may as well fix the bug here too. :)

Fixes #2960 coreos/bugs#1187 coreos/bugs#463

Passing NULL for the filename to mnt_table_parse_mtab allows libmount to
pick either /etc/mtab or /proc/self/mountinfo depending on whether
/etc/mtab is a regular file or not. Normally it is a symlink but when
booting with an empty /etc the symlink won't be created until tmpfiles
runs. Combined with 6f20f85 which re-enables writing to /etc/mtab we
now have systemd reading an incomplete mount table until tmpfiles runs.

Whether or not this is a problem is inherently racy but can cause mount
units to be marked as dead. Later if the unit is activated it may fail.
CoreOS has hit this bug a couple times over with usr.mount.

Relatedly, util-linux introduced the --enable-libmount-force-mountinfo
configure option as an alternative work-around for this sort of
situation. Considering that option is not enabled by default and systemd
should never read /etc/mtab regardless of util-linux's build config we
may as well fix the bug here too. :)
@martinpitt

Copy link
Copy Markdown
Contributor

Indeed, we assume that util-linux gets built with --enable-libmount-force-mountinfo on Linux [1], as this is pretty much an "unbreak things" option. So enforcing this stronger, like with your patch, seems fine to me as it's essentially a no-change on systems with --enable-libmount-force-mountinfo and fixes things on those which don't.

So, 👍 from me.

[1] Not on BSD, where it builds too, despite the name :-)

@karelzak

karelzak commented Apr 7, 2016

Copy link
Copy Markdown
Contributor

Well, patch is technically correct and I don't see a problem with it.

But --enable-libmount-force-mountinfo forces libmount to use mountinfo also in another situations (for example in mount(8)) and you really want to use this option to be safe. We should be really strict about systemd requirements. It's naive to assume that systemd will work everywhere...

So, apply the patch if you're really paranoid, but still require --enable-libmount-force-mountinfo.

@karelzak

karelzak commented Apr 7, 2016

Copy link
Copy Markdown
Contributor

Note, it's possible that in v2.29 we will kill mtab support at all (or at least force to mountinfo by default), but we need discussion about it on util-linux upstream.

@poettering

Copy link
Copy Markdown
Member

I am tempted to say we should rather document in the README that we don't support util-linux without --enable-libmount-force-mountinfo set. It sounds weird, adding work-arounds for /etc/mtab usage to systemd, after all…

@karelzak

karelzak commented Apr 7, 2016

Copy link
Copy Markdown
Contributor

I thought it's already documented :-)

@keszybz

keszybz commented Apr 7, 2016

Copy link
Copy Markdown
Member

The patch removes one way that users can screw up systemd installation. Granted, they could have other issues if util-linux is compiled wrong, but since we "hide" those issues after tmpfiles is run, things might otherwise work just fine. It also makes reading of the code slightly easier. So +1 to merging.

@marineam

marineam commented Apr 7, 2016

Copy link
Copy Markdown
Contributor Author

And note that "users can screw up" includes disros! I had no idea that util-linix option existed until this second round of hitting the same bug. Unless util-linix exposes the option in pkg-config or similar so systemd can refuse to build without it claiming systemd doesn't support util-linix builds without it isn't really helpful. When this problem comes up it is inherently racy, only might happen on the first boot of a system, happens so early during boot journal isn't running so the bad mounted->dead transition is only going to be visible in debug logging if you think to log to kmsg and configure the kernel with a huge buffer (console logging is too slow), and given pid1 keeps envoron empty and stderr redirected to devnull it takes custom hacking to enable and capture the libmount debug messages that make this bug obvious.

Basically re-enbling writing mtab with the removal of '-n' from mount commands a while back has led us to spend a week debugging usr.mount twice. (The same person wasn't available to work on it both times so there was a lot of step retracing). The commit message claimed removing -n was harmless being and old and deprecated thing but until mtab support is actually removed that little -n option is actually still meaningful! :)

This commit certainly doesn't eliminate other possible situations the --enable-libmount-force-mountinfo option fixes but at least those are probably not in pid1 during early boot and thus practical to debug for most people in a reasonable amount of time.

Also, ugg, sorry for the close/open and truncated post of this comment earlier. Teach me to use github on my phone...

@marineam marineam closed this Apr 7, 2016
@marineam marineam reopened this Apr 7, 2016
@poettering

Copy link
Copy Markdown
Member

Yeah, we should have documented the configure switch required for util-linux in the NEWS+README files.

I am very sure we should not override library defaults in code, hence I am against the proposed patch. However, we really should document that we require the aforementioned configure switch to be set...

@marineam

marineam commented Apr 8, 2016

Copy link
Copy Markdown
Contributor Author

I don't follow why a value shouldn't be specified here. Passing NULL doesn't mean "use whichever path is the default". It is exactly equivalent to passing "/etc/mtab", regardless of util-linux's configuration. With the required build option util-linux's behavior is to ignore the argument entirely. Passing the string "/etc/mtab" would be clearly wrong here, and considering the current implementation in util-linux passing NULL is equivalently wrong.

@keszybz

keszybz commented Apr 8, 2016

Copy link
Copy Markdown
Member

@poettering: you are saying that --enable-libmount-force-mountinfo is required. OK, I think nobody is disputing that. But then, all this PR does is that:

  • for the supported configuration, it has no effect,
  • for the broken configuration, it just makes things work.

I don't think we should be detecting broken configuration in other libraries by breaking users' systems.

@floppym

floppym commented Apr 10, 2016

Copy link
Copy Markdown
Contributor

As the systemd maintainer on a distro that supports both systemd and other inits (Gentoo), forcing --enable-libmount-force-mountinfo globally is not an option for me. We have OpenRC users that are very vocal about keeping /etc/mtab support around.

If necessary, I could control that option with a build-time USE flag, and then depend on that use flag from the systemd ebuild. That would result in users getting an error message at build/install time if their util-linux package is misconfigured.

RDPEND="sys-apps/util-linux[force-mountinfo(-)]

If there is a way to force the proper behavior from libmount within systemd itself, I would greatly appreciate it.

@centos-ci

Copy link
Copy Markdown

Can one of the admins verify this patch?

@poettering

Copy link
Copy Markdown
Member

@floppym i am sorry, but my sympathies for Gentoo wanting to support /etc/mtab are pretty limited. It's a seriously broken concept, and if you want to support that, then it should be on Gentoo really, i.e. maintain that locally...

@keszybz I am pretty sure we should leave the library defaults in ther by default, and not hardcode too much information, overriding its defaults. i.e. the docs already suggest that there are three possible options ("/etc/mtab or /proc/self/mountinfo + /run/mount/utabs or /proc/mounts"), and in reality I really don't want to get too much into the business of telling libmount what to do there, except that I know that /etc/mtab is something we really should not support. This is particularly relevant as specifying "/proc/self/mountinfo" is actually slightly misleading, as it also needs "/run/mount/utabs" in that case. Hence: yes, we break the abstraction that libmount is, by saying that we don't support /etc/mtab, but then again, I prefer breaking this abstraction in text only, and not in code.

Or to say this differently: I think it would have been a better choice if libmount would just have switched this over internally, and we never would have had to deal with this in the systemd context, because ultimately I don't really care where libmount gets its data from, as long as it's not /etc/mtab... For example, maybe one day with get a syscall based iface to acquire the mount table. If so, I think it should really be up to libmount to use that, and we shouldn't force it to use "/proc/self/mountinfo" in that case, nor even have to think about that then.

I have now added a comment about this to NEWS and README. I hope that settles the issue.

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

Development

Successfully merging this pull request may close these issues.

usr.mount unit failure after switching root

7 participants