-
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
sys/net/gnrc_pktbuf_static: add use-after-free detection #18227
sys/net/gnrc_pktbuf_static: add use-after-free detection #18227
Conversation
4b67680
to
7396095
Compare
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.
Took me a moment to see that the +1
was in _unused_t
increments, but it does check in the right area. Tests with corruption (albeit right in _pktbuf_alloc) successfully triggered the panic.
Ah, the beauty of C pointer arithmetic ;-) |
98a2921
to
9768ce4
Compare
printf("[%p] mismatch at offset %u/%u (ignoring %d initial bytes that were repurposed)\n", | ||
(void *)ptr, (uintptr_t)mismatch - (uintptr_t)ptr, size, sizeof(_unused_t)); |
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.
printf("[%p] mismatch at offset %u/%u (ignoring %d initial bytes that were repurposed)\n", | |
(void *)ptr, (uintptr_t)mismatch - (uintptr_t)ptr, size, sizeof(_unused_t)); | |
printf("[%p] mismatch at offset %" PRIuPTR "/%zu (ignoring %zu initial bytes that were repurposed)\n", | |
(void *)ptr, (uintptr_t)mismatch - (uintptr_t)ptr, size, sizeof(_unused_t)); |
"%"PRIuPTR
can be used to print uintptr_t
, "%zu"
for size_t
.
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.
I'm pretty sure there is no %z
on newlib
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.
Hmm, maybe casting to unsigned
instead while staying with %u
to please the CI?
PRIuPTR
actually maps to something non-magical and should even work with a limited subset of supported printf format specifiers.
9768ce4
to
a165093
Compare
Contribution description
This overwrites the memory of the pktbuf chunk with a canary value and checks if the value is still there on allocation.
Testing procedure
Enable the option with
CFLAGS += -DCONFIG_GNRC_PKTBUF_CHECK_USE_AFTER_FREE=1
.This should now catch errors where a pktbuf chunk is written to after its been freed:
Issues/PRs references