Skip to content

systemd-tmpfiles deletes quota files and lost+found directory #181

Closed

Description

@mbiebl

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=788193

The default cleanup rules in /usr/lib/tmpfiles.d/tmp.conf will remove all files and directories, excluding systemd-private in /tmp and /var/tmp.

If /tmp or /var/tmp are on a separate partition, those directories can contain a lost+found folder from a previous fsck run. More inportantly, they might contain quota configuration files. Those should not be removed by systemd-tmpfiles.

In Debian, we had the following exceptions when cleaning up /tmp and /var/tmp in our old sysvinit setup:

    EXCEPT='! -name .
            ! ( -path ./lost+found -uid 0 )
            ! ( -path ./quota.user -uid 0 )
            ! ( -path ./aquota.user -uid 0 )
            ! ( -path ./quota.group -uid 0 )
            ! ( -path ./aquota.group -uid 0 )
            ! ( -path ./.journal -uid 0 )

For systemd, we should at least ignore the lost+found directory and the quota.{user,group} files.

I first intended to create a pull request, which adds those to tmp.conf and marks them as x, but @martinpitt mentioned, that it might be preferable to always ignore those paths when using "D" or "d" and add those ignore list to the source code instead.

I'm therefor looking for feedback first, which approach would be preferred.

Activity

  1. grawity commented on Jun 12, 2015

    @grawity
    Contributor

    Hmm, src/tmpfiles/tmpfiles.c:498 already has:

                            if (mountpoint && S_ISREG(s.st_mode))
                                    if ((streq(dent->d_name, ".journal") && s.st_uid == 0) ||
                                        streq(dent->d_name, "aquota.user") ||
                                        streq(dent->d_name, "aquota.group")) {
                                            log_debug("Skipping \"%s\".", sub_path);
                                            continue;
                                    }

    On the other hand, there is no conf syntax for "/aquota.user at the root of any mountpoint".

  2. keszybz commented on Jun 13, 2015

    @keszybz
    Member

    On Fri, Jun 12, 2015 at 04:36:54PM -0700, Mantas Mikulėnas wrote:

    Hmm, src/tmpfiles/tmpfiles.c:498 already has:

                            if (mountpoint && S_ISREG(s.st_mode))
                                    if ((streq(dent->d_name, ".journal") && s.st_uid == 0) ||
                                        streq(dent->d_name, "aquota.user") ||
                                        streq(dent->d_name, "aquota.group")) {
                                            log_debug("Skipping \"%s\".", sub_path);
                                            continue;
                                    }

    It seems that the uid check should apply to all of them, no?

    Also, without looking at the code it's hard to tell, but I think
    we should recurse into lost+found, and just ignore the directory
    itself.

  3. mbiebl commented on Jun 13, 2015

    @mbiebl
    ContributorAuthor

    I indeed missed, that we alreay ignore aquota.user and aquote.group.
    But as @keszybz said, we should apply the uid check to aquota.user and aquota.group as well.

    We should also skip the quota.group and quota.user file and the lost+found directory.
    As for the latter, I think we should ignore lost+found completely

  4. poettering commented on Jun 13, 2015

    @poettering
    Member

    Yeah i agree, we should ignore the whole of lost+found and not descend into it.

  5. mbiebl commented on Jun 13, 2015

    @mbiebl
    ContributorAuthor

    @poettering any idea, why the uid check is only applied to ".journal"? Is that deliberate or an oversight/bug? I.e. shouldn't it rather be s.st_uid == 0 && (foo || bar || baz)

  6. keszybz commented on Jun 13, 2015

    @keszybz
    Member

    Well, we do already ignore lost+found. The check is just in the other branch of the same if, the one that applies to directories. You added it back in 2010 ;). I now checked, and on my system, lost+found is ignored in /tmp. So it seems that the original reporter messed something up: maybe he created the directory as non-root?

    I don't get it why you both think that we should ignore contents of lost+found. If my machine is reset, and something lands in lost+found, it most likely is some garbage temporary file. I certainly wouldn't mind if it was deleted like any other file in /var/tmp or /tmp after a while, they are probably less useful than other files in /tmp or /var/tmp.

    For your consideration: #188.

  7. poettering commented on Jun 14, 2015

    @poettering
    Member

    @keszybz well, we really have no idea what ends up in lost+found. It could be super important data that just ended up there because the machine crashed while the user edited it. Automatic time-based clean-up is something we should only do if we know that the data is only temporary data that is OK to trash, and when the app developer acknowledged that things are cleaned up that way, by placing it in /tmp or /var/tmp. This is very different for lost-found where we really have no clue what it is, the file system forgot the context about it could be both the most irrelevant or most important of files.

    So yes, lost+found should not be cleaned up. It's not safe to do things.

    Or to turn this around: lost+found is for files that where recovered from a corrupted file systems. It's great that they were recovered, and we shouldn't then go ahead and delete them again, possibly even very quickly since the original mtime was recovered too and is very old.

    Also, the directory doesn't really exist on modern file systems anyway, and we shouldn't design around design weirdness of older file systems...

    Really, we should stay away from it.

  8. poettering commented on Jun 17, 2015

    @poettering
    Member

    I am not sure what this bug is about now. If we add the uid check to tmpfiles, then nothing about the original issue will change.

    @mbiebl any idea why the checks we already have in place don't work?

    Can you provide a reproducer or an strace or so?

  9. keszybz commented on Jun 17, 2015

    @keszybz
    Member

    But that lost+found we are looking at must be underneath the directory we are cleaning up... Realistically that would only be /var/tmp/lost+found or /tmp/lost+found. In either case the only files which could end up there should be from the temporary filesystem anyway. But I'm fine with leaving things as they are.

    I'm pretty sure that the original reported misunderstood something. I'd just push patch 1/2 and close this issue.

  10. mbiebl commented on Jun 17, 2015

    @mbiebl
    ContributorAuthor

    @poettering, @keszybz: nod, please push patch 1, since it looks correct in any case. As for lost+found, I'll doublecheck if I can reproduce the issue myself and if not, ask the bug reporter for futher info.

  11. poettering commented on Jun 17, 2015

    @poettering
    Member

    @keszybz ok, pushed patch 1 now.

  12. poettering commented on Jul 11, 2015

    @poettering
    Member

    Closing this issue now. Should there be something more to fix, please reopen.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions