Assignment 2 due Nov 16th.
This page will be updated with more indications as I get more questions.
glpsol).glpsol on an example file to check that it
works.myscript.sh), make the script executable
(chmod +x myscript.sh), then run the script file
(./myscript.sh). This has the added advantage of allowing
you to re-run the exact same building or fuzzing commands later.GLPK’s ./configure script options to
choose a compiler (e.g. AFL++’s compile-with-instrumentation scripts)
and to choose compiler options (e.g. enabling ASan or UBSan). Run
./configure --help | less to see how to.GLPK with
static linking. Disable dynamic linking and enable
static linking in the options of ./configure. It may be
convenient to create a small script that calls ./configure
with your chosen options../configure, you need to run
make clean to make sure that the next compilation will
re-build everything with your updated options.-j option of make allows parallel
(hence faster) compilations. For example, use -j 8 if your
computer has 8 parallel threads.glpsol executable is in the examples/
directory.glpsol was already installed on your computer,
beware of which glpsol executable you are running
(you probably want to run the one you just compiled).afl-clang-lto if it is available on your
platform. Fuzzing will be slightly faster with
afl-clang-lto, but compilation will be significantly
slower. One option would be to test everything and start fuzzing with
afl-clang-fast variants, and only use LTO for long
(e.g. overnight) runs in an effort to find more crashes.clang or with afl-clang, with or without
sanitizers, etc.) Once you successfully produce a glpsol
executable, I would advise copying it somewhere for safekeeping.make
without the -j option and try to fix the compilation error.
Once it is fixed, you can interrupt the non-parallel build (control+C),
then resume building in parallel.For the starting set of input files, afl-fuzz works
best with a limited number (5 to 20) of small valid files (smaller than,
say, 10 kB, and can be as small as 5 to 10 bytes) that are different
from each other. Invalid files can be included, but they are typically
not useful. The examples/ directory in the
GLPK source code contains many .mps files in
the “fixed MPS” format (--mps option of
glpsol), and .mod files in the GNU MathProg
format (--math option of glpsol). For example
files in the “free MPS” format, see https://miplib2010.zib.de/miplib3/miplib.html.
For faster and more effective fuzzing, discard large input files, as
well as input files that GLPK is slow to parse. It is also
easier to understand bugs when the input files are small. One way to get
smaller GNU MathProg files is to remove comments.
The first time you run afl-fuzz, it may ask you to
adjust system settings to allow it to run faster. Whenever those
adjustments are easy to perform, it is recommended to follow its advice.
For example, this command
echo core | sudo tee /proc/sys/kernel/core_pattern
is easy to run and is essentially required for AFL++ to work properly on Linux and WSL2.
For fuzzing, you can compile with UBSan enabled to find more bugs, but do not enable ASan (it creates issues when used with AFL++). Once you found a crash, you can recompile with ASan enabled to help track down the bug.
To focus on the input parsing code, use the --check
option of glpsol to only run that code (for faster
fuzzing).
AFL++ may give you warnings about your input size, or your computer configuration. In such cases, read the instructions carefully. You can choose to address the issues or ignore them (the instructions explain how the warning can be discarded).
When afl-fuzz is running, a red message indicating
“no new paths” (or something similar) means that fuzzing is probably not
working. The most common cause of that is that the fuzzed program
(glpsol in our case) immediately exits with an error
message.
The first thing to try in such case is to run the same
glpsol command outside of afl-fuzz, and make
sure that everything is working fine.
If it is, then there must be a difference between us running
glpsol manually and afl-fuzz running it. The
next two points could be causes for such difference.
By default afl-fuzz chooses a name and directory for
the “input” files it creates. If this confuses glpsol, the
problem can be worked around with the -f option of
afl-fuzz (see afl-fuzz -h for details), which
forces it to use a fixed name and path for input files.
If everything is running properly, afl-fuzz should
find bugs within the first 2 to 5 minutes.
Once afl-fuzz is running, it keeps looking for new
crashes until you stop it. At first, it should be plenty enough to stop
it after 5-10 crashes.
GLPK code and recompile it, it will be
convenient to compile it without AFL++ whenever not fuzzing (remember to
run make clean before or after ./configure
every time).abort(). A call to
abort() ends a program. When run with
valgrind, you get a stack trace at the point
abort() was called (i.e. the functions that were called
leading to abort()). On MacOS, valgrind may
not work, in which case you can use lldb (see below).GLPK to get more
information about bugs. You can insert printf() statements,
modify logic, etc.grep command is useful for navigating a foreign
codebase.exit() call before it
is triggered. This will allow the fuzzer to find other bugs.main() at the
“bottom”).GLPK’s parser code.Run AFL++ on WSL2 (do not use WSL1).
AFL++ Installation
apt-get install afl++Instructions are here: https://github.com/AFLplusplus/AFLplusplus/blob/stable/docs/INSTALL.md.
As far as I have been told, the docker-based instructions
don’t seem to work, so it is probably better to skip them.
Your WSL2 distribution probably has a version of LLVM more recent than 18. Therefore, ignore the instructions aiming to install version 18 specifically, replacing
sudo apt-get install -y lld-14 llvm-14 llvm-14-dev clang-14 || sudo apt-get install -y lld llvm llvm-dev clangby
sudo apt-get install -y lld llvm llvm-dev clangMake sure that your operating system is fully updated.
Ensure Homebrew is installed
AFL++ Installation
brew install afl++afl-clang-lto. It is ok, use
afl-clang-fast instead./opt/homebrew/afl-clang-fast/opt/homebrew/afl-clang-fast++/opt/homebrew/afl-fuzzThe installation instructions for MacOS are here: https://github.com/AFLplusplus/AFLplusplus/blob/stable/docs/INSTALL.md#macos-on-x86_64-and-arm64 but they are a bit out of date, so before following them, first try this:
Just download AFL++ source and run make:
git clone https://github.com/AFLplusplus/AFLplusplus
cd AFLplusplus
makeIf you get the message “LLVM mode could not be built … please install llvm-13”, then make sure that llvm is installed with brew:
brew install llvm
then find the llvm-config utility, it should be
somewhere like /opt/homebrew/Cellar/llvm/19.1.3/bin/ (the
exact path will vary depending on the version of LLMV installed).
Then, try to run AFL++’s Makefile again, but specifying where it can
find llvm-config, like:
LLVM_CONFIG=/opt/homebrew/Cellar/llvm/19.1.3/bin/llvm-config makeYou may get a message “LLVM LTO mode could not be build”. You can safely ignore this.
Test failure messages containing “assembler command failed” can
be ignored as well, as long as you get afl-clang-fast and
afl-clang-fast++.
Note the full paths of the afl-clang-fast and
afl-clang-fast++ executable binaries. You will need them
later.
If you see a message
ld: unsupported tapi file type '!tapi-tbd' in YAML file
when trying to compile, then something went wrong with you system
configuration. Find out where the ld utility is located by
running:
which ld
You should get /opt/homebrew/bin/ld or
/usr/local/bin/ld (or possibly /usr/bin/ld)
but not anything to do with conda. If you
see conda in ld’s path, then you must disable
Anaconda.
conda deactivate
Note that even if it is deactivated now, Anaconda may have interferred with how LLVM, clang and AFL++ were installed. You may have, for example to re-run, with Anaconda deactivated,
brew install afl++To get a stack trace, you can
use lldb with the following command:
lldb path/to/glpsol -o 'run -i path/to/crash/file' -o 'bt' -o 'quit'where you need to adjust path/to/bin/scip and
-f path/to/crash/file.mps to your specific needs.
Explanations:
lldb the path to the binary executable (and,
optionally, additional parameters).lldb starts in an interactive mode in which
we can type commands. The -o command command-line parameter
is equivalent to typing command in interactive mode.run commands tells lldb to run the
executable. We type after run the parameters we want to
pass to the executable. In our case, we could want glpsol
to read and solve a file, hence -i path/to/crash/file.bt commands tells lldb to print the
stack trace.quit commands prevents lldb from
entering interactive mode.If you get an error message about llvm-ar not being
found, you need to update your PATH environment variable so
that it can be found.
First make sure llvm is installed with brew:
brew install llvmThen, find the llvm-ar utility. It should be
somewhere like /opt/homebrew/Cellar/llvm/19.1.3/bin/ (the
exact path will vary depending on the version of LLMV installed). As a
last resort, you can use the following commands to find the exact path
(this will be a bit slow):
find /usr -name llvm-ar
find /opt -name llvm-arNext, you can run mfile.py with the
PATH variable overriden:
PATH=/opt/homebrew/Cellar/llvm/19.1.3/bin/:$PATH ./mfile.pyYou can make this change permanent to the current shell session by running:
export PATH=/opt/homebrew/Cellar/llvm/19.1.3/bin/:$PATHYou can make this change permanent to all shell sessions by
adding the line above to your ~/.zshrc file. (However,
remember that this will only apply to shell sessions opened after the
change.)
If you get an error message about MacOSX26.sdk not
being found (or MacOSX14.sdk, or any other version, as long
as it corresponds to the version of OSX you have installed), you can
create that file. For example, if the message claims that
/Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk is
not found, but you have
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
(without the version 26 in the file name), then you create
the missing file by running the following commands (adapt them to the
version of the missing file):
cd /Library/Developer/CommandLineTools/SDKs
sudo ln -s MacOSX.sdk MacOSX26.sdk
# your password will be prompted hereIf afl-fuzz complains about shmget()
failing or other issues at startup, you may have to run:
sudo afl-system-configbefore running afl-fuzz