mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-07 05:55:58 +01:00
util/shm: clear mode permission bits in allocate_shm_file_pair
This ensures the file cannot be re-opened with write permissions. Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3429
This commit is contained in:
parent
e646d882cf
commit
19896e7fb6
1 changed files with 9 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <wlr/config.h>
|
||||
|
@ -73,6 +74,14 @@ bool allocate_shm_file_pair(size_t size, int *rw_fd_ptr, int *ro_fd_ptr) {
|
|||
|
||||
shm_unlink(name);
|
||||
|
||||
// Make sure the file cannot be re-opened in read-write mode (e.g. via
|
||||
// "/proc/self/fd/" on Linux)
|
||||
if (fchmod(rw_fd, 0) != 0) {
|
||||
close(rw_fd);
|
||||
close(ro_fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
int ret;
|
||||
do {
|
||||
ret = ftruncate(rw_fd, size);
|
||||
|
|
Loading…
Reference in a new issue