If you ran the command
chmod -777 /foo, it could have some weird functionality. Most likely, it will negate the bits you are passing in the octal negation of 777 (which is 111111111 in binary, which is important), which is not actually possible to represent, since
chmod is using a 9 bit set for file permissions (1 bit per permission for read, write, execute * owner,group,user), which is an unsigned number (cannot be negative).
Let's assume that you can represent signed numbers (negative and positive values). If you find 2's complement of 777 (0b111111111), then you can figure out the exact behavior of (and number you are passing to) the command:
1000000000 #this number will cause an overflow because it is 512
#since our range is only -256 -> 255
What does all this mean? You told the kernel "Hey, make the permissions for this folder 1000000000". The kernel responded with "Ok" and did what you asked. Now your filesystem permissions are exactly that,
--------- root root /. This is all assuming that I (and your kernel/CPU) did the math correctly.
The root filesystem's (what
/ is) default permissions are usually 755. The easiest way to fix this is to log in and switch to tty using Ctrl+F1 (which will take you to tty1, tty2-6 are open as well, with tty7 being the location of the current X session). You can log in as root (or as a regular user, but use
sudo before each command below) and run this command:
chmod 755 /
That should fix the issue you are having.