Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 85eb4f303f4fc9eb8edfd9be0f6f67d435af9972 authored by ha1215 on 23 April 2024, 01:54:36 UTC, committed by Tomas Mraz on 09 September 2024, 07:23:38 UTC
Minor WINDOWS.md cleanups
The possessive form of "Windows" has been updated from "Windows's"
to "Windows'".

The function call "a poll(2) call" has been specified as
"a poll(2) system call" for clarity.

The phrase "and supposed" has been corrected to "and was supposed" to
improve sentence structure.

The phrase "However Microsoft has" now includes a comma, revised to
"However, Microsoft has" to enhance readability.

The statement "Supporting these is a pain" has been adjusted to
"Supporting these can be a pain" to better convey potential variability
in user experience.

CLA: trivial

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Yang <kaishen.yy@antfin.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24242)
1 parent a5cd06f
  • Files
  • Changes
  • cc018ae
  • /
  • fuzz
  • /
  • README.md
Raw File
Cook and download a directory from the Software Heritage Vault

You have requested the cooking of the directory with identifier None into a standard tar.gz archive.

Are you sure you want to continue ?

Download a directory from the Software Heritage Vault

You have requested the download of the directory with identifier None as a standard tar.gz archive.

Are you sure you want to continue ?

Cook and download a revision from the Software Heritage Vault

You have requested the cooking of the history heading to revision with identifier swh:1:rev:85eb4f303f4fc9eb8edfd9be0f6f67d435af9972 into a bare git archive.

Are you sure you want to continue ?

Download a revision from the Software Heritage Vault

You have requested the download of the history heading to revision with identifier swh:1:rev:85eb4f303f4fc9eb8edfd9be0f6f67d435af9972 as a bare git archive.

Are you sure you want to continue ?

Invalid Email !

The provided email is not well-formed.

Download link has expired

The requested archive is no longer available for download from the Software Heritage Vault.

Do you want to cook it again ?

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • content
revision badge
swh:1:rev:85eb4f303f4fc9eb8edfd9be0f6f67d435af9972
content badge Iframe embedding
swh:1:cnt:795606fec2c439ac09504d37e4adbb1d2cc0f800
README.md
Fuzzing OpenSSL
===============

OpenSSL can use either LibFuzzer or AFL to do fuzzing.

LibFuzzer
---------

How to fuzz OpenSSL with [libfuzzer](http://llvm.org/docs/LibFuzzer.html),
starting from a vanilla+OpenSSH server Ubuntu install.

With `clang` from a package manager
-----------------------------------

Install `clang`, which [ships with `libfuzzer`](http://llvm.org/docs/LibFuzzer.html#fuzzer-usage)
since version 6.0:

    sudo apt-get install clang

Configure `openssl` for fuzzing. For now, you'll still need to pass in the path
to the `libFuzzer` library file while configuring; this is represented as
`$PATH_TO_LIBFUZZER` below. A typical value would be
`/usr/lib/llvm-7/lib/clang/7.0.1/lib/linux/libclang_rt.fuzzer-x86_64.a`.

    CC=clang ./config enable-fuzz-libfuzzer \
            --with-fuzzer-lib=$PATH_TO_LIBFUZZER \
            -DPEDANTIC enable-asan enable-ubsan no-shared \
            -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION \
            -fsanitize=fuzzer-no-link \
            enable-ec_nistp_64_gcc_128 -fno-sanitize=alignment \
            enable-weak-ssl-ciphers enable-rc5 enable-md2 \
            enable-ssl3 enable-ssl3-method enable-nextprotoneg \
            --debug

Clang uses the gcc libstdc++ library so this must also be installed. You can
check which version of gcc clang is using like this:

    $ clang --verbose
    Ubuntu clang version 14.0.0-1ubuntu1.1
    Target: x86_64-pc-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin
    Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/12
    Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
    Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
    Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
    Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
    Candidate multilib: .;@m64
    Selected multilib: .;@m64

So, in the above example clang is using gcc version 12. Ensure that the selected
gcc version has the relevant libstdc++ files installed:

    $ ls /usr/lib/gcc/x86_64-linux-gnu/12 | grep stdc++
    libstdc++.a
    libstdc++fs.a
    libstdc++.so

On Ubuntu for gcc-12 this requires the libstdc++-12-dev package installed.

    $ sudo apt-get install libstdc++-12-dev

Compile:

    sudo apt-get install make
    make clean
    LDCMD=clang++ make -j4

Finally, perform the actual fuzzing:

    fuzz/helper.py $FUZZER

where $FUZZER is one of the executables in `fuzz/`.
It will run until you stop it.

If you get a crash, you should find a corresponding input file in
`fuzz/corpora/$FUZZER-crash/`.

With `clang` from source/pre-built binaries
-------------------------------------------

You may also wish to use a pre-built binary from the [LLVM Download
site](http://releases.llvm.org/download.html), or to [build `clang` from
source](https://clang.llvm.org/get_started.html). After adding `clang` to your
path and locating the `libfuzzer` library file, the procedure for configuring
fuzzing is the same, except that you also need to specify
a `--with-fuzzer-include` option, which should be the parent directory of the
prebuilt fuzzer library. This is represented as `$PATH_TO_LIBFUZZER_DIR` below.

    CC=clang ./config enable-fuzz-libfuzzer \
            --with-fuzzer-include=$PATH_TO_LIBFUZZER_DIR \
            --with-fuzzer-lib=$PATH_TO_LIBFUZZER \
            -DPEDANTIC enable-asan enable-ubsan no-shared \
            -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION \
            -fsanitize=fuzzer-no-link \
            enable-ec_nistp_64_gcc_128 -fno-sanitize=alignment \
            enable-weak-ssl-ciphers enable-rc5 enable-md2 \
            enable-ssl3 enable-ssl3-method enable-nextprotoneg \
            --debug

AFL
---

This is an alternative to using LibFuzzer.

Configure for fuzzing:

    sudo apt-get install afl-clang
    CC=afl-clang-fast ./config enable-fuzz-afl no-shared no-module \
        -DPEDANTIC enable-tls1_3 enable-weak-ssl-ciphers enable-rc5 \
        enable-md2 enable-ssl3 enable-ssl3-method enable-nextprotoneg \
        enable-ec_nistp_64_gcc_128 -fno-sanitize=alignment \
        --debug
    make clean
    make

The following options can also be enabled: enable-asan, enable-ubsan, enable-msan

Run one of the fuzzers:

    afl-fuzz -i fuzz/corpora/$FUZZER -o fuzz/corpora/$FUZZER/out fuzz/$FUZZER

Where $FUZZER is one of the executables in `fuzz/`.

Reproducing issues
------------------

If a fuzzer generates a reproducible error, you can reproduce the problem using
the fuzz/*-test binaries and the file generated by the fuzzer. They binaries
don't need to be built for fuzzing, there is no need to set CC or the call
config with enable-fuzz-* or -fsanitize-coverage, but some of the other options
above might be needed. For instance the enable-asan or enable-ubsan option might
be useful to show you when the problem happens. For the client and server fuzzer
it might be needed to use -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION to
reproduce the generated random numbers.

To reproduce the crash you can run:

    fuzz/$FUZZER-test $file

To do all the tests of a specific fuzzer such as asn1 you can run

    fuzz/asn1-test fuzz/corpora/asn1
or
    make test TESTS=fuzz_test_asn1

To run several fuzz tests you can use for instance:

    make test TESTS='test_fuzz_cmp test_fuzz_cms'

To run all fuzz tests you can use:

    make test TESTS='test_fuzz_*'

Random numbers
--------------

The client and server fuzzer normally generate random numbers as part of the TLS
connection setup. This results in the coverage of the fuzzing corpus changing
depending on the random numbers. This also has an effect for coverage of the
rest of the test suite and you see the coverage change for each commit even when
no code has been modified.

Since we want to maximize the coverage of the fuzzing corpus, the client and
server fuzzer will use predictable numbers instead of the random numbers. This
is controlled by the FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION define.

The coverage depends on the way the numbers are generated. We don't disable any
check of hashes, but the corpus has the correct hash in it for the random
numbers that were generated. For instance the client fuzzer will always generate
the same client hello with the same random number in it, and so the server, as
emulated by the file, can be generated for that client hello.

Coverage changes
----------------

Since the corpus depends on the default behaviour of the client and the server,
changes in what they send by default will have an impact on the coverage. The
corpus will need to be updated in that case.

Updating the corpus
-------------------

The client and server corpus is generated with multiple config options:

- The options as documented above
- Without enable-ec_nistp_64_gcc_128 and without --debug
- With no-asm
- Using 32 bit
- A default config, plus options needed to generate the fuzzer.

The libfuzzer merge option is used to add the additional coverage
from each config to the minimal set.

Minimizing the corpus
---------------------

When you have gathered corpus data from more than one fuzzer run
or for any other reason want to minimize the data
in some corpus subdirectory `fuzz/corpora/DIR` this can be done as follows:

    mkdir fuzz/corpora/NEWDIR
    fuzz/$FUZZER -merge=1 fuzz/corpora/NEWDIR fuzz/corpora/DIR
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top