-2

Assuming root privileges are unavailable to user A and user B. Suppose:

  • User A makes directory X with 777 permissions
  • User B then makes a directory X/Y with 755 permissions.
  • User B then makes a file in X/Y/troll with 755 permissions.

What is the correct behavior if user A tries to run:

rm -rf X/Y

What about on the "troll" file? I have just tested this on my machine and user A cannot delete user B's files. Is this correct?

If so, does that mean user B could make a very large file in A's directory that A could not delete and thus exceed A's quota?

Viktor
  • 19

2 Answers2

2

Yes this is expected behavior and as you point out it can be used to troll another user who has given others write permission on their directory. As you show correctly a directory without write permission created with contents by a "troll" user can only be deleted by that user and root.

This is derived from the fact that you cannot remove any directory which is not empty and you cannot modify another user's directory without permission.

Typically this doesn't cause a problem with resource limits (quotas) as they are usually calculated by file ownership not directory location and this is one reason that regular users cannot chown their own files to another user. Otherwise they could pass (chown) a user a file to which that user has no access to delete it.

There is still a way to troll quotas with this: if user A changed permissions on X after user B added a file to it:

chmod 700 X

User B would then be unable to delete the file. Without a hardlink to any files there they couldn't view or rewrite them either. While you cannot move directories, you can move another user's file if you have write permission on the parent directory. So world writable directories are generally ill advised.

Instead, in Linux when passing files to another user, always leave the files in your own directory and give read access. The other user can copy the files for themselves with no risk to you or them.

In almost every case the answer to this type of behavior is to ask the troll user politely to stop and then report them user to the sysadmin if they don't.

0

Suppose you don't have any other fancy stuff like stick bit or ACL or file capabilities or something.

Since A can't write to Y, A can't unlink the troll file, then Y is not empty, so it can't be deleted, eventually, nothing would happen at all.

Whether a process of FSUID=A can unlink a file owned B really depends on … many conditions. Please focus on credentials of process instead of talking about usernames all the time.

So does your last question. Linux really have so much fancy stuff, do you have permission to do something? It really depends on so many conditions…