From d61d0d72128cb5d953d8d633c41b7f648f1a63f5 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Thu, 28 Nov 2024 19:05:06 +0000 Subject: [PATCH 1/3] starnix-netlink: Project Initialisation (#12790) Project initialisation for starnix-netlink. --------- Signed-off-by: Arthur Chan --- projects/starnix-netlink/Dockerfile | 30 +++++++++ projects/starnix-netlink/build.sh | 26 +++++++ projects/starnix-netlink/cargo.toml/core | 13 ++++ projects/starnix-netlink/cargo.toml/generic | 14 ++++ projects/starnix-netlink/cargo.toml/parent | 9 +++ projects/starnix-netlink/cargo.toml/route | 21 ++++++ projects/starnix-netlink/cargo.toml/sock_diag | 20 ++++++ projects/starnix-netlink/cargo.toml/utils | 15 +++++ projects/starnix-netlink/fuzz/.gitignore | 4 ++ projects/starnix-netlink/fuzz/Cargo.toml | 32 +++++++++ .../fuzz/fuzz_targets/core_fuzzer.rs | 59 ++++++++++++++++ .../fuzz/fuzz_targets/utils_fuzzer.rs | 67 +++++++++++++++++++ projects/starnix-netlink/project.yaml | 10 +++ 13 files changed, 320 insertions(+) create mode 100644 projects/starnix-netlink/Dockerfile create mode 100755 projects/starnix-netlink/build.sh create mode 100644 projects/starnix-netlink/cargo.toml/core create mode 100644 projects/starnix-netlink/cargo.toml/generic create mode 100644 projects/starnix-netlink/cargo.toml/parent create mode 100644 projects/starnix-netlink/cargo.toml/route create mode 100644 projects/starnix-netlink/cargo.toml/sock_diag create mode 100644 projects/starnix-netlink/cargo.toml/utils create mode 100644 projects/starnix-netlink/fuzz/.gitignore create mode 100644 projects/starnix-netlink/fuzz/Cargo.toml create mode 100644 projects/starnix-netlink/fuzz/fuzz_targets/core_fuzzer.rs create mode 100644 projects/starnix-netlink/fuzz/fuzz_targets/utils_fuzzer.rs create mode 100644 projects/starnix-netlink/project.yaml diff --git a/projects/starnix-netlink/Dockerfile b/projects/starnix-netlink/Dockerfile new file mode 100644 index 000000000000..e83a8cdfda08 --- /dev/null +++ b/projects/starnix-netlink/Dockerfile @@ -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 diff --git a/projects/starnix-netlink/build.sh b/projects/starnix-netlink/build.sh new file mode 100755 index 000000000000..5278b27191c7 --- /dev/null +++ b/projects/starnix-netlink/build.sh @@ -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/ diff --git a/projects/starnix-netlink/cargo.toml/core b/projects/starnix-netlink/cargo.toml/core new file mode 100644 index 000000000000..24e36da806cf --- /dev/null +++ b/projects/starnix-netlink/cargo.toml/core @@ -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" diff --git a/projects/starnix-netlink/cargo.toml/generic b/projects/starnix-netlink/cargo.toml/generic new file mode 100644 index 000000000000..139656f5d572 --- /dev/null +++ b/projects/starnix-netlink/cargo.toml/generic @@ -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" diff --git a/projects/starnix-netlink/cargo.toml/parent b/projects/starnix-netlink/cargo.toml/parent new file mode 100644 index 000000000000..567ed257ac6f --- /dev/null +++ b/projects/starnix-netlink/cargo.toml/parent @@ -0,0 +1,9 @@ +[workspace] +members = [ + "netlink_packet_core", + "netlink_packet_generic", + "netlink_packet_route", + "netlink_packet_sock_diag", + "netlink_packet_utils", + "fuzz" +] diff --git a/projects/starnix-netlink/cargo.toml/route b/projects/starnix-netlink/cargo.toml/route new file mode 100644 index 000000000000..353896bf6474 --- /dev/null +++ b/projects/starnix-netlink/cargo.toml/route @@ -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 = [] diff --git a/projects/starnix-netlink/cargo.toml/sock_diag b/projects/starnix-netlink/cargo.toml/sock_diag new file mode 100644 index 000000000000..6007e6ae114a --- /dev/null +++ b/projects/starnix-netlink/cargo.toml/sock_diag @@ -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 = [] diff --git a/projects/starnix-netlink/cargo.toml/utils b/projects/starnix-netlink/cargo.toml/utils new file mode 100644 index 000000000000..066160ddd994 --- /dev/null +++ b/projects/starnix-netlink/cargo.toml/utils @@ -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" diff --git a/projects/starnix-netlink/fuzz/.gitignore b/projects/starnix-netlink/fuzz/.gitignore new file mode 100644 index 000000000000..1a45eee7760d --- /dev/null +++ b/projects/starnix-netlink/fuzz/.gitignore @@ -0,0 +1,4 @@ +target +corpus +artifacts +coverage diff --git a/projects/starnix-netlink/fuzz/Cargo.toml b/projects/starnix-netlink/fuzz/Cargo.toml new file mode 100644 index 000000000000..614652fc874b --- /dev/null +++ b/projects/starnix-netlink/fuzz/Cargo.toml @@ -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 diff --git a/projects/starnix-netlink/fuzz/fuzz_targets/core_fuzzer.rs b/projects/starnix-netlink/fuzz/fuzz_targets/core_fuzzer.rs new file mode 100644 index 000000000000..f10d92874338 --- /dev/null +++ b/projects/starnix-netlink/fuzz/fuzz_targets/core_fuzzer.rs @@ -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, + payload_data: Vec, +} + +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(); + } + } +}); diff --git a/projects/starnix-netlink/fuzz/fuzz_targets/utils_fuzzer.rs b/projects/starnix-netlink/fuzz/fuzz_targets/utils_fuzzer.rs new file mode 100644 index 000000000000..c66e1ff5f25f --- /dev/null +++ b/projects/starnix-netlink/fuzz/fuzz_targets/utils_fuzzer.rs @@ -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, + utf8_data: Vec, + nla_kind: u16, + nla_value: Vec, +} + +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); + } +}); diff --git a/projects/starnix-netlink/project.yaml b/projects/starnix-netlink/project.yaml new file mode 100644 index 000000000000..ef23b0c51a60 --- /dev/null +++ b/projects/starnix-netlink/project.yaml @@ -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" From e9cbf07b9bfe265d9394a6f187be87ccff137e7c Mon Sep 17 00:00:00 2001 From: Oliver Chang Date: Fri, 29 Nov 2024 11:16:27 +1100 Subject: [PATCH 2/3] Replace pip with pip3 in builds status cron. (#12793) Should hopefully fix #12772. --- infra/build/build_status/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infra/build/build_status/Dockerfile b/infra/build/build_status/Dockerfile index 881562587f62..287bcbdf1b0f 100644 --- a/infra/build/build_status/Dockerfile +++ b/infra/build/build_status/Dockerfile @@ -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" ] \ No newline at end of file +ENTRYPOINT [ "python3", "/opt/oss-fuzz/infra/build_status/update_build_status.py" ] From 372224d9db960a57db45c6bbd2bcca489ab8b4ea Mon Sep 17 00:00:00 2001 From: Oliver Chang Date: Fri, 29 Nov 2024 14:20:17 +1100 Subject: [PATCH 3/3] Upgrade hiredis to fix Docker build: (#12794) ``` 2024-11-29 14:01:13.657 AEDT Step #0: clang -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Ivendor -I/usr/local/include/python3.10 -c src/hiredis.c -o build/temp.linux-x86_64-cpython-310/src/hiredis.o 2024-11-29 14:01:13.657 AEDT Step #0: error: command 'clang' failed: No such file or directory 2024-11-29 14:01:13.657 AEDT Step #0: [end of output] 2024-11-29 14:01:13.657 AEDT Step #0: 2024-11-29 14:01:13.657 AEDT Step #0: note: This error originates from a subprocess, and is likely not a problem with pip. 2024-11-29 14:01:13.658 AEDT Step #0: [0m[91m ERROR: Failed building wheel for hiredis 2024-11-29 14:01:13.659 AEDT Step #0: [0m Running setup.py clean for hiredis 2024-11-29 14:01:14.059 AEDT Step #0: Failed to build hiredis ``` Use a version that has a compatible prebuilt. For #12772. --- infra/build/functions/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/build/functions/requirements.txt b/infra/build/functions/requirements.txt index 55206ef2b6fd..e71815f74ee9 100644 --- a/infra/build/functions/requirements.txt +++ b/infra/build/functions/requirements.txt @@ -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