Skip to content

Commit b67a6a0

Browse files
asahilinaslp
authored andcommitted
virtio/fs: Drop O_NOATIME open flag if we don't have CAP_FOWNER
This makes overlayfs mounts with virtiofs lower dirs work. Signed-off-by: Asahi Lina <[email protected]>
1 parent bc25125 commit b67a6a0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/devices/src/virtio/fs/linux/passthrough.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ pub struct PassthroughFs {
340340
announce_submounts: AtomicBool,
341341
my_uid: Option<libc::uid_t>,
342342
my_gid: Option<libc::gid_t>,
343+
cap_fowner: bool,
343344

344345
cfg: Config,
345346
}
@@ -390,6 +391,9 @@ impl PassthroughFs {
390391
Some(unsafe { libc::getgid() })
391392
};
392393

394+
let cap_fowner =
395+
has_cap(None, CapSet::Effective, Capability::CAP_FOWNER).unwrap_or_default();
396+
393397
// Safe because we just opened this fd or it was provided by our caller.
394398
let proc_self_fd = unsafe { File::from_raw_fd(fd) };
395399

@@ -408,6 +412,7 @@ impl PassthroughFs {
408412
announce_submounts: AtomicBool::new(false),
409413
my_uid,
410414
my_gid,
415+
cap_fowner,
411416
cfg,
412417
})
413418
}
@@ -676,8 +681,15 @@ impl PassthroughFs {
676681
Ok(())
677682
}
678683

679-
fn do_open(&self, inode: Inode, flags: u32) -> io::Result<(Option<Handle>, OpenOptions)> {
684+
fn do_open(&self, inode: Inode, mut flags: u32) -> io::Result<(Option<Handle>, OpenOptions)> {
680685
debug!("do_open: {:?}", inode);
686+
if !self.cap_fowner {
687+
// O_NOATIME can only be used with CAP_FOWNER or if we are the file
688+
// owner. Not worth checking the latter, just drop it if we don't
689+
// have the cap. This makes overlayfs mounts with virtiofs lower dirs
690+
// work.
691+
flags &= !(libc::O_NOATIME as u32);
692+
}
681693
let file = RwLock::new(self.open_inode(inode, flags as i32)?);
682694

683695
let handle = self.next_handle.fetch_add(1, Ordering::Relaxed);

0 commit comments

Comments
 (0)