| 1 |
.. title:: clang-tidy - android-cloexec-open |
| 2 |
|
| 3 |
android-cloexec-open |
| 4 |
==================== |
| 5 |
|
| 6 |
A common source of security bugs is code that opens a file without using the |
| 7 |
``O_CLOEXEC`` flag. Without that flag, an opened sensitive file would remain |
| 8 |
open across a fork+exec to a lower-privileged SELinux domain, leaking that |
| 9 |
sensitive data. Open-like functions including ``open()``, ``openat()``, and |
| 10 |
``open64()`` should include ``O_CLOEXEC`` in their flags argument. |
| 11 |
|
| 12 |
Examples: |
| 13 |
|
| 14 |
.. code-block:: c++ |
| 15 |
|
| 16 |
open("filename", O_RDWR); |
| 17 |
open64("filename", O_RDWR); |
| 18 |
openat(0, "filename", O_RDWR); |
| 19 |
|
| 20 |
// becomes |
| 21 |
|
| 22 |
open("filename", O_RDWR | O_CLOEXEC); |
| 23 |
open64("filename", O_RDWR | O_CLOEXEC); |
| 24 |
openat(0, "filename", O_RDWR | O_CLOEXEC); |