Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Background: I have a cron job which chown's the directories of new users. More often than not, these users are already uploading files to the server before the job occurs.

So will files successfully have their ownership changed if they are in the process of being uploaded?

share|improve this question
It sounds like you need to make sure your users have the correct umask, and the directories need the correct group, and the setgid bit. – Zoredache May 14 '10 at 19:23
up vote 4 down vote accepted

I have a cron job which chown's the directories of new users.

I take it you mean both the directories of these new users, and all the contents of those directories (i.e. chown -R newuser:newuser /home/newuser-dir).

This is a race condition, much like in programming, except you are experiencing it at the system rather than process level, but it is still a security risk.

Mo is correct, unless you have a very strange requirement, it would be much better to use a uploading process that does not need such a background task to change file ownership.

Because in one sense you are taking unvalidated data (the uploaded file), and automatically setting the trust level to equivalent to a different, presumably a more trusted user, without necessarily ensuring the security of the files. This creates the potential for abusing this race condition, such as if the new user can create a symbolic or hard link to a system file (e.g. /etc/shadow) so they can obtain the hashed passwords to then mount an off-line password cracking attack. That would be sad.

share|improve this answer
wow, that had not occurred to me, that's devious, if the ftpd allows one to break out of the chroot somehow... or if the directory structure weren't set up too well, as it kind of sounds, in this case... – cpbills May 14 '10 at 19:30
They don't pay me just for my good looks. :) – mctylr May 14 '10 at 19:33
It's an old ftpd exploit as far as I can remember, back when ftp was popular. – mctylr May 14 '10 at 19:39
you get PAID?! :P – cpbills May 14 '10 at 19:39
peanuts (Literally. Bags of them. :-D) – voretaq7 May 14 '10 at 20:00

Ownership information is set when the file is created. If it's changed after that, it will stay unless the program rewrites ownership information again after the fact.

share|improve this answer

Assuming you’re doing a recursive chown, and the files are written somewhere within the tree that you’re recursively changing the ownership of, then yes.

What user are they uploading files as, though? How do they have write permission if the directories haven’t been chowned yet? Why not set the correct permissions before giving them access?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.