Skip to content

Commit 3d325bf

Browse files
authored
[WIP] Add libnss build and 15 fuzzers from crrev.com/1677803002. (#12)
* Add libnss build and 15 fuzzers from crrev.com/1677803002. * Added missing $LDFLAGS and used /out/*.a. * Another attempt to link statically. The best one so far. * Manually linking with nspr/Linux*/pr/src/misc/prlog2.o. * Cleanup nss/buil.sh script and disable 2 of 15 nss fuzzers for now. * Fix comments.
1 parent 58dc27a commit 3d325bf

19 files changed

+437
-0
lines changed

nss/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
################################################################################
16+
17+
FROM ossfuzz/base-libfuzzer
18+
MAINTAINER mmoroz@chromium.org
19+
RUN apt-get install -y make autoconf automake libtool mercurial zlib1g-dev
20+
21+
COPY build.sh /src/
22+
23+
ENV LD_LIBRARY_PATH "$LD_LIBRARY_PATH:/out"

nss/Jenkinsfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2016 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
////////////////////////////////////////////////////////////////////////////////
16+
17+
def libfuzzerBuild = fileLoader.fromGit('infra/libfuzzer-pipeline.groovy',
18+
'https://github.com/google/oss-fuzz.git',
19+
'master', null, '')
20+
21+
libfuzzerBuild {
22+
// We can't use git. We need to use mercurial (hg) and checkout 2 repos.
23+
// build.sh does the checkout with hg. The below is just a dummy.
24+
git = "https://github.com/google/oss-fuzz"
25+
}

nss/build.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash -eu
2+
# Copyright 2016 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
################################################################################
17+
18+
cd /src/nss
19+
20+
# Check out the code using mercurial.
21+
rm -rf nspr
22+
rm -rf nss
23+
hg clone https://hg.mozilla.org/projects/nspr
24+
hg clone https://hg.mozilla.org/projects/nss
25+
26+
# Build the library.
27+
mkdir -p /work/nss
28+
cp -u -r /src/nss/* /work/nss/
29+
cd /work/nss/nss
30+
make BUILD_OPT=1 USE_64=1 NSS_DISABLE_GTESTS=1 CC="$CC $CFLAGS" \
31+
CXX="$CXX $CXXFLAGS" LD="$CC $CFLAGS" ZDEFS_FLAG= clean nss_build_all
32+
cd ..
33+
34+
# Copy libraries and some objects to /work/nss/lib.
35+
mkdir -p /work/nss/lib
36+
cp dist/Linux*/lib/*.a /work/nss/lib
37+
cp nspr/Linux*/pr/src/misc/prlog2.o /work/nss/lib
38+
39+
# Copy includes to /work/nss/include.
40+
mkdir -p /work/nss/include
41+
cp -rL dist/Linux*/include/* /work/nss/include
42+
cp -rL dist/{public,private}/nss/* /work/nss/include
43+
44+
45+
# Build the fuzzers.
46+
FUZZERS="asn1_algorithmid_fuzzer \
47+
asn1_any_fuzzer \
48+
asn1_bitstring_fuzzer \
49+
asn1_bmpstring_fuzzer \
50+
asn1_boolean_fuzzer \
51+
asn1_generalizedtime_fuzzer \
52+
asn1_ia5string_fuzzer \
53+
asn1_integer_fuzzer \
54+
asn1_null_fuzzer \
55+
asn1_objectid_fuzzer \
56+
asn1_octetstring_fuzzer \
57+
asn1_utctime_fuzzer \
58+
asn1_utf8string_fuzzer"
59+
60+
# The following fuzzers are currently disabled due to linking issues:
61+
# cert_certificate_fuzzer, seckey_privatekeyinfo_fuzzer
62+
63+
64+
for fuzzer in $FUZZERS; do
65+
$CXX $CXXFLAGS -std=c++11 /src/oss-fuzz/nss/fuzzers/$fuzzer.cc \
66+
-I/work/nss/include \
67+
/work/libfuzzer/*.o \
68+
/work/nss/lib/libnss.a /work/nss/lib/libnssutil.a \
69+
/work/nss/lib/libnspr4.a /work/nss/lib/libplc4.a /work/nss/lib/libplds4.a \
70+
/work/nss/lib/prlog2.o -o /out/$fuzzer $LDFLAGS
71+
done
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <secoid.h>
6+
#include <stddef.h>
7+
#include <stdint.h>
8+
9+
#include "asn1_fuzzer_template.h"
10+
11+
// Entry point for LibFuzzer.
12+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
13+
NSSFuzzOneInput<SECAlgorithmID, SEC_QuickDERDecodeItem>(
14+
SEC_ASN1_GET(SECOID_AlgorithmIDTemplate), data, size);
15+
NSSFuzzOneInput<SECAlgorithmID, SEC_ASN1DecodeItem>(
16+
SEC_ASN1_GET(SECOID_AlgorithmIDTemplate), data, size);
17+
18+
return 0;
19+
}

nss/fuzzers/asn1_any_fuzzer.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
8+
#include "asn1_fuzzer_template.h"
9+
10+
// Entry point for LibFuzzer.
11+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12+
NSSFuzzOneInput<SECItem, SEC_QuickDERDecodeItem>(
13+
SEC_ASN1_GET(SEC_AnyTemplate), data, size);
14+
NSSFuzzOneInput<SECItem, SEC_ASN1DecodeItem>(
15+
SEC_ASN1_GET(SEC_AnyTemplate), data, size);
16+
17+
return 0;
18+
}

nss/fuzzers/asn1_bitstring_fuzzer.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
8+
#include "asn1_fuzzer_template.h"
9+
10+
// Entry point for LibFuzzer.
11+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12+
NSSFuzzOneInput<SECItem, SEC_QuickDERDecodeItem>(
13+
SEC_ASN1_GET(SEC_BitStringTemplate), data, size);
14+
NSSFuzzOneInput<SECItem, SEC_ASN1DecodeItem>(
15+
SEC_ASN1_GET(SEC_BitStringTemplate), data, size);
16+
17+
return 0;
18+
}

nss/fuzzers/asn1_bmpstring_fuzzer.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
8+
#include "asn1_fuzzer_template.h"
9+
10+
// Entry point for LibFuzzer.
11+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12+
NSSFuzzOneInput<SECItem, SEC_QuickDERDecodeItem>(
13+
SEC_ASN1_GET(SEC_BMPStringTemplate), data, size);
14+
NSSFuzzOneInput<SECItem, SEC_ASN1DecodeItem>(
15+
SEC_ASN1_GET(SEC_BMPStringTemplate), data, size);
16+
17+
return 0;
18+
}

nss/fuzzers/asn1_boolean_fuzzer.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
8+
#include "asn1_fuzzer_template.h"
9+
10+
// Entry point for LibFuzzer.
11+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12+
NSSFuzzOneInput<SECItem, SEC_QuickDERDecodeItem>(
13+
SEC_ASN1_GET(SEC_BooleanTemplate), data, size);
14+
NSSFuzzOneInput<SECItem, SEC_ASN1DecodeItem>(
15+
SEC_ASN1_GET(SEC_BooleanTemplate), data, size);
16+
17+
return 0;
18+
}

nss/fuzzers/asn1_fuzzer_template.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef ASN1_FUZZER_TEMPLATE_H_
6+
#define ASN1_FUZZER_TEMPLATE_H_
7+
8+
#include <nspr.h>
9+
#include <nss.h>
10+
#include <secasn1.h>
11+
#include <secder.h>
12+
#include <secitem.h>
13+
#include <secport.h>
14+
#include <stddef.h>
15+
#include <stdint.h>
16+
17+
template <typename DestinationType,
18+
SECStatus (*DecodeFunction)(PLArenaPool*,
19+
void*,
20+
const SEC_ASN1Template*,
21+
const SECItem*)>
22+
void NSSFuzzOneInput(const SEC_ASN1Template* the_template,
23+
const uint8_t* data,
24+
size_t size) {
25+
DestinationType* destination = new DestinationType();
26+
memset(destination, 0, sizeof(DestinationType));
27+
28+
PLArenaPool* arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
29+
if (!arena) {
30+
delete destination;
31+
return;
32+
}
33+
34+
SECItem source;
35+
source.type = siBuffer;
36+
source.data = static_cast<unsigned char*>(const_cast<uint8_t*>(data));
37+
source.len = static_cast<unsigned int>(size);
38+
39+
DecodeFunction(arena, destination, the_template, &source);
40+
41+
PORT_FreeArena(arena, PR_FALSE);
42+
delete destination;
43+
}
44+
45+
#endif // ASN1_FUZZER_TEMPLATE_H_
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
8+
#include "asn1_fuzzer_template.h"
9+
10+
// Entry point for LibFuzzer.
11+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12+
NSSFuzzOneInput<SECItem, SEC_QuickDERDecodeItem>(
13+
SEC_ASN1_GET(SEC_GeneralizedTimeTemplate), data, size);
14+
NSSFuzzOneInput<SECItem, SEC_ASN1DecodeItem>(
15+
SEC_ASN1_GET(SEC_GeneralizedTimeTemplate), data, size);
16+
17+
return 0;
18+
}

nss/fuzzers/asn1_ia5string_fuzzer.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
8+
#include "asn1_fuzzer_template.h"
9+
10+
// Entry point for LibFuzzer.
11+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12+
NSSFuzzOneInput<SECItem, SEC_QuickDERDecodeItem>(
13+
SEC_ASN1_GET(SEC_IA5StringTemplate), data, size);
14+
NSSFuzzOneInput<SECItem, SEC_ASN1DecodeItem>(
15+
SEC_ASN1_GET(SEC_IA5StringTemplate), data, size);
16+
17+
return 0;
18+
}

nss/fuzzers/asn1_integer_fuzzer.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
8+
#include "asn1_fuzzer_template.h"
9+
10+
// Entry point for LibFuzzer.
11+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12+
NSSFuzzOneInput<SECItem, SEC_QuickDERDecodeItem>(
13+
SEC_ASN1_GET(SEC_IntegerTemplate), data, size);
14+
NSSFuzzOneInput<SECItem, SEC_ASN1DecodeItem>(
15+
SEC_ASN1_GET(SEC_IntegerTemplate), data, size);
16+
17+
return 0;
18+
}

nss/fuzzers/asn1_null_fuzzer.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
8+
#include "asn1_fuzzer_template.h"
9+
10+
// Entry point for LibFuzzer.
11+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12+
NSSFuzzOneInput<SECItem, SEC_QuickDERDecodeItem>(
13+
SEC_ASN1_GET(SEC_NullTemplate), data, size);
14+
NSSFuzzOneInput<SECItem, SEC_ASN1DecodeItem>(
15+
SEC_ASN1_GET(SEC_NullTemplate), data, size);
16+
17+
return 0;
18+
}

nss/fuzzers/asn1_objectid_fuzzer.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
8+
#include "asn1_fuzzer_template.h"
9+
10+
// Entry point for LibFuzzer.
11+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12+
NSSFuzzOneInput<SECItem, SEC_QuickDERDecodeItem>(
13+
SEC_ASN1_GET(SEC_ObjectIDTemplate), data, size);
14+
NSSFuzzOneInput<SECItem, SEC_ASN1DecodeItem>(
15+
SEC_ASN1_GET(SEC_ObjectIDTemplate), data, size);
16+
17+
return 0;
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
8+
#include "asn1_fuzzer_template.h"
9+
10+
// Entry point for LibFuzzer.
11+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12+
NSSFuzzOneInput<SECItem, SEC_QuickDERDecodeItem>(
13+
SEC_ASN1_GET(SEC_OctetStringTemplate), data, size);
14+
NSSFuzzOneInput<SECItem, SEC_ASN1DecodeItem>(
15+
SEC_ASN1_GET(SEC_OctetStringTemplate), data, size);
16+
17+
return 0;
18+
}

nss/fuzzers/asn1_utctime_fuzzer.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
8+
#include "asn1_fuzzer_template.h"
9+
10+
// Entry point for LibFuzzer.
11+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
12+
NSSFuzzOneInput<SECItem, SEC_QuickDERDecodeItem>(
13+
SEC_ASN1_GET(SEC_UTCTimeTemplate), data, size);
14+
NSSFuzzOneInput<SECItem, SEC_ASN1DecodeItem>(
15+
SEC_ASN1_GET(SEC_UTCTimeTemplate), data, size);
16+
17+
return 0;
18+
}

0 commit comments

Comments
 (0)