Skip to content

Commit 3026a83

Browse files
danieldgvberger
authored andcommitted
Set F_SEAL_SHRINK on memfds we create
This prevents us from ever shrinking the file (which we never do) and lets the wayland server skip configuring its SIGBUS handler when accessing our buffers.
1 parent 9824d71 commit 3026a83

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/shm/mempool.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,18 @@ fn create_shm_fd() -> io::Result<RawFd> {
250250
loop {
251251
match memfd::memfd_create(
252252
CStr::from_bytes_with_nul(b"smithay-client-toolkit\0").unwrap(),
253-
memfd::MemFdCreateFlag::MFD_CLOEXEC,
253+
memfd::MemFdCreateFlag::MFD_CLOEXEC | memfd::MemFdCreateFlag::MFD_ALLOW_SEALING,
254254
) {
255-
Ok(fd) => return Ok(fd),
255+
Ok(fd) => {
256+
// this is only an optimization, so ignore errors
257+
let _ = fcntl::fcntl(
258+
fd,
259+
fcntl::F_ADD_SEALS(
260+
fcntl::SealFlag::F_SEAL_SHRINK | fcntl::SealFlag::F_SEAL_SEAL,
261+
),
262+
);
263+
return Ok(fd);
264+
}
256265
Err(nix::Error::Sys(Errno::EINTR)) => continue,
257266
Err(nix::Error::Sys(Errno::ENOSYS)) => break,
258267
Err(nix::Error::Sys(errno)) => return Err(io::Error::from(errno)),

0 commit comments

Comments
 (0)