Sub topic 18
File Protection and Permissions
Assume you know processes, system calls, user and kernel mode, and binary notation. This chapter explains how a file system decides whether a process may read, modify, or execute a file.
Protection as an Access Check
File protection controls which subjects may perform which operations on objects. A subject is usually a user or process. An object may be a file or directory. The operating system checks permission data before completing operations such as open, read, write, or execute.
A common Unix-like model divides users into three classes:
- Owner: the user associated with the file.
- Group: users belonging to the file's group.
- Other: every remaining user.
Each class can have three basic permissions:
rmeans read.wmeans write.xmeans execute for a file, or search and enter for a directory.
For a regular file, rwxr-x--- means:
| Class | Read | Write | Execute | Numeric value |
|---|---|---|---|---|
| Owner | yes | yes | yes | 7 |
| Group | yes | no | yes | 5 |
| Other | no | no | no | 0 |
The numeric form is 750. Read, write, and execute have values 4, 2, and 1. Add the enabled values for each class.
Directory Permissions
Directory permissions have different effects from file permissions:
rallows listing directory names.wallows creating, deleting, or renaming entries when combined withx.xallows traversing the directory and accessing an entry when its name is known.
A user may therefore have permission to enter a directory without being able to list its contents.
When a process accesses /a/b/file, the kernel checks search permission on each directory in the path. It then checks the requested operation against the file's permissions. A process's effective user and group identifiers determine which permission class applies.
ACLs and Least Privilege
Traditional mode bits provide one owner, one group, and one other category. An access control list (ACL) extends this model with entries for particular users or groups. ACLs are useful when a project needs to share one file with a specific colleague without granting access to everyone in the group.
Protection should follow least privilege: grant only the operations and users required. Programs should avoid running with unnecessary privileges. Special mechanisms such as set-user-ID can change a program's effective identity, so they require careful control.
Exercise
A file has mode 640. May a group member read it? May that member execute it?
Show answer
Yes. The group value is 4, so group members have read permission. The group value contains neither 2 nor 1, so they cannot write or execute the file.