-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix-jvm-coverage-remove-redundant
- Loading branch information
Showing
15 changed files
with
323 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
target | ||
corpus | ||
artifacts | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
67
projects/starnix-netlink/fuzz/fuzz_targets/utils_fuzzer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |