Skip to content

Commit

Permalink
Fix line split in secure mount and notify
Browse files Browse the repository at this point in the history
Currently the code splits the mount command line returns
incorrectly. This results in a non match which means a new
mount is created everytime, instead of using an existing mount.

This results in many mounts being present on the system, every
time the agent is restarted.

This is due to the split element being a back slash `\` whereas
it should be a whitespace `' '`

There is also no feedback provided to the user when an existing
mount is used. This information should be provided to the user.

Resolves: #83
  • Loading branch information
Luke Hinds authored and lukehinds committed Oct 30, 2019
1 parent bdf879b commit 1194c9a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/secure_mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,27 @@ fn check_mount(secure_dir: &str) -> Result<bool, Box<String>> {

// Check mount list for secure directory
for line in lines {
let tokens: Vec<&str> = line.split('/').collect();
let tokens: Vec<&str> = line.split(' ').collect();

if tokens.len() < 3 {
continue;
}

if tokens[2] == secure_dir {
if tokens[0] != "tmpfs" {
return emsg(format!("secure storage location {} already mounted on wrong file system type: {}. Unmount to continue.", secure_dir, tokens[0]).as_str(), None::<String>);
return emsg(
format!(
"secure storage location {} already mounted on wrong file system type: {}. Unmount to continue.",
secure_dir,
tokens[0]).as_str(),
None::<String>
);
} else {
info!(
"Using existing secure storage tmpsfs mount {}",
secure_dir
);
}

return Ok(true);
}
}
Expand All @@ -54,7 +64,7 @@ fn check_mount(secure_dir: &str) -> Result<bool, Box<String>> {
* implementation as the original python version, but the chown/geteuid
* functions are unsafe function in Rust to use.
*/
fn mount() -> Result<String, Box<String>> {
pub fn mount() -> Result<String, Box<String>> {
// Use /tmpfs-dev directory if MOUNT_SECURE flag is set, which doesn't
// mount to the system. This is for developement envrionment. No need to
// mount to file system.
Expand Down Expand Up @@ -83,6 +93,7 @@ fn mount() -> Result<String, Box<String>> {
let secure_dir = format!("{}/secure", common::WORK_DIR);
let secure_size =
config_get("/etc/keylime.conf", "cloud_agent", "secure_size");

match check_mount(&secure_dir) {
Ok(false) => {
// If the directory is not mount to file system, mount the directory to
Expand All @@ -92,6 +103,7 @@ fn mount() -> Result<String, Box<String>> {

// Create directory if the directory is not exist. The
// directory permission is set to 448.

if !secure_dir_path.exists() {
if let Err(e) = fs::create_dir(secure_dir_path) {
return emsg("Failed to create directory.", Some(e));
Expand Down

0 comments on commit 1194c9a

Please sign in to comment.