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.
rm
command in full. – Philip Couling Jun 27 '19 at 10:48