mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/net/gnrc_pktbuf: detect use after free if canary is in metadata
This commit is contained in:
parent
ea1670ab0f
commit
83f5b261a8
@ -93,6 +93,14 @@ void gnrc_pktbuf_release_error(gnrc_pktsnip_t *pkt, uint32_t err)
|
||||
assert(gnrc_pktbuf_contains(pkt));
|
||||
assert(pkt->users > 0);
|
||||
tmp = pkt->next;
|
||||
|
||||
/* if the memory was freed, memory has been overwritten by CANARY */
|
||||
if (CONFIG_GNRC_PKTBUF_CHECK_USE_AFTER_FREE &&
|
||||
pkt->users == GNRC_PKTBUF_CANARY) {
|
||||
puts("gnrc_pktbuf: double free detected\n");
|
||||
DEBUG_BREAKPOINT(3);
|
||||
}
|
||||
|
||||
if (pkt->users == 1) {
|
||||
pkt->users = 0; /* not necessary but to be on the safe side */
|
||||
if (!IS_USED(MODULE_GNRC_TX_SYNC)
|
||||
|
@ -218,6 +218,13 @@ gnrc_pktsnip_t *gnrc_pktbuf_start_write(gnrc_pktsnip_t *pkt)
|
||||
mutex_unlock(&gnrc_pktbuf_mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (CONFIG_GNRC_PKTBUF_CHECK_USE_AFTER_FREE &&
|
||||
pkt->users == GNRC_PKTBUF_CANARY) {
|
||||
puts("gnrc_pktbuf: use after free detected\n");
|
||||
DEBUG_BREAKPOINT(3);
|
||||
}
|
||||
|
||||
if (pkt->users > 1) {
|
||||
gnrc_pktsnip_t *new;
|
||||
new = _create_snip(pkt->next, pkt->data, pkt->size, pkt->type);
|
||||
|
Loading…
Reference in New Issue
Block a user