Commit 2045edd
committed
pidfile: open with O_NOFOLLOW to prevent symlink TOCTOU on POSIX
The pidfile path is operator-controlled and typically lives in a
root-owned directory like /var/run, so this is not exploitable in
the standard threat model. However, if an operator configures a
pidfile path in a directory writable by an unprivileged user, that
user could pre-place a symlink to cause Falco (running as root) to
overwrite an arbitrary file with the PID on startup.
Replace the std::ofstream open with a raw POSIX open() using
O_NOFOLLOW | O_CLOEXEC on non-Windows platforms. The open will now
fail with ELOOP if the path is a symlink, closing the
defence-in-depth gap with no behaviour change for legitimate users.
Windows builds retain the original std::ofstream path since
O_NOFOLLOW / O_CLOEXEC are not available on the Windows toolchain
and the Linux-as-root threat model that motivates the hardening
does not apply to Falco's Windows build.1 parent cd1a862 commit 2045edd
1 file changed
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
21 | 27 | | |
22 | 28 | | |
23 | 29 | | |
| |||
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
37 | 72 | | |
38 | 73 | | |
39 | 74 | | |
| |||
47 | 82 | | |
48 | 83 | | |
49 | 84 | | |
| 85 | + | |
50 | 86 | | |
51 | 87 | | |
52 | 88 | | |
0 commit comments