-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fuzzing: Update to afl++, adding persisten-fuzzing example #19562
Open
Teufelchen1
wants to merge
1
commit into
RIOT-OS:master
Choose a base branch
from
Teufelchen1:feat/afl++
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+60
−9
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fuzzing: Update to afl++, adding persisten-fuzzing example
- Loading branch information
commit 4c696ac46603cb39c1987cb2341b8b0f23dc77b1
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
include ../Makefile.fuzzing_common | ||
|
||
USEMODULE += nanocoap_resources | ||
USEMODULE += gcoap | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
include ../Makefile.fuzzing_common | ||
# name of your application | ||
APPLICATION = uriparser | ||
|
||
USEMODULE += uri_parser | ||
|
||
# Comment this out to disable code in RIOT that does safety checking | ||
# which is not needed in a production environment but helps in the | ||
# development process: | ||
DEVELHELP ?= 1 | ||
|
||
# Change this to 0 show compiler invocation lines by default: | ||
QUIET ?= 0 | ||
|
||
# Needed when using afl++ and persistent fuzzing | ||
CFLAGS += -Wno-gnu-statement-expression | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coap:///R@[2008::1]:5own//R@[2008::1]:5own/?v=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coap://user@[2001:db8::1]:12345 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ftp://riot-os.org:99/bar/foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
http://riot-os.org:99/bar/foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coap://user@[2001:db8::1%eth0]:12345 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <err.h> | ||
|
||
#include "uri_parser.h" | ||
#include "fuzzing.h" | ||
|
||
__AFL_FUZZ_INIT() | ||
|
||
#pragma clang optimize off | ||
|
||
int main(void) | ||
{ | ||
__AFL_INIT(); | ||
unsigned char *buf = __AFL_FUZZ_TESTCASE_BUF; | ||
while (__AFL_LOOP(10000)) { | ||
int len = __AFL_FUZZ_TESTCASE_LEN; | ||
uri_parser_result_t uri_res; | ||
uri_parser_process(&uri_res, (char *)buf, len); | ||
} | ||
|
||
exit(EXIT_SUCCESS); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
include $(RIOTMAKE)/toolchain/gnu.inc.mk | ||
include $(RIOTMAKE)/toolchain/llvm.inc.mk | ||
|
||
CC = $(PREFIX)afl-gcc | ||
CXX = $(PREFIX)afl-g++ | ||
LINK = $(PREFIX)afl-gcc | ||
LINKXX = $(PREFIX)afl-g++ | ||
CC = $(PREFIX)afl-clang-fast | ||
CXX = $(PREFIX)afl-clang-fast++ | ||
LINK = $(PREFIX)afl-clang-fast | ||
LINKXX = $(PREFIX)afl-clang-fast++ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for waiting.
Otherwise
coap_resources
andcoap_resources_numof
are not defined. See/sys/net/application_layer/nanocoap/nanocoap.c:448
. The file gets pulled in as soon as you use thegcoap
module.With normal llvm/gcc this isn't an issue, only AFL++ is affected.
As far as I understand it, this is usually not a problem as the code paths containing the undefined values aren't used and get removed during build. AFL++ seems to do this differently and immediately complains about the undefined references even though they aren't used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhm sounds a bit vague, to make my explanation clear:
You can comment out
coap_well_known_core_default_handler
andcoap_handle_req
innanocoap.c
and still compile & runexamples/gcoap/
using gcc/llvm. In this modified state, the gcoap fuzzing examples also builds fine via AFL++ without thenanocoap_resources
module.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a bit concerning because the
if (IS_USED(MODULE_…)) {
pattern is used quite a lot in RIOT.What is the error you are getting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see what's happening, looks like
--gc-sections
does not happen with AFL++.In the 'old style' applications were expected to define
coap_resources
/coap_resources_numof
, now withnanocoap_resources
this is an XFA and the definitions are inside nanoCoAP. But to not break applications we keep support for the legacy definitions unless the application requestsnanocoap_resources
.The GCoAP fuzzing example doesn't make use of nanoCoAP resources at all (as GCoAP has it's own way to define resources as a linked list of resource arrays) but the functions that would interact with
nanocoap_resources
are still compiled as they are part of common code, they are just not used by GCoAP so they are normally discarded on linking.