Skip to content

Commit

Permalink
vm/adb: a more reliable way to delete broken symlinks
Browse files Browse the repository at this point in the history
When fuzzing Android, the executor sometimes leaves broken symlinks that
point to non-existent directories. The command that adb.go was using to
delete the leftover symlinks:
  `find /data/syzkaller* -type l -exec unlink {} \;`
actually choked on such files and led to syzkaller rebooting the device
indefinitely.
Parse the output of `find /data/syzkaller*` to obtain the list of broken
symlinks and pass them to `unlink` one by one.

Fixes #2831.
  • Loading branch information
ramosian-glider committed Dec 1, 2023
1 parent f819d6f commit 78b0f6e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vm/adb/adb.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,11 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) {
// Remove temp files from previous runs.
// rm chokes on bad symlinks so we must remove them first
if _, err := inst.adb("shell", "ls /data/syzkaller*"); err == nil {
if _, err := inst.adb("shell", "find /data/syzkaller* -type l -exec unlink {} \\;"+
" && rm -Rf /data/syzkaller*"); err != nil {
if _, err := inst.adb("shell", "find /data/syzkaller* 2>&1 | grep 'No such file' "+
"| sed 's/.*\\/data/\\/data/;s/:.*//' | xargs -r unlink"); err != nil {
return nil, err
}
if _, err := inst.adb("shell", "rm -Rf /data/syzkaller*"); err != nil {
return nil, err
}
}
Expand Down

0 comments on commit 78b0f6e

Please sign in to comment.