Commit 2546c4a
PhysicalMemory: open /tmp lock file with O_NOFOLLOW (fix symlink redirect)
Summary:
`PhysicalMemory`'s constructor opened its lock file `/tmp/pmem_<phyAddr>_lock` with `O_CREAT | O_WRONLY` (no `O_NOFOLLOW`). The path is predictable from the device tree, and this process runs as root, so on an image where an unprivileged user can write to `/tmp` a local attacker could pre-place the path as a symlink to a sensitive root-writable target and have the `O_CREAT | O_WRONLY` open follow the link.
This adds `O_NOFOLLOW` (the open refuses to follow a pre-planted symlink) and `O_CLOEXEC` (avoid leaking the lock fd across exec). The file remains a shared advisory lock reused across processes, so `O_EXCL` is intentionally not used.
Addresses a LOW finding from the FBOSS AI security scan (AVDP).
Reviewed By: zechengh09
Differential Revision: D114768813
fbshipit-source-id: 7916bd3e7e3aee79bfad5fb394f3dfb0a7ec22c11 parent 521e794 commit 2546c4a
1 file changed
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
0 commit comments