From 8a06835d0da2ec43429909487ef737f3c4f73799 Mon Sep 17 00:00:00 2001 From: Arjun <36335769+0x34d@users.noreply.github.com> Date: Fri, 30 Sep 2022 00:39:49 +0530 Subject: [PATCH] [lldpd] initial integration (#8577) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hello @vincentbernat  Can you check this PR? oss-fuzz team.  Application usage in router:  - Unifi, - Cambium Networks, - oVirt, - OpenWrt, - Poly, - MikroTik, - Cumulus, - ASUS. It is possibly used in other places as well. Signed-off-by: 0x34d Signed-off-by: 0x34d --- projects/lldpd/Dockerfile | 22 ++++++++++++++++++ projects/lldpd/FuzzDecode.c | 45 +++++++++++++++++++++++++++++++++++++ projects/lldpd/build.sh | 27 ++++++++++++++++++++++ projects/lldpd/project.yaml | 14 ++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 projects/lldpd/Dockerfile create mode 100644 projects/lldpd/FuzzDecode.c create mode 100644 projects/lldpd/build.sh create mode 100644 projects/lldpd/project.yaml diff --git a/projects/lldpd/Dockerfile b/projects/lldpd/Dockerfile new file mode 100644 index 000000000..c4740d11e --- /dev/null +++ b/projects/lldpd/Dockerfile @@ -0,0 +1,22 @@ +# Copyright 2022 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 +RUN apt-get update && apt-get install -y autoconf libtool-bin pkg-config +RUN git clone --recursive https://github.com/lldpd/lldpd/ +RUN git clone https://github.com/0x34d/oss-fuzz-bloat +COPY build.sh $SRC/ +COPY FuzzDecode.c $SRC/lldpd/FuzzDecode.c +WORKDIR $SRC/lldpd/ diff --git a/projects/lldpd/FuzzDecode.c b/projects/lldpd/FuzzDecode.c new file mode 100644 index 000000000..122670e38 --- /dev/null +++ b/projects/lldpd/FuzzDecode.c @@ -0,0 +1,45 @@ +/* Copyright 2022 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. +*/ +#include +#include +#include "../src/daemon/lldpd.h" + +#define kMinInputLength 30 +#define kMaxInputLength 1500 + +extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + + if (Size < kMinInputLength || Size > kMaxInputLength){ + return 0; + } + + int ret = 0; + struct lldpd cfg; + cfg.g_config.c_mgmt_pattern = NULL; + +/* For decoding, we only need a very basic hardware */ + struct lldpd_hardware hardware; + memset(&hardware, 0, sizeof(struct lldpd_hardware)); + hardware.h_mtu = 1500; + strlcpy(hardware.h_ifname, "test", sizeof(hardware.h_ifname)); + + struct lldpd_chassis *nchassis = NULL; + struct lldpd_port *nport = NULL; + +//Decoding + ret += lldp_decode(&cfg, (char *)Data, Size, &hardware, &nchassis, &nport); + ret += cdp_decode(&cfg, (char *)Data, Size, &hardware, &nchassis, &nport); + ret += sonmp_decode(&cfg, (char *)Data, Size, &hardware, &nchassis, &nport); + ret += edp_decode(&cfg, (char *)Data, Size, &hardware, &nchassis, &nport); + + return ret; +} diff --git a/projects/lldpd/build.sh b/projects/lldpd/build.sh new file mode 100644 index 000000000..baeca00fd --- /dev/null +++ b/projects/lldpd/build.sh @@ -0,0 +1,27 @@ +#!/bin/bash -eu +# Copyright 2022 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. +# +################################################################################ +./autogen.sh +./configure CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$CFLAGS" --disable-shared --disable-hardening --enable-pie +make + +$CC $CFLAGS -fPIE -Wall -Werror -pipe -DHAVE_CONFIG_H -I. -I include/ -c FuzzDecode.c +$CC $CFLAGS -fPIE -pie -o FuzzDecode FuzzDecode.o $LIB_FUZZING_ENGINE src/daemon/.libs/liblldpd.a libevent/.libs/libevent.a +cp FuzzDecode $OUT/FuzzDecode + +pushd $SRC/oss-fuzz-bloat/lldpd/ +cp FuzzDecode_seed_corpus.zip $OUT/FuzzDecode_seed_corpus.zip +popd diff --git a/projects/lldpd/project.yaml b/projects/lldpd/project.yaml new file mode 100644 index 000000000..7c3aa40de --- /dev/null +++ b/projects/lldpd/project.yaml @@ -0,0 +1,14 @@ +homepage: "https://lldpd.github.io" +language: c +primary_contact: "vincent@bernat.ch" +auto_ccs: + - "ajsinghyadav00@gmail.com" +fuzzing_engines: + - libfuzzer + - afl + - honggfuzz +sanitizers: + - address + - memory + - undefined +main_repo: 'https://github.com/lldpd/lldpd'