Skip to content

Commit

Permalink
Merge branch 'master' into fix-jvm-coverage-remove-redundant
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKorczynski authored Nov 30, 2024
2 parents 1d2e177 + 372224d commit 8745d89
Show file tree
Hide file tree
Showing 15 changed files with 323 additions and 3 deletions.
4 changes: 2 additions & 2 deletions infra/build/build_status/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ FROM gcr.io/oss-fuzz-base/base-runner
RUN mkdir -p /opt/oss-fuzz/infra/build_status
COPY infra/build/functions/* /opt/oss-fuzz/infra/build_status/
COPY infra/build/build_status/* /opt/oss-fuzz/infra/build_status/
RUN pip install -r /opt/oss-fuzz/infra/build_status/requirements.txt
RUN pip3 install -r /opt/oss-fuzz/infra/build_status/requirements.txt

ENTRYPOINT [ "python3", "/opt/oss-fuzz/infra/build_status/update_build_status.py" ]
ENTRYPOINT [ "python3", "/opt/oss-fuzz/infra/build_status/update_build_status.py" ]
2 changes: 1 addition & 1 deletion infra/build/functions/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
################################################################################

Brotli==1.0.9
hiredis==1.1.0
hiredis==3.0.0
PyYaml==6.0
PyGithub==1.51
grpcio==1.49.1
Expand Down
30 changes: 30 additions & 0 deletions projects/starnix-netlink/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
FROM gcr.io/oss-fuzz-base/base-builder-rust

RUN git clone https://fuchsia.googlesource.com/fuchsia
WORKDIR $SRC/fuchsia/src/starnix/lib/third_party/rust_netlink

COPY build.sh $SRC/
COPY fuzz $SRC/fuchsia/src/starnix/lib/third_party/rust_netlink/fuzz

# Copy Cargo.toml to different modules
COPY cargo.toml/parent $SRC/fuchsia/src/starnix/lib/third_party/rust_netlink/Cargo.toml
COPY cargo.toml/core $SRC/fuchsia/src/starnix/lib/third_party/rust_netlink/netlink_packet_core/Cargo.toml
COPY cargo.toml/generic $SRC/fuchsia/src/starnix/lib/third_party/rust_netlink/netlink_packet_generic/Cargo.toml
COPY cargo.toml/route $SRC/fuchsia/src/starnix/lib/third_party/rust_netlink/netlink_packet_route/Cargo.toml
COPY cargo.toml/sock_diag $SRC/fuchsia/src/starnix/lib/third_party/rust_netlink/netlink_packet_sock_diag/Cargo.toml
COPY cargo.toml/utils $SRC/fuchsia/src/starnix/lib/third_party/rust_netlink/netlink_packet_utils/Cargo.toml
26 changes: 26 additions & 0 deletions projects/starnix-netlink/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash -eu
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################

# Update local crate.io vendors
cargo vendor -- /src/fuchsia/third_party/rust_crates/vendor/

# Build the fuzzers and project source code
cargo fuzz build

# Copy built fuzzer binaries to $OUT
cp /src/fuchsia/out/cargo_target/x86_64-unknown-linux-gnu/release/core_fuzzer $OUT/
cp /src/fuchsia/out/cargo_target/x86_64-unknown-linux-gnu/release/utils_fuzzer $OUT/
13 changes: 13 additions & 0 deletions projects/starnix-netlink/cargo.toml/core
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "netlink_packet_core"
version = "0.1.0"
edition = "2018"

[dependencies]
anyhow = { path = "/src/fuchsia/third_party/rust_crates/vendor/anyhow-1.0.86" }
byteorder = "1.5"
netlink_packet_utils = { path = "../netlink_packet_utils" }

[lib]
name = "netlink_packet_core"
path = "src/lib.rs"
14 changes: 14 additions & 0 deletions projects/starnix-netlink/cargo.toml/generic
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "netlink_packet_generic"
version = "0.1.0"
edition = "2018"

[dependencies]
anyhow = { path = "/src/fuchsia/third_party/rust_crates/vendor/anyhow-1.0.86" }
byteorder = "1.5"
netlink_packet_core = { path = "../netlink_packet_core" }
netlink_packet_utils = { path = "../netlink_packet_utils" }

[lib]
name = "netlink_packet_generic"
path = "src/lib.rs"
9 changes: 9 additions & 0 deletions projects/starnix-netlink/cargo.toml/parent
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]
members = [
"netlink_packet_core",
"netlink_packet_generic",
"netlink_packet_route",
"netlink_packet_sock_diag",
"netlink_packet_utils",
"fuzz"
]
21 changes: 21 additions & 0 deletions projects/starnix-netlink/cargo.toml/route
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "netlink_packet_route"
version = "0.1.0"
edition = "2018"

[dependencies]
anyhow = { path = "/src/fuchsia/third_party/rust_crates/vendor/anyhow-1.0.86" }
bitflags = { path = "/src/fuchsia/third_party/rust_crates/vendor/bitflags-2.4.1" }
byteorder = "1.5"
libc = { path = "/src/fuchsia/third_party/rust_crates/vendor/libc-0.2.158" }
log = { path = "/src/fuchsia/third_party/rust_crates/vendor/log-0.4.22", features = ["std"] }
thiserror = { path = "/src/fuchsia/third_party/rust_crates/vendor/thiserror-1.0.57" }
netlink_packet_core = { path = "../netlink_packet_core" }
netlink_packet_utils = { path = "../netlink_packet_utils" }

[lib]
name = "netlink_packet_route"
path = "src/lib.rs"

[features]
rich_nlas = []
20 changes: 20 additions & 0 deletions projects/starnix-netlink/cargo.toml/sock_diag
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "netlink_packet_sock_diag"
version = "0.1.0"
edition = "2018"

[dependencies]
anyhow = { path = "/src/fuchsia/third_party/rust_crates/vendor/anyhow-1.0.86" }
bitflags = { path = "/src/fuchsia/third_party/rust_crates/vendor/bitflags-2.4.1" }
byteorder = "1.5"
libc = { path = "/src/fuchsia/third_party/rust_crates/vendor/libc-0.2.158" }
smallvec = { path = "/src/fuchsia/third_party/rust_crates/vendor/smallvec-1.13.1" }
netlink_packet_core = { path = "../netlink_packet_core" }
netlink_packet_utils = { path = "../netlink_packet_utils" }

[lib]
name = "netlink_packet_sock_diag"
path = "src/lib.rs"

[features]
rich_nlas = []
15 changes: 15 additions & 0 deletions projects/starnix-netlink/cargo.toml/utils
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "netlink_packet_utils"
version = "0.1.0"
edition = "2018"

[dependencies]
anyhow = { path = "/src/fuchsia/third_party/rust_crates/vendor/anyhow-1.0.86" }
bitflags = { path = "/src/fuchsia/third_party/rust_crates/vendor/bitflags-2.4.1" }
byteorder = "1.5"
paste = { path = "/src/fuchsia/third_party/rust_crates/vendor/paste-1.0.9" }
thiserror = { path = "/src/fuchsia/third_party/rust_crates/vendor/thiserror-1.0.57" }

[lib]
name = "netlink_packet_utils"
path = "src/lib.rs"
4 changes: 4 additions & 0 deletions projects/starnix-netlink/fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
32 changes: 32 additions & 0 deletions projects/starnix-netlink/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "netlink_fuzz"
version = "0.0.0"
publish = false
edition = "2018"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
arbitrary = "1.3.2"
derive_arbitrary = "1.3.2"
netlink_packet_core = { path = "../netlink_packet_core" }
netlink_packet_generic = { path = "../netlink_packet_generic" }
netlink_packet_route = { path = "../netlink_packet_route" }
netlink_packet_sock_diag = { path = "../netlink_packet_sock_diag" }
netlink_packet_utils = { path = "../netlink_packet_utils" }

[[bin]]
name = "core_fuzzer"
path = "fuzz_targets/core_fuzzer.rs"
test = false
doc = false
bench = false

[[bin]]
name = "utils_fuzzer"
path = "fuzz_targets/utils_fuzzer.rs"
test = false
doc = false
bench = false
59 changes: 59 additions & 0 deletions projects/starnix-netlink/fuzz/fuzz_targets/core_fuzzer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![no_main]
use arbitrary::{Arbitrary, Unstructured};
use derive_arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;
use netlink_packet_core::buffer::NetlinkBuffer;
use netlink_packet_core::constants::*;
use netlink_packet_core::done::DoneBuffer;
use netlink_packet_core::error::ErrorBuffer;
use netlink_packet_core::header::NetlinkHeader;

// Derive random data from fuzz input
#[derive(Arbitrary, Debug)]
struct FuzzInput {
message_type: u16,
sequence_number: u32,
port_number: u32,
buffer_data: Vec<u8>,
payload_data: Vec<u8>,
}

fuzz_target!(|data: &[u8]| {
// Initialize Unstructured for parsing the data
let mut unstructured = Unstructured::new(data);

// Attempt to parse the fuzz input structure
if let Ok(fuzz_input) = FuzzInput::arbitrary(&mut unstructured) {
// Fuzz NetlinkBuffer
if let Ok(netlink_buffer) = NetlinkBuffer::new_checked(&fuzz_input.buffer_data) {
let _ = netlink_buffer.payload_length();
let _ = netlink_buffer.payload();
}

// Fuzz DoneBuffer
if let Ok(done_buffer) = DoneBuffer::new_checked(&fuzz_input.buffer_data) {
let _ = done_buffer.code();
let _ = done_buffer.extended_ack();
}

// Fuzz ErrorBuffer
if let Ok(error_buffer) = ErrorBuffer::new_checked(&fuzz_input.buffer_data) {
let _code = error_buffer.code();
let _payload = error_buffer.payload();
}
}
});
67 changes: 67 additions & 0 deletions projects/starnix-netlink/fuzz/fuzz_targets/utils_fuzzer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![no_main]

use arbitrary::{Arbitrary, Unstructured};
use derive_arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;
use netlink_packet_utils::nla::{DefaultNla, NlaBuffer};
use netlink_packet_utils::parsers::*;
use netlink_packet_utils::traits::{Emitable, Parseable};

// Derive random data from fuzz input
#[derive(Arbitrary, Debug)]
struct FuzzInput {
mac_data: [u8; 6],
ip_data: Vec<u8>,
utf8_data: Vec<u8>,
nla_kind: u16,
nla_value: Vec<u8>,
}

fuzz_target!(|data: &[u8]| {
// Attempt to create a FuzzInput struct from the fuzzed data
let mut unstructured = Unstructured::new(data);
let fuzz_input = match FuzzInput::arbitrary(&mut unstructured) {
Ok(input) => input,
Err(_) => return,
};

// Fuzz parse_mac
let _ = parse_mac(&fuzz_input.mac_data);

// Fuzz parse_ip
let _ = parse_ip(&fuzz_input.ip_data);

// Fuzz parse_string
let _ = parse_string(&fuzz_input.utf8_data);

// Fuzz NlaBuffer
if let Ok(nla_buf) = NlaBuffer::new_checked(&fuzz_input.nla_value) {
let _ = nla_buf.kind();
let _ = nla_buf.length();
let _ = nla_buf.value_length();
}

// Fuzz DefaultNla
let nla = DefaultNla::new(fuzz_input.nla_kind, fuzz_input.nla_value.clone());
let mut emit_buffer = vec![0; nla.buffer_len()];
nla.emit(&mut emit_buffer);

// Fuzz DefaultNla parsing
if let Ok(nla_buf) = NlaBuffer::new_checked(&fuzz_input.nla_value) {
let _ = DefaultNla::parse(&nla_buf);
}
});
10 changes: 10 additions & 0 deletions projects/starnix-netlink/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
homepage: "https://cs.opensource.google/fuchsia/fuchsia/+/main:src/starnix/lib/third_party/rust_netlink"
main_repo: "https://fuchsia.googlesource.com/fuchsia"
sanitizers:
- address
fuzzing_engines:
- libfuzzer
language: rust
auto_ccs:
- "arthur.chan@adalogics.com"
- "david@adalogics.com"

0 comments on commit 8745d89

Please sign in to comment.