Skip to content

Commit

Permalink
virtio/fs: Drop O_NOATIME open flag if we don't have CAP_FOWNER
Browse files Browse the repository at this point in the history
This makes overlayfs mounts with virtiofs lower dirs work.

Signed-off-by: Asahi Lina <[email protected]>
  • Loading branch information
asahilina committed Dec 15, 2024
1 parent 19080a7 commit 6ad8a33
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/devices/src/virtio/fs/linux/passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ pub struct PassthroughFs {
announce_submounts: AtomicBool,
my_uid: Option<libc::uid_t>,
my_gid: Option<libc::gid_t>,
cap_fowner: bool,

cfg: Config,
}
Expand Down Expand Up @@ -390,6 +391,9 @@ impl PassthroughFs {
Some(unsafe { libc::getgid() })
};

let cap_fowner =
has_cap(None, CapSet::Effective, Capability::CAP_FOWNER).unwrap_or_default();

// Safe because we just opened this fd or it was provided by our caller.
let proc_self_fd = unsafe { File::from_raw_fd(fd) };

Expand All @@ -408,6 +412,7 @@ impl PassthroughFs {
announce_submounts: AtomicBool::new(false),
my_uid,
my_gid,
cap_fowner,
cfg,
})
}
Expand Down Expand Up @@ -676,8 +681,15 @@ impl PassthroughFs {
Ok(())
}

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

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

0 comments on commit 6ad8a33

Please sign in to comment.