Mercurial > dropbear
annotate fuzz.h @ 1780:b5aedadc0008
fuzzing - Set postauth user to root since that's what it runs as
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 17 Nov 2020 19:28:11 +0800 |
parents | 36d4c027cba7 |
children | a6da10ac64b5 |
rev | line source |
---|---|
1348 | 1 #ifndef DROPBEAR_FUZZ_H |
2 #define DROPBEAR_FUZZ_H | |
3 | |
1357 | 4 #include "config.h" |
1559
92c93b4a3646
Fix to be able to compile normal(ish) binaries with --enable-fuzz
Matt Johnston <matt@ucc.asn.au>
parents:
1558
diff
changeset
|
5 |
1558
2f64cb3d3007
- #if not #ifdef for DROPBEAR_FUZZ
Matt Johnston <matt@ucc.asn.au>
parents:
1456
diff
changeset
|
6 #if DROPBEAR_FUZZ |
1357 | 7 |
1348 | 8 #include "includes.h" |
9 #include "buffer.h" | |
1357 | 10 #include "algo.h" |
1778 | 11 #include "netio.h" |
1357 | 12 #include "fuzz-wrapfd.h" |
1348 | 13 |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1348
diff
changeset
|
14 // once per process |
1456
a90fdd2d2ed8
add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents:
1385
diff
changeset
|
15 void fuzz_common_setup(void); |
a90fdd2d2ed8
add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents:
1385
diff
changeset
|
16 void fuzz_svr_setup(void); |
1741
d1b279aa5ed1
Get client fuzzer building and starting (fails straight away)
Matt Johnston <matt@ucc.asn.au>
parents:
1740
diff
changeset
|
17 void fuzz_cli_setup(void); |
1348 | 18 |
1758
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
19 // constructor attribute so it runs before main(), including |
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
20 // in non-fuzzing mode. |
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
21 void fuzz_early_setup(void) __attribute__((constructor)); |
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
22 |
1377
d4cc85e6c569
rearrange, all fuzzers now call fuzzer_set_input()
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
23 // must be called once per fuzz iteration. |
d4cc85e6c569
rearrange, all fuzzers now call fuzzer_set_input()
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
24 // returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE |
1456
a90fdd2d2ed8
add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents:
1385
diff
changeset
|
25 int fuzz_set_input(const uint8_t *Data, size_t Size); |
a90fdd2d2ed8
add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents:
1385
diff
changeset
|
26 |
1777
97ad26e397a5
Add server postauth fuzzer, wrap connect_remote()
Matt Johnston <matt@ucc.asn.au>
parents:
1768
diff
changeset
|
27 int fuzz_run_server(const uint8_t *Data, size_t Size, int skip_kexmaths, int authdone); |
1746 | 28 int fuzz_run_client(const uint8_t *Data, size_t Size, int skip_kexmaths); |
1589
35af85194268
Add kexdh and kexecdh fuzzers
Matt Johnston <matt@ucc.asn.au>
parents:
1561
diff
changeset
|
29 const void* fuzz_get_algo(const algo_type *algos, const char* name); |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1348
diff
changeset
|
30 |
1369 | 31 // fuzzer functions that intrude into general code |
1357 | 32 void fuzz_kex_fakealgos(void); |
1369 | 33 int fuzz_checkpubkey_line(buffer* line, int line_num, char* filename, |
34 const char* algo, unsigned int algolen, | |
35 const unsigned char* keyblob, unsigned int keybloblen); | |
36 extern const char * const * fuzz_signkey_names; | |
1757
517fb7b62438
Add some more variation to fuzzer random number generation
Matt Johnston <matt@ucc.asn.au>
parents:
1751
diff
changeset
|
37 void fuzz_seed(const unsigned char* dat, unsigned int len); |
1741
d1b279aa5ed1
Get client fuzzer building and starting (fails straight away)
Matt Johnston <matt@ucc.asn.au>
parents:
1740
diff
changeset
|
38 |
1778 | 39 typedef void(*connect_callback)(int result, int sock, void* data, const char* errstring); |
40 struct dropbear_progress_connection *fuzz_connect_remote(const char* remotehost, const char* remoteport, | |
41 connect_callback cb, void* cb_data, | |
42 const char* bind_address, const char* bind_port); | |
43 | |
1741
d1b279aa5ed1
Get client fuzzer building and starting (fails straight away)
Matt Johnston <matt@ucc.asn.au>
parents:
1740
diff
changeset
|
44 // helpers |
1383
f03cfe9c76ac
Disable setnonblocking(), get_socket_address(), set_sock_priority()
Matt Johnston <matt@ucc.asn.au>
parents:
1377
diff
changeset
|
45 void fuzz_get_socket_address(int fd, char **local_host, char **local_port, |
f03cfe9c76ac
Disable setnonblocking(), get_socket_address(), set_sock_priority()
Matt Johnston <matt@ucc.asn.au>
parents:
1377
diff
changeset
|
46 char **remote_host, char **remote_port, int host_lookup); |
1456
a90fdd2d2ed8
add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents:
1385
diff
changeset
|
47 void fuzz_fake_send_kexdh_reply(void); |
1740
dfbe947bdf0d
Make wrapfd share a common buffer for all FDs
Matt Johnston <matt@ucc.asn.au>
parents:
1589
diff
changeset
|
48 int fuzz_spawn_command(int *ret_writefd, int *ret_readfd, int *ret_errfd, pid_t *ret_pid); |
1751
3b9b427925a0
Load password and key for client fuzzer.
Matt Johnston <matt@ucc.asn.au>
parents:
1746
diff
changeset
|
49 void fuzz_dump(const unsigned char* data, size_t len); |
1357 | 50 |
51 // fake IO wrappers | |
52 #ifndef FUZZ_SKIP_WRAP | |
53 #define select(nfds, readfds, writefds, exceptfds, timeout) \ | |
54 wrapfd_select(nfds, readfds, writefds, exceptfds, timeout) | |
55 #define write(fd, buf, count) wrapfd_write(fd, buf, count) | |
56 #define read(fd, buf, count) wrapfd_read(fd, buf, count) | |
1358
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
57 #define close(fd) wrapfd_close(fd) |
1357 | 58 #endif // FUZZ_SKIP_WRAP |
59 | |
1348 | 60 struct dropbear_fuzz_options { |
61 int fuzzing; | |
62 | |
63 // fuzzing input | |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1348
diff
changeset
|
64 buffer *input; |
1357 | 65 struct dropbear_cipher recv_cipher; |
66 struct dropbear_hash recv_mac; | |
67 int wrapfds; | |
1348 | 68 |
1456
a90fdd2d2ed8
add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents:
1385
diff
changeset
|
69 // whether to skip slow bignum maths |
a90fdd2d2ed8
add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents:
1385
diff
changeset
|
70 int skip_kexmaths; |
a90fdd2d2ed8
add fuzzer-preauth_nomaths
Matt Johnston <matt@ucc.asn.au>
parents:
1385
diff
changeset
|
71 |
1348 | 72 // dropbear_exit() jumps back |
1385
6c92e97553f1
Add a flag whether to longjmp, missed that last commit
Matt Johnston <matt@ucc.asn.au>
parents:
1383
diff
changeset
|
73 int do_jmp; |
1348 | 74 sigjmp_buf jmp; |
1751
3b9b427925a0
Load password and key for client fuzzer.
Matt Johnston <matt@ucc.asn.au>
parents:
1746
diff
changeset
|
75 |
3b9b427925a0
Load password and key for client fuzzer.
Matt Johnston <matt@ucc.asn.au>
parents:
1746
diff
changeset
|
76 // write out decrypted session data to this FD if it's set |
3b9b427925a0
Load password and key for client fuzzer.
Matt Johnston <matt@ucc.asn.au>
parents:
1746
diff
changeset
|
77 // flag - this needs to be set manually in cli-main.c etc |
3b9b427925a0
Load password and key for client fuzzer.
Matt Johnston <matt@ucc.asn.au>
parents:
1746
diff
changeset
|
78 int dumping; |
3b9b427925a0
Load password and key for client fuzzer.
Matt Johnston <matt@ucc.asn.au>
parents:
1746
diff
changeset
|
79 // the file descriptor |
3b9b427925a0
Load password and key for client fuzzer.
Matt Johnston <matt@ucc.asn.au>
parents:
1746
diff
changeset
|
80 int recv_dumpfd; |
1758
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
81 |
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
82 // avoid filling fuzzing logs, this points to /dev/null |
1768
096a66e45212
Fix fuzzing stderr override on os x
Matt Johnston <matt@ucc.asn.au>
parents:
1758
diff
changeset
|
83 FILE *fake_stderr; |
1348 | 84 }; |
85 | |
86 extern struct dropbear_fuzz_options fuzz; | |
87 | |
1768
096a66e45212
Fix fuzzing stderr override on os x
Matt Johnston <matt@ucc.asn.au>
parents:
1758
diff
changeset
|
88 /* guard for when fuzz.h is included by fuzz-common.c */ |
096a66e45212
Fix fuzzing stderr override on os x
Matt Johnston <matt@ucc.asn.au>
parents:
1758
diff
changeset
|
89 #ifndef FUZZ_NO_REPLACE_STDERR |
096a66e45212
Fix fuzzing stderr override on os x
Matt Johnston <matt@ucc.asn.au>
parents:
1758
diff
changeset
|
90 |
1758
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
91 /* This is a bodge but seems to work. |
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
92 glibc stdio.h has the comment |
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
93 "C89/C99 say they're macros. Make them happy." */ |
1768
096a66e45212
Fix fuzzing stderr override on os x
Matt Johnston <matt@ucc.asn.au>
parents:
1758
diff
changeset
|
94 /* OS X has it as a macro */ |
1758
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
95 #ifdef stderr |
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
96 #undef stderr |
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
97 #endif |
1768
096a66e45212
Fix fuzzing stderr override on os x
Matt Johnston <matt@ucc.asn.au>
parents:
1758
diff
changeset
|
98 #define stderr (fuzz.fake_stderr) |
096a66e45212
Fix fuzzing stderr override on os x
Matt Johnston <matt@ucc.asn.au>
parents:
1758
diff
changeset
|
99 |
096a66e45212
Fix fuzzing stderr override on os x
Matt Johnston <matt@ucc.asn.au>
parents:
1758
diff
changeset
|
100 #endif /* FUZZ_NO_REPLACE_STDERR */ |
1758
1365661f6be6
Disable stderr output for fuzzer by default
Matt Johnston <matt@ucc.asn.au>
parents:
1757
diff
changeset
|
101 |
1779
36d4c027cba7
fuzzing: add workaround getpwuid/getpwnam
Matt Johnston <matt@ucc.asn.au>
parents:
1778
diff
changeset
|
102 struct passwd* fuzz_getpwuid(uid_t uid); |
36d4c027cba7
fuzzing: add workaround getpwuid/getpwnam
Matt Johnston <matt@ucc.asn.au>
parents:
1778
diff
changeset
|
103 struct passwd* fuzz_getpwnam(const char *login); |
36d4c027cba7
fuzzing: add workaround getpwuid/getpwnam
Matt Johnston <matt@ucc.asn.au>
parents:
1778
diff
changeset
|
104 /* guard for when fuzz.h is included by fuzz-common.c */ |
36d4c027cba7
fuzzing: add workaround getpwuid/getpwnam
Matt Johnston <matt@ucc.asn.au>
parents:
1778
diff
changeset
|
105 #ifndef FUZZ_NO_REPLACE_GETPW |
36d4c027cba7
fuzzing: add workaround getpwuid/getpwnam
Matt Johnston <matt@ucc.asn.au>
parents:
1778
diff
changeset
|
106 #define getpwnam(x) fuzz_getpwnam(x) |
36d4c027cba7
fuzzing: add workaround getpwuid/getpwnam
Matt Johnston <matt@ucc.asn.au>
parents:
1778
diff
changeset
|
107 #define getpwuid(x) fuzz_getpwuid(x) |
36d4c027cba7
fuzzing: add workaround getpwuid/getpwnam
Matt Johnston <matt@ucc.asn.au>
parents:
1778
diff
changeset
|
108 #endif // FUZZ_NO_REPLACE_GETPW |
36d4c027cba7
fuzzing: add workaround getpwuid/getpwnam
Matt Johnston <matt@ucc.asn.au>
parents:
1778
diff
changeset
|
109 |
1357 | 110 #endif // DROPBEAR_FUZZ |
1348 | 111 |
112 #endif /* DROPBEAR_FUZZ_H */ |