Merge pull request #10200 from evverx/fuzz-dhcp6-client

Add a fuzzer for dhcp6-client
This commit is contained in:
Yu Watanabe
2018-09-29 13:41:52 +02:00
committed by GitHub
9 changed files with 87 additions and 2 deletions
+59
View File
@@ -0,0 +1,59 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <unistd.h>
#include "sd-dhcp6-client.h"
#include "sd-event.h"
#include "dhcp6-internal.h"
#include "dhcp6-protocol.h"
#include "fd-util.h"
#include "fuzz.h"
static int test_dhcp_fd[2];
int dhcp6_network_send_udp_socket(int s, struct in6_addr *server_address,
const void *packet, size_t len) {
return len;
}
int dhcp6_network_bind_udp_socket(int index, struct in6_addr *local_address) {
assert_se(socketpair(AF_UNIX, SOCK_STREAM, 0, test_dhcp_fd) >= 0);
return test_dhcp_fd[0];
}
static void fuzz_client(const uint8_t *data, size_t size, bool is_information_request_enabled) {
_cleanup_(sd_event_unrefp) sd_event *e;
_cleanup_(sd_dhcp6_client_unrefp) sd_dhcp6_client *client = NULL;
struct in6_addr address = { { { 0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01 } } };
assert_se(sd_event_new(&e) >= 0);
assert_se(sd_dhcp6_client_new(&client) >= 0);
assert_se(sd_dhcp6_client_attach_event(client, e, 0) >= 0);
assert_se(sd_dhcp6_client_set_ifindex(client, 42) == 0);
assert_se(sd_dhcp6_client_set_local_address(client, &address) >= 0);
assert_se(sd_dhcp6_client_set_information_request(client, is_information_request_enabled) == 0);
assert_se(sd_dhcp6_client_start(client) >= 0);
if (size >= sizeof(DHCP6Message))
assert_se(sd_dhcp6_client_set_transaction_id(client, htobe32(0x00ffffff) & ((const DHCP6Message *) data)->transaction_id) == 0);
assert_se(write(test_dhcp_fd[1], data, size) == (ssize_t) size);
sd_event_run(e, (uint64_t) -1);
assert_se(sd_dhcp6_client_stop(client) >= 0);
test_dhcp_fd[1] = safe_close(test_dhcp_fd[1]);
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
/* This triggers client_receive_advertise */
fuzz_client(data, size, false);
/* This triggers client_receive_reply */
fuzz_client(data, size, true);
return 0;
}
+9
View File
@@ -9,6 +9,15 @@ fuzzers += [
libgpg_error,
libm]],
[['src/fuzz/fuzz-dhcp6-client.c',
'src/libsystemd-network/dhcp-identifier.h',
'src/libsystemd-network/dhcp-identifier.c',
'src/libsystemd-network/dhcp6-internal.h',
'src/systemd/sd-dhcp6-client.h'],
[libshared,
libsystemd_network],
[]],
[['src/fuzz/fuzz-dhcp-server.c'],
[libsystemd_network,
libshared],
+6 -1
View File
@@ -108,8 +108,13 @@ int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len) {
assert(len);
r = sd_id128_get_machine(&machine_id);
if (r < 0)
if (r < 0) {
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
machine_id = SD_ID128_MAKE(01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10);
#else
return r;
#endif
}
unaligned_write_be16(&duid->type, DUID_TYPE_EN);
unaligned_write_be32(&duid->en.pen, SYSTEMD_PEN);
+1 -1
View File
@@ -563,7 +563,7 @@ int dhcp6_option_parse_domainname(const uint8_t *optval, uint16_t optlen, char *
/* Literal label */
label = (const char *)&optval[pos];
pos += c;
if (pos > optlen)
if (pos >= optlen)
return -EMSGSIZE;
if (!GREEDY_REALLOC(ret, allocated, n + !first + DNS_LABEL_ESCAPED_MAX)) {
+8
View File
@@ -368,6 +368,14 @@ int sd_dhcp6_client_set_address_request(sd_dhcp6_client *client, int request) {
return 0;
}
int sd_dhcp6_client_set_transaction_id(sd_dhcp6_client *client, be32_t transaction_id) {
assert_return(client, -EINVAL);
client->transaction_id = transaction_id;
return 0;
}
int sd_dhcp6_client_get_lease(sd_dhcp6_client *client, sd_dhcp6_lease **ret) {
assert_return(client, -EINVAL);
+2
View File
@@ -25,6 +25,7 @@
#include "sd-dhcp6-lease.h"
#include "sd-event.h"
#include "sparse-endian.h"
#include "_sd-common.h"
@@ -127,6 +128,7 @@ int sd_dhcp6_client_get_address_request(sd_dhcp6_client *client,
int *request);
int sd_dhcp6_client_set_address_request(sd_dhcp6_client *client,
int request);
int sd_dhcp6_client_set_transaction_id(sd_dhcp6_client *client, be32_t transaction_id);
int sd_dhcp6_client_get_lease(
sd_dhcp6_client *client,
+2
View File
@@ -12,6 +12,8 @@ sanitize_address = custom_target(
sanitizers = [['address', sanitize_address]]
fuzz_regression_tests = '''
fuzz-dhcp6-client/crash-4003c06fce43a11fbd22f02584df2807ac333eae
fuzz-dhcp6-client/crash-6e88fcb6b85c9436bcbe05219aa8e550194645ef
fuzz-dns-packet/issue-7888
fuzz-dns-packet/oss-fuzz-5465
fuzz-journal-remote/crash-5a8f03d4c3a46fcded39527084f437e8e4b54b76