spolu / gym_fuzz1ng

OpenAI Gym environment for binary fuzzing based on afl
21 stars 10 forks source link

posix_ipc.ExistentialError: No shared memory exists with the specified name #7

Open davidleejy opened 5 years ago

davidleejy commented 5 years ago

Hello. Nice work wrapping AFL as an OpenAI gym environment :)

I am writing about a shared memory error that seems like a simple bug for someone who's familiar with the inter-process communication libraries ("posix_ipc" I think) used in this code base.

What I did

  1. Followed install instructions in README.md.
  2. Ran make all for gym_fuzz1ng/gym_fuzz1ng/mods/Makefile.
  3. Ran python dummy_simple_bits.py

which gave the following

~/code/gym_fuzz1ng$ python ./test/dummy_simple_bits.py 

Starting afl-forkserver...
Traceback (most recent call last):
  File "./test/dummy_simple_bits.py", line 62, in <module>
    main()
  File "./test/dummy_simple_bits.py", line 7, in main
    env = gym.make('FuzzSimpleBits-v0')
  File "/home/dl/anaconda3/envs/gymfuzz/lib/python3.5/site-packages/gym/envs/registration.py", line 167, in make
    return registry.make(id)
  File "/home/dl/anaconda3/envs/gymfuzz/lib/python3.5/site-packages/gym/envs/registration.py", line 119, in make
    env = spec.make()
  File "/home/dl/anaconda3/envs/gymfuzz/lib/python3.5/site-packages/gym/envs/registration.py", line 86, in make
    env = cls(**self._kwargs)
  File "/home/dl/anaconda3/envs/gymfuzz/lib/python3.5/site-packages/gym_fuzz1ng/envs/fuzz_simple_bits_env.py", line 16, in __init__
    super(FuzzSimpleBitsEnv, self).__init__()
  File "/home/dl/anaconda3/envs/gymfuzz/lib/python3.5/site-packages/gym_fuzz1ng/envs/fuzz_base_env.py", line 16, in __init__
    self.engine = coverage.Afl(self._target_path, args=self._args)
  File "/home/dl/anaconda3/envs/gymfuzz/lib/python3.5/site-packages/gym_fuzz1ng/coverage/coverage.py", line 100, in __init__
    self.fc = ForkClient(target_path, args)
  File "/home/dl/anaconda3/envs/gymfuzz/lib/python3.5/site-packages/gym_fuzz1ng/coverage/forkclient.py", line 107, in __init__
    _shm = SharedMemory(SHARED_MEM_NAME)
posix_ipc.ExistentialError: No shared memory exists with the specified name
davidleejy commented 5 years ago

Solved

Turns out afl-forkserver has checks that would abort the program if /proc/sys/kernel/core_pattern and /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor were not set to expected values. dummy_simple_bits.py pipes afl-forkserver's output to /dev/null so messages concerning the abort wouldn't show. Writing expected values to core pattern and cpu freq scaling governor solves this.

Just FYI: As of writing this, core pattern file is expected to contain value core. As of writing this, all cpus' scaling governor files are expected to contain value performance

BlackHat-S commented 1 year ago

I also encountered the same issue, but when I run the program in a virtual machine, I found that the file "/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor" does not exist. How can I solve it? And by the way, did you run the program on a virtual machine or a physical machine?