Skip to content

Commit ee3e6e8

Browse files
authored
Merge pull request #62 from rust-windowing/seal-shrink
wayland: Seal memfd to prevent shrinking
2 parents 2cdbb48 + 165a15e commit ee3e6e8

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/wayland/buffer.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,22 @@ use super::State;
1616

1717
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
1818
fn create_memfile() -> File {
19-
use nix::sys::memfd::{memfd_create, MemFdCreateFlag};
19+
use nix::{
20+
fcntl::{fcntl, FcntlArg, SealFlag},
21+
sys::memfd::{memfd_create, MemFdCreateFlag},
22+
};
2023

2124
let name = unsafe { CStr::from_bytes_with_nul_unchecked("softbuffer\0".as_bytes()) };
22-
let fd = memfd_create(name, MemFdCreateFlag::MFD_CLOEXEC)
23-
.expect("Failed to create memfd to store buffer.");
25+
let fd = memfd_create(
26+
name,
27+
MemFdCreateFlag::MFD_CLOEXEC | MemFdCreateFlag::MFD_ALLOW_SEALING,
28+
)
29+
.expect("Failed to create memfd to store buffer.");
30+
let _ = fcntl(
31+
fd,
32+
FcntlArg::F_ADD_SEALS(SealFlag::F_SEAL_SHRINK | SealFlag::F_SEAL_SEAL),
33+
)
34+
.expect("Failed to seal memfd.");
2435
unsafe { File::from_raw_fd(fd) }
2536
}
2637

0 commit comments

Comments
 (0)