Was changing ownership of everything to root the right thing to do?
No. It is, however, the quickest way I can think of to get the system to normal state.
- There are plenty of process which require some directories/files be owned by their user. Examples include logs, caches, working/home directories of some processes like MySQL, LightDM, etc. Especially log files can create a lot of problems.
- There are some applications which are
setuid
/setgid
, and so need their owner/group to be something specific. Examples include /usr/bin/at
, /usr/bin/crontab
, etc.
I think running chown caused some of the folder and file permissions to be changed. Is that normal?
I doubt modes got changed. If it did, it most definitely is not normal.
Would this cause any security vulnerabilities?
Since you just set /usr/bin/crontab
to be owned by root
, you now have a setuid application that opens an editor. I doubt any vulnerabilities compare to that. Of course, this is a blatant vulnerability, so something more insidious might now pop up. Overall, I'd recommend simply re-installing the system - or hopefully you have full-disk backups.
Apparently, chown(3)
is supposed to clear the setuid and setgid bits if the running process doesn't have the appropriate privileges. And man 2 chown
for Linux says:
When the owner or group of an executable file are changed by an
unprivileged user the S_ISUID
and S_ISGID
mode bits are cleared.
POSIX does not specify whether this also should happen when root does
the chown()
; the Linux behavior depends on the kernel version. In
case of a non-group-executable file (i.e., one for which the S_IXGRP
bit is not set) the S_ISGID
bit indicates mandatory locking, and is
not cleared by a chown()
.
So, it seems the devs and the standards committees have provided safegaurds.
man 3 chown
: "If the specified file is a regular file, one or more of the S_IXUSR, S_IXGRP, or S_IXOTH bits of the file mode are set, and the process does not have appropriate privileges, the set-user-ID (S_ISUID) and set-group-ID (S_ISGID) bits of the file mode shall be cleared successful return from chown()." (and a couple more lines on clearing suid and sgid bits) Any idea what theseS_IX*
bits are and what the appropriate privileges are? – muru Jul 06 '15 at 19:36