Skip to content

Commit 2546c4a

Browse files
srikrishnagopumeta-codesync[bot]
authored andcommitted
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: 7916bd3e7e3aee79bfad5fb394f3dfb0a7ec22c1
1 parent 521e794 commit 2546c4a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

fboss/lib/PhysicalMemory.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ PhysicalMemory::PhysicalMemory(uint64_t phyAddr, uint32_t size, bool mustLock)
4343
// construct the lock file name
4444
const auto lockFN = fmt::format("{}/pmem_{:x}_lock", kLockPath, phyAddr_);
4545

46-
// lock it
47-
lockFile_ = folly::File(lockFN, O_CREAT | O_WRONLY);
46+
// lock it. O_NOFOLLOW refuses a pre-planted symlink at the predictable /tmp
47+
// lock path (this process runs as root), and O_CLOEXEC avoids leaking the fd
48+
// across exec.
49+
lockFile_ = folly::File(lockFN, O_CREAT | O_WRONLY | O_NOFOLLOW | O_CLOEXEC);
4850
auto locked = lockFile_.try_lock();
4951
XLOG(DBG1) << folly::format(
5052
"{} to acquire lock, {}({})",

0 commit comments

Comments
 (0)