chmod: read the permission string and change it
chmod sets read, write and execute bits on files and directories for owner, group and others, in symbolic or numeric form. In the recorded run, as a non-root user (uid 1000), reading d/x fails with exit status 1 when the directory has mode 644 and works with mode 755; the error line is "cat: d/x: Permission denied".
Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.
TE-19-A: numeric mode sets exact bits; a directory without execute permission cannot be traversed by a normal user
Setup for this run, inside a throwaway directory (mktemp -d):
mkdir -p d; printf 'x\n' > f.txt; printf 'inner\n' > d/xCommand:
chmod 644 f.txt; echo file=$(stat -c %a f.txt); chmod 644 d; cat d/x 2>&1; echo rc_without_x=$?; chmod 755 d; cat d/x; echo rc_with_x=$?; id -uRecorded output:
file=644
cat: d/x: Permission denied
rc_without_x=1
inner
rc_with_x=0
1000TE-19-B: chmod u+x adds the execute bit for the owner to a file set to mode 600
Setup for this run, inside a throwaway directory (mktemp -d):
printf 'x\n' > f.txtCommand:
chmod 600 f.txt; stat -c %a f.txt; chmod u+x f.txt; stat -c %a f.txtRecorded output:
600
700Exit status: 0. This status and the output match what was written before the run.
TE-19-C: expected non-zero exit: chmod rejects a numeric mode that contains the digit 9
Setup for this run, inside a throwaway directory (mktemp -d):
printf 'x\n' > f.txtCommand:
chmod 999 f.txtRecorded output: none, standard output was empty.
Standard error from the same run:
chmod: invalid mode: ‘999’
Try 'chmod --help' for more information.Exit status: 1. This status and the output match what was written before the run.
Reading the recorded output
The first line, file=644, is the mode that stat reports for f.txt after chmod 644. Next, the same user tried to read d/x while the directory d had mode 644, which has no execute bit. The read failed with Permission denied and status 1. After chmod 755 on the directory, the same read printed inner and the status was 0. The last output line shows that this user has uid 1000. In this run the only change between failure and success was the mode of the directory d.
TE-19-B: stat printed 600 after chmod 600, and 700 after chmod u+x on the same file. TE-19-C: chmod 999 f.txt exited with status 1. Standard error holds chmod: invalid mode: ‘999’ and a line that starts with Try 'chmod --help'.
Limits
Traditional rwx model only; directory x means traverse; ACLs and special bits are out of scope.
Source
Evidence
TE-19-A: numeric mode sets exact bits; a directory without execute permission cannot be traversed by a normal user
- logs: one recorded log for each row above
- Recorded on: Linux x86_64, kernel 7.3.4; bash 5.1.16; git 2.34.1; python 3.10.12; findutils 4.8.0; grep 3.7; sed 4.8; gawk 5.1.0; tar 1.34; curl 7.81.0. Locale C.UTF-8, TZ=UTC.
Evidence table
| Test | What it checks | Exit | Verdict | Log sha256 (first 12) | |---|---|---|---|---| | TE-19-A | numeric mode sets exact bits; a directory without execute permission cannot be traversed by a normal user | 0 | PASS | 06c8bb5f0082 | | TE-19-B | chmod u+x adds the execute bit for the owner to a file set to mode 600 | 0 | PASS | 673fc191475c | | TE-19-C | expected non-zero exit: chmod rejects a numeric mode that contains the digit 9 | 1 | PASS | 04025b7c072e |
Every row has a recorded log holding the setup commands, the command, stdout, stderr, exit status and the final directory state. The first 12 characters of the log's sha256 are in the table.
All full guides: All guides