networkd: make netdev_load_one "public" and add a fuzzer for it

This commit is contained in:
Evgeny Vereshchagin 2018-11-04 22:06:03 +01:00
parent 0621f03b13
commit e27aac11f2
32 changed files with 245 additions and 1 deletions

View File

@ -0,0 +1,22 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
#include "fuzz.h"
#include "networkd-manager.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
_cleanup_(manager_freep) Manager *manager = NULL;
_cleanup_fclose_ FILE *f = NULL;
_cleanup_(unlink_tempfilep) char netdev_config[] = "/tmp/fuzz-networkd.XXXXXX";
assert_se(fmkostemp_safe(netdev_config, "r+", &f) == 0);
if (size != 0)
assert_se(fwrite(data, size, 1, f) == 1);
rewind(f);
assert_se(manager_new(&manager) >= 0);
(void) netdev_load_one(manager, netdev_config);
return 0;
}

View File

@ -136,6 +136,16 @@ if conf.get('ENABLE_NETWORKD') == 1
install_data('networkd.conf',
install_dir : pkgsysconfdir)
fuzzers += [
[['src/network/fuzz-netdev-parser.c',
'src/fuzz/fuzz.h'],
[libnetworkd_core,
libudev_static,
libsystemd_network,
libshared],
[threads]],
]
tests += [
[['src/network/test-networkd-conf.c'],
[libnetworkd_core,

View File

@ -594,7 +594,7 @@ int netdev_join(NetDev *netdev, Link *link, sd_netlink_message_handler_t callbac
return 0;
}
static int netdev_load_one(Manager *manager, const char *filename) {
int netdev_load_one(Manager *manager, const char *filename) {
_cleanup_(netdev_unrefp) NetDev *netdev_raw = NULL, *netdev = NULL;
_cleanup_fclose_ FILE *file = NULL;
const char *dropin_dirname;

View File

@ -146,6 +146,7 @@ extern const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX];
#define NETDEV(n) (&(n)->meta)
int netdev_load(Manager *manager);
int netdev_load_one(Manager *manager, const char *filename);
void netdev_drop(NetDev *netdev);
NetDev *netdev_unref(NetDev *netdev);

View File

@ -0,0 +1,3 @@
[NetDev]
Name=test1
Kind=dummy

View File

@ -0,0 +1,3 @@
[NetDev]
Name=dummy98
Kind=dummy

View File

@ -0,0 +1,3 @@
[NetDev]
Name=macvlan99
Kind=macvlan

View File

@ -0,0 +1,3 @@
[NetDev]
Name=macvtap99
Kind=macvtap

View File

@ -0,0 +1,10 @@
[NetDev]
Name=vlan99
Kind=vlan
[VLAN]
Id=99
GVRP=true
MVRP=true
LooseBinding=true
ReorderHeader=true

View File

@ -0,0 +1,6 @@
[NetDev]
Name=bond199
Kind=bond
[Bond]
Mode=active-backup

View File

@ -0,0 +1,18 @@
[NetDev]
Name=bond99
Kind=bond
[Bond]
Mode=802.3ad
TransmitHashPolicy=layer3+4
MIIMonitorSec=1s
LACPTransmitRate=fast
UpDelaySec=2s
DownDelaySec=2s
ResendIGMP=4
MinLinks=1
AdActorSysPrio=1218
AdUserPortKey=811
AdActorSystem=00:11:22:33:44:55
# feed the sanitizer
AdActorSystem=00:11:22:33:44:55

View File

@ -0,0 +1,13 @@
[NetDev]
Name=bridge99
Kind=bridge
[Bridge]
HelloTimeSec=9
MaxAgeSec=9
ForwardDelaySec=9
AgeingTimeSec=9
Priority=9
MulticastQuerier= true
MulticastSnooping=true
STP=true

View File

@ -0,0 +1,12 @@
[NetDev]
Name=geneve99
Kind=geneve
[GENEVE]
Id=99
Remote=192.168.22.1
TTL=1
UDPChecksum=true
UDP6ZeroChecksumTx=true
UDP6ZeroChecksumRx=true
DestinationPort=6082

View File

@ -0,0 +1,7 @@
[NetDev]
Name=gretun99
Kind=gre
[Tunnel]
Local=10.65.223.238
Remote=10.65.223.239

View File

@ -0,0 +1,7 @@
[NetDev]
Name=gretap99
Kind=gretap
[Tunnel]
Local=10.65.223.238
Remote=10.65.223.239

View File

@ -0,0 +1,7 @@
[NetDev]
Name=ip6gretap99
Kind=ip6gretap
[Tunnel]
Local=2a00:ffde:4567:edde::4987
Remote=2001:473:fece:cafe::5179

View File

@ -0,0 +1,8 @@
[NetDev]
Name=ip6tnl99
Kind=ip6tnl
[Tunnel]
Mode=ip6ip6
Local=2a00:ffde:4567:edde::4987
Remote=2001:473:fece:cafe::5179

View File

@ -0,0 +1,9 @@
[NetDev]
Name=ipiptun99
Kind=ipip
MTUBytes=1480
[Tunnel]
Local=192.168.223.238
Remote=192.169.224.239
Independent=true

View File

@ -0,0 +1,8 @@
[NetDev]
Name=ipiptun99
Kind=ipip
MTUBytes=1480
[Tunnel]
Local=192.168.223.238
Remote=192.169.224.239

View File

@ -0,0 +1,6 @@
[NetDev]
Name=ipvlan99
Kind=ipvlan
[IPVLAN]
Mode=L2

View File

@ -0,0 +1,7 @@
[NetDev]
Name=sittun99
Kind=sit
[Tunnel]
Local=10.65.223.238
Remote=10.65.223.239

View File

@ -0,0 +1,7 @@
[NetDev]
Name=tap99
Kind=tap
[Tap]
MultiQueue=true
PacketInfo=true

View File

@ -0,0 +1,7 @@
[NetDev]
Name=tun99
Kind=tun
[Tun]
MultiQueue=true
PacketInfo=true

View File

@ -0,0 +1,3 @@
[NetDev]
Name=vcan99
Kind=vcan

View File

@ -0,0 +1,8 @@
[NetDev]
Name=veth99
Kind=veth
MACAddress=12:34:56:78:9a:bc
[Peer]
Name=veth-peer
MACAddress=12:34:56:78:9a:bd

View File

@ -0,0 +1,6 @@
[NetDev]
Name=vrf99
Kind=vrf
[VRF]
TableId=42

View File

@ -0,0 +1,7 @@
[NetDev]
Name=vtitun99
Kind=vti
[Tunnel]
Local=10.65.223.238
Remote=10.65.223.239

View File

@ -0,0 +1,7 @@
[NetDev]
Name=vti6tun99
Kind=vti6
[Tunnel]
Local=2a00:ffde:4567:edde::4987
Remote=2001:473:fece:cafe::5179

View File

@ -0,0 +1,16 @@
[NetDev]
Name=vxlan99
Kind=vxlan
[VXLAN]
Id=999
L2MissNotification=true
L3MissNotification=true
RouteShortCircuit=true
UDPChecksum=true
UDP6ZeroChecksumTx=true
UDP6ZeroChecksumRx=true
RemoteChecksumTx=true
RemoteChecksumRx=true
GroupPolicyExtension=true
DestinationPort=5555

View File

@ -0,0 +1,12 @@
[NetDev]
Name=wg99
Kind=wireguard
[WireGuard]
PrivateKey=EEGlnEPYJV//kbvvIqxKkQwOiS+UENyPncC4bF46ong=
ListenPort=51820
[WireGuardPeer]
PublicKey=RDf+LSpeEre7YEIKaxg+wbpsNV7du+ktR99uBEtIiCA=
AllowedIPs=fd31:bf08:57cb::/48,192.168.26.0/24
Endpoint=wireguard.example.com:51820

View File

@ -0,0 +1,3 @@
[NetDev]
Name=bridge99
Kind=bridge

View File

@ -0,0 +1,5 @@
[NetDev]
Name=veth99
Kind=veth
MACAddress=12:34:56:78:9a:bc
MACAddress=12:34:56:78:9a:bc