Home directory not (really) being unmounted after logout?

Bug #706078 reported by Armin Kunaschik
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ecryptfs-utils
In Progress
Undecided
Unassigned

Bug Description

I'm running vanilla ecrypt-fs of Ubuntu 10.10 and encrypted the whole home directory of the user "user".
The encrypted home is generated with "ecryptfs-migrate-home -u user". No additional configuration.
The ecryptfs mount looks like this:
/home/user/.Private on /home/user type ecryptfs ....

I have a script inside the encrypted home called /home/user/garbage.sh containing the following line:
/bin/date >>/home/user/garbage.out

Now I'm creating a cronjob with the following crontab entry:
0-59 * * * * /home/user/garbage.sh

The cronjob runs as expected when I'm logged in.
I logout and the ecryptfs mount disappears as expected.
"ls -l ~user" as root lists no garbage.* files.
Now I would expect that cron would fail to locate the script after I logout.
But this is not the case. The cronjob continues to run and is writing the timestamp every minute.
If I login again, I find the timestamp correctly written into the encrypted file. How is this possible?

Logging out again as user "user".
Now when I terminate cron (service cron stop), the cronjob is not executed anymore... this is expected.
I'd expect (again) that cron does not find the script when I re-start cron shortly after it's termination.
But now (at least to me) the unexplainable happens:
1. The cronjob continues to be executed.
2. The script continues to write timestamps into the encrypted file.

Logging in again as user "user" verifies: The timestamps were written to the file when user "user" was not logged in
and ecryptfs was not mounted.

Could anybody explain this trick to me?
It looks like a bug to me, but I want to make sure it's not a feature...
Thanks in advance!

Changed in ecryptfs:
assignee: nobody → Serge Hallyn (serge-hallyn)
Revision history for this message
Armin Kunaschik (armin-kunaschik) wrote :

as requested by Serge Hallyn assigned to ecryptfs-utils.
I could not (yet) figure out how assign this directly to a person

affects: ecryptfs → ecryptfs-utils
Changed in ecryptfs-utils:
assignee: Serge Hallyn (serge-hallyn) → nobody
assignee: nobody → Serge Hallyn (serge-hallyn)
Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

I created a new 10.10 server instance, and created user 'user1' using the command 'adduser --encrypt-home user1'. I logged in using ssh, created a file and made sure .bashrc looked ok. Logged out, and did 'ls /home/user1' as the root user. I only saw:

root@ip-172-56-125-2:/etc/pam.d# ls /home/user1
Access-Your-Private-Data.desktop README.txt

I also tried 'su - user1', and again after logout my home directory was unmounted.

Armin, how exactly do you log in? Are you using the stock gdm login manager shipped with Ubuntu?

Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Armin,

also, after you have logged out as the user using ecryptfs, could you do a 'ps -ef' and paste the result here?

Changed in ecryptfs-utils:
status: New → Incomplete
Revision history for this message
Armin Kunaschik (armin-kunaschik) wrote :

Regarding #2:
I created the user as normal user and converted the home directory.
I tried to log in via "su - user" or via "ssh user@localhost" and both works fine; the encrypted home is mounted.
I see also exactly the same behavior you describe after I log out: The home directory is unmounted.

Please try to reproduce the cron part. This is the disturbing part!

I'm currently not near my Linux box, so I have to delay the ps -ef part...

Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Armin,

sorry, I had misunderstood some of your original comment.

Is your garbage.sh script exactly the one line you showed? If not, please paste the whole thing. How did you enable the cronjob? Using 'crontab -e'?

Revision history for this message
Armin Kunaschik (armin-kunaschik) wrote :

garbage.sh contains only this one line and the cronjob was created with "crontab -e"

One thing comes to my mind: Maybe there are some credentials "cached" so the "su - user"
done internally by cron will "simply" mount the encrypted home and then execute the script.
This will probably be visible, if you add a "sleep 30" as first line.
So garbage.sh would look like:
<snip>
sleep 30
/bin/date >>/home/user/garbage.out
<snip>

Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

I'm sorry, I had asked you to file this bug based on my initial misunderstanding: I thought you had said at some point that after logging out, you could still see your encrypted contents.

The reason why cron can keep running your scripts with your encrypted home mounted is because /etc/pam.d/cron includes common-auth, which in turn includes pam_ecryptfs.so. So pam mounts your encrypted home for you.

Your next question is "why does it have my keys?" I assume that is because after you log out, your keyring is not being cleared. You can clear it manually by doing 'keyctl clear @u'. After that, cron will no longer be able to run your job.

This should have been fixed with bug https://bugs.launchpad.net/ecryptfs/+bug/313812. I will investigate further next week whether (a) my understanding is correct, and (b) why 313812 is not fixed if so.

Changed in ecryptfs-utils:
status: Incomplete → In Progress
Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Indeed, after you log out as the user who has an ecryptfs home, you can see with a

    cat /proc/key-users

that the key still exists.

Changed in ecryptfs-utils:
assignee: Serge Hallyn (serge-hallyn) → nobody
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.