Ny security gained by having a file with 4xx permsion instead of 6xx

permissionsSecurity

If a file can only be read by its owner (400), is this any more secure than that file having read write permissions?

At best wouldn't this just help prevent you making stupid mistakes with your own files, rather than add any actual security? If you own a file, then you can alter its permissions. So if someone malicious gained access to a user, then having a file owned by that user set to 400 wouldn't prevent the attacker changing permissions on the file and writing to it?

Is there any security gained by having a file not writeable by its owner?

Best Answer

If your threat model is binary — either the user account is not compromised or it is fully compromised (arbitrary command execution) — there isn't any difference. As you note, the attacker can just chmod u+w the file.

Partial compromise, however, can happen. E.g., if the attacker only gains "write to any file", then he can't write to the 0400 file. This is of questionable benefit in a lot of cases though — "write to any file" can often be elevated to arbitrary command fairly easily (e.g., write to ~/.bashrc).

Further, with write permission on the parent directory, you can still delete (unlink) a mode 0400 file. Meaning an attacker could delete the existing file and put a new one in place using the same name.

The one "security" use that comes to mind is a FTP (etc.) dropbox. You could put a README file in there, mode 0400. If your dropbox parent directory is set to a+rwxt, then everyone can add new files there (and due to +t) only delete files they own. So your README would be protected.

So I think overall it's a prevent accidents feature more than a security feature.

Related Question