Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleans /tmp/ida every time ida is called #853

Merged
merged 5 commits into from
Aug 10, 2018

Conversation

gitoleg
Copy link
Contributor

@gitoleg gitoleg commented Aug 8, 2018

fix #720

Just remove dump files from /tmp/ida before any ida launch

fix BinaryAnalysisPlatform#720

This PR removes dump files from `/tmp/ida` before any ida launch
Copy link
Member

@ivg ivg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code doesn't prevent bap from failing because ida dump exists because of TOCTOU bug. Also it may interact with other processes.

You shall create a lock file and cleanup the folder while have an exclusive access to it.

Also, your code is hard to read, for such a simple operation as rm -f /tmp/ida/*.dmp. It shall not be that bad. There is no need to use FileUtil if they do not make your code more readable, plain OCaml is sufficient here,

let tmp = "/tmp/ida in
if Sys.file_exists tmp && Sys.is_directory tmp then 
   Sys.readdir tmp |> Array.iter ~f:(fun n -> 
       if Filename.check_suffix n ".dmp"  then Sys.remove n)

Just add the locking procedure and you are done.

@ivg
Copy link
Member

ivg commented Aug 8, 2018

Please, look into plugins/cache/cache_main.ml for the inspiration on file locks.

let cleanup_minidump () =
let is_dump x = String.equal (Filename.extension x) ".dmp" in
let dump_path = "/tmp/ida" in
if Sys.file_exists dump_path then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will fail if dump_path is a file, add Sys.is_directory

@@ -79,8 +81,24 @@ let setup_headless_env path =
if old_path <> "" then Unix.putenv var old_path
with _ -> ()

let cleanup_minidump () =
let is_dump x = String.equal (Filename.extension x) ".dmp" in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Filename.check_suffix n ".dmp"
in general use the most specialized function available. It conveys you intentions better and is usually more efficient and straightforward

| [] -> ()
| files ->
info "ida minidump is not empty";
let lock = sprintf "%s/lock" dump_path in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protect this code with finally, to ensure that the file is always unlocked.

| files ->
info "ida minidump is not empty";
let lock = sprintf "%s/lock" dump_path in
let lock = Unix.openfile lock Unix.[O_RDWR; O_CREAT] 0o640 in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the lockfile is global it should be readable (and thus shareable) by all users, so provide corresponding rights.

Consider the scenario when BAP is run by two different users, the first user will create a lock file, while the second will not be able to graph the lock as she will fail on open.

@ivg ivg merged commit c81a157 into BinaryAnalysisPlatform:master Aug 10, 2018
@gitoleg gitoleg deleted the ida-minidump branch October 10, 2018 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The IDA service should cleanup minidump before
2 participants