Skip to content

Commit 2e7a64f

Browse files
repository: don't leak repository fd
We're leaking fds into the sandbox in flatpak-rs. Let's fix these obvious ones. Signed-off-by: Allison Karlitskaya <[email protected]>
1 parent 03f4eb2 commit 2e7a64f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

crates/composefs/src/repository.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<ObjectID: FsVerityHashValue> Repository<ObjectID> {
7676
let path = path.as_ref();
7777

7878
// O_PATH isn't enough because flock()
79-
let repository = openat(dirfd, path, OFlags::RDONLY, Mode::empty())
79+
let repository = openat(dirfd, path, OFlags::RDONLY | OFlags::CLOEXEC, Mode::empty())
8080
.with_context(|| format!("Cannot open composefs repository at {}", path.display()))?;
8181

8282
flock(&repository, FlockOperation::LockShared)
@@ -144,7 +144,11 @@ impl<ObjectID: FsVerityHashValue> Repository<ObjectID> {
144144
fdatasync(&file)?;
145145

146146
// We can't enable verity with an open writable fd, so re-open and close the old one.
147-
let ro_fd = open(proc_self_fd(&file), OFlags::RDONLY, Mode::empty())?;
147+
let ro_fd = open(
148+
proc_self_fd(&file),
149+
OFlags::RDONLY | OFlags::CLOEXEC,
150+
Mode::empty(),
151+
)?;
148152
drop(file);
149153

150154
enable_verity::<ObjectID>(&ro_fd).context("Enabling verity digest")?;

0 commit comments

Comments
 (0)