From 62facba19ad645df7fb425ce170bdbda208b303c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 7 Nov 2018 17:21:41 +0900 Subject: [PATCH 1/3] network: ignore multiple assignment of netdev kind Fixes oss-fuzz#11279 and oss-fuzz#11280. --- src/network/netdev/netdev.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index 9ec16579e4..f9a2246d08 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -97,7 +97,41 @@ static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = { }; DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind); -DEFINE_CONFIG_PARSE_ENUM(config_parse_netdev_kind, netdev_kind, NetDevKind, "Failed to parse netdev kind"); + +int config_parse_netdev_kind( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + NetDevKind k, *kind = data; + + assert(rvalue); + assert(data); + + k = netdev_kind_from_string(rvalue); + if (k < 0) { + log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse netdev kind, ignoring assignment: %s", rvalue); + return 0; + } + + if (*kind != _NETDEV_KIND_INVALID && *kind != k) { + log_syntax(unit, LOG_ERR, filename, line, 0, + "Specified netdev kind is different from the previous value '%s', ignoring assignment: %s", + netdev_kind_to_string(*kind), rvalue); + return 0; + } + + *kind = k; + + return 0; +} static void netdev_callbacks_clear(NetDev *netdev) { netdev_join_callback *callback; From 348784e62a7f6643f8e795dc9e24823d5345bd3c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 7 Nov 2018 17:24:41 +0900 Subject: [PATCH 2/3] fuzz: add testcases for oss-fuzz#11279 and #11280 --- test/fuzz/fuzz-netdev-parser/oss-fuzz-11279 | Bin 0 -> 60 bytes test/fuzz/fuzz-netdev-parser/oss-fuzz-11280 | Bin 0 -> 76 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/fuzz/fuzz-netdev-parser/oss-fuzz-11279 create mode 100644 test/fuzz/fuzz-netdev-parser/oss-fuzz-11280 diff --git a/test/fuzz/fuzz-netdev-parser/oss-fuzz-11279 b/test/fuzz/fuzz-netdev-parser/oss-fuzz-11279 new file mode 100644 index 0000000000000000000000000000000000000000..f7a99bdaa1355535e7589b43dd8254a8204dcf50 GIT binary patch literal 60 zcma#{OD%CpEsN#y&df`(Ezc}UO)pI>O5utQDb34E&57mmVTgt)@k`82watX6%q++( F004n>6w&|y literal 0 HcmV?d00001 diff --git a/test/fuzz/fuzz-netdev-parser/oss-fuzz-11280 b/test/fuzz/fuzz-netdev-parser/oss-fuzz-11280 new file mode 100644 index 0000000000000000000000000000000000000000..33d24990b74651f3c65b73553263950f73fb8cf1 GIT binary patch literal 76 zcma#{OD%CpEsN#y&df`(Ez3#F Date: Wed, 7 Nov 2018 18:14:11 +0900 Subject: [PATCH 3/3] network: drop unused members in Wireguard object --- src/network/netdev/wireguard.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/network/netdev/wireguard.h b/src/network/netdev/wireguard.h index bd97004519..70690ee2b8 100644 --- a/src/network/netdev/wireguard.h +++ b/src/network/netdev/wireguard.h @@ -46,17 +46,14 @@ struct Wireguard { NetDev meta; unsigned last_peer_section; - char interface[IFNAMSIZ]; uint32_t flags; - uint8_t public_key[WG_KEY_LEN]; uint8_t private_key[WG_KEY_LEN]; uint32_t fwmark; uint16_t port; LIST_HEAD(WireguardPeer, peers); - size_t allocation_size; LIST_HEAD(WireguardEndpoint, unresolved_endpoints); LIST_HEAD(WireguardEndpoint, failed_endpoints);