]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: New style fuzzing tool for P2P frame processing
authorJouni Malinen <j@w1.fi>
Sat, 1 Jun 2019 13:15:35 +0000 (16:15 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 2 Jun 2019 10:00:39 +0000 (13:00 +0300)
This is a newer version of tests/p2p-fuzzer tool.

Signed-off-by: Jouni Malinen <j@w1.fi>
tests/fuzzing/p2p/Makefile [new file with mode: 0644]
tests/fuzzing/p2p/corpus/go-neg-req.dat [new file with mode: 0644]
tests/fuzzing/p2p/corpus/invitation-req.dat [new file with mode: 0644]
tests/fuzzing/p2p/corpus/p2ps-pd-req.dat [new file with mode: 0644]
tests/fuzzing/p2p/corpus/proberesp-go.dat [new file with mode: 0644]
tests/fuzzing/p2p/corpus/proberesp.dat [new file with mode: 0644]
tests/fuzzing/p2p/p2p.c [new file with mode: 0644]

diff --git a/tests/fuzzing/p2p/Makefile b/tests/fuzzing/p2p/Makefile
new file mode 100644 (file)
index 0000000..c088e32
--- /dev/null
@@ -0,0 +1,18 @@
+all: p2p
+include ../rules.include
+
+LIBS += $(SRC)/utils/libutils.a
+LIBS += $(SRC)/common/libcommon.a
+LIBS += $(SRC)/crypto/libcrypto.a
+LIBS += $(SRC)/p2p/libp2p.a
+LIBS += $(SRC)/tls/libtls.a
+LIBS += $(SRC)/wps/libwps.a
+
+p2p: p2p.o $(OBJS) $(LIBS)
+       $(LDO) $(LDFLAGS) -o $@ $^ $(LIBS)
+
+clean:
+       $(MAKE) -C $(SRC) clean
+       rm -f p2p *~ *.o *.d ../*~ ../*.o ../*.d
+
+-include $(OBJS:%.o=%.d)
diff --git a/tests/fuzzing/p2p/corpus/go-neg-req.dat b/tests/fuzzing/p2p/corpus/go-neg-req.dat
new file mode 100644 (file)
index 0000000..ed06834
Binary files /dev/null and b/tests/fuzzing/p2p/corpus/go-neg-req.dat differ
diff --git a/tests/fuzzing/p2p/corpus/invitation-req.dat b/tests/fuzzing/p2p/corpus/invitation-req.dat
new file mode 100644 (file)
index 0000000..5991f3e
Binary files /dev/null and b/tests/fuzzing/p2p/corpus/invitation-req.dat differ
diff --git a/tests/fuzzing/p2p/corpus/p2ps-pd-req.dat b/tests/fuzzing/p2p/corpus/p2ps-pd-req.dat
new file mode 100644 (file)
index 0000000..7e1b6d9
Binary files /dev/null and b/tests/fuzzing/p2p/corpus/p2ps-pd-req.dat differ
diff --git a/tests/fuzzing/p2p/corpus/proberesp-go.dat b/tests/fuzzing/p2p/corpus/proberesp-go.dat
new file mode 100644 (file)
index 0000000..8541652
Binary files /dev/null and b/tests/fuzzing/p2p/corpus/proberesp-go.dat differ
diff --git a/tests/fuzzing/p2p/corpus/proberesp.dat b/tests/fuzzing/p2p/corpus/proberesp.dat
new file mode 100644 (file)
index 0000000..8d997d1
Binary files /dev/null and b/tests/fuzzing/p2p/corpus/proberesp.dat differ
diff --git a/tests/fuzzing/p2p/p2p.c b/tests/fuzzing/p2p/p2p.c
new file mode 100644 (file)
index 0000000..8ffcbbd
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ * wpa_supplicant - P2P fuzzer
+ * Copyright (c) 2015, Jouni Malinen <j@w1.fi>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "common/ieee802_11_defs.h"
+#include "p2p/p2p.h"
+#include "../fuzzer-common.h"
+
+
+static void debug_print(void *ctx, int level, const char *msg)
+{
+       wpa_printf(level, "P2P: %s", msg);
+}
+
+
+static void find_stopped(void *ctx)
+{
+}
+
+
+static int start_listen(void *ctx, unsigned int freq,
+                       unsigned int duration,
+                       const struct wpabuf *probe_resp_ie)
+{
+       return 0;
+}
+
+
+static void stop_listen(void *ctx)
+{
+}
+
+
+static void dev_found(void *ctx, const u8 *addr,
+                     const struct p2p_peer_info *info,
+                     int new_device)
+{
+}
+
+
+static void dev_lost(void *ctx, const u8 *dev_addr)
+{
+}
+
+
+static int send_action(void *ctx, unsigned int freq, const u8 *dst,
+                      const u8 *src, const u8 *bssid, const u8 *buf,
+                      size_t len, unsigned int wait_time, int *scheduled)
+{
+       *scheduled = 0;
+       return 0;
+}
+
+
+static void send_action_done(void *ctx)
+{
+}
+
+
+static void go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id,
+                         u8 go_intent)
+{
+}
+
+
+static struct p2p_data * init_p2p(void)
+{
+       struct p2p_config p2p;
+
+       os_memset(&p2p, 0, sizeof(p2p));
+       p2p.max_peers = 100;
+       p2p.passphrase_len = 8;
+       p2p.channels.reg_classes = 1;
+       p2p.channels.reg_class[0].reg_class = 81;
+       p2p.channels.reg_class[0].channel[0] = 1;
+       p2p.channels.reg_class[0].channel[1] = 2;
+       p2p.channels.reg_class[0].channels = 2;
+       p2p.debug_print = debug_print;
+       p2p.find_stopped = find_stopped;
+       p2p.start_listen = start_listen;
+       p2p.stop_listen = stop_listen;
+       p2p.dev_found = dev_found;
+       p2p.dev_lost = dev_lost;
+       p2p.send_action = send_action;
+       p2p.send_action_done = send_action_done;
+       p2p.go_neg_req_rx = go_neg_req_rx;
+
+       return p2p_init(&p2p);
+}
+
+
+struct arg_ctx {
+       const u8 *data;
+       size_t data_len;
+       struct p2p_data *p2p;
+       int count;
+};
+
+
+static void test_send(void *eloop_data, void *user_ctx)
+{
+       struct arg_ctx *ctx = eloop_data;
+       struct os_reltime rx_time;
+
+       wpa_hexdump(MSG_MSGDUMP, "fuzzer - IEs", ctx->data, ctx->data_len);
+
+       os_memset(&rx_time, 0, sizeof(rx_time));
+       p2p_scan_res_handler(ctx->p2p, (u8 *) "\x02\x00\x00\x00\x01\x00", 2412,
+                            &rx_time, 0, ctx->data, ctx->data_len);
+       p2p_scan_res_handled(ctx->p2p);
+
+       p2p_probe_req_rx(ctx->p2p, (u8 *) "\x02\x00\x00\x00\x01\x00",
+                        (u8 *) "\x02\x00\x00\x00\x00\x00",
+                        (u8 *) "\x02\x00\x00\x00\x00\x00",
+                        ctx->data, ctx->data_len, 2412, 0);
+
+       if (ctx->data_len >= IEEE80211_HDRLEN + 1) {
+               struct os_reltime rx_time;
+               const struct ieee80211_mgmt *mgmt;
+
+               mgmt = (const struct ieee80211_mgmt *) ctx->data;
+               os_memset(&rx_time, 0, sizeof(rx_time));
+               p2p_rx_action(ctx->p2p, mgmt->da, mgmt->sa, mgmt->bssid,
+                             mgmt->u.action.category,
+                             (const u8 *) ctx->data + IEEE80211_HDRLEN + 1,
+                             ctx->data_len - IEEE80211_HDRLEN - 1, 2412);
+       }
+
+       eloop_terminate();
+}
+
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+       struct p2p_data *p2p;
+       struct arg_ctx ctx;
+
+       wpa_fuzzer_set_debug_level();
+
+       if (os_program_init())
+               return -1;
+
+       if (eloop_init()) {
+               wpa_printf(MSG_ERROR, "Failed to initialize event loop");
+               return 0;
+       }
+
+       p2p = init_p2p();
+       if (!p2p) {
+               wpa_printf(MSG_ERROR, "P2P init failed");
+               return 0;
+       }
+
+       os_memset(&ctx, 0, sizeof(ctx));
+       ctx.p2p = p2p;
+       ctx.data = data;
+       ctx.data_len = size;
+
+       eloop_register_timeout(0, 0, test_send, &ctx, NULL);
+
+       wpa_printf(MSG_DEBUG, "Starting eloop");
+       eloop_run();
+       wpa_printf(MSG_DEBUG, "eloop done");
+
+       p2p_deinit(p2p);
+       eloop_destroy();
+       os_program_deinit();
+
+       return 0;
+}