Skip to content

Heap overflow detection improvement (IDFGH-15349) #16008

Open
@bryghtlabs-richard

Description

@bryghtlabs-richard

Is your feature request related to a problem?

Today, I found a piece of code had corrupted a heap-buffer. (This is problem is mine alone)

However, I was surprised to find that it overwrote it by 1.7MB before a thread on the other core noticed, and crashed.

From the hardware available, it should be possible to make the heap much more aggressive at detecting these, and sometimes detect use-after-free as well.

Describe the solution you'd like.

I'd like to suggest that the ESP-HEAP treat physical memory as an array of MMU pages, and that access to those MMU pages be enabled/disabled as needed.

Ex:

  • On heap creation, access to the first page of the heap is enabled(and will stay enabled forever, also it must stay enabled if there are variables before it in the same page). Middle pages of the heap will be disabled. The last page of the heap must stay enabled if there are variables after it.
  • Once an allocation extends to a new page(s), access to those pages will be enabled.
  • When allocations are freed, if the coalesced area covers a whole page, access to that page will be disabled.
  • Access to a disabled page will fault and trap the error. This is nice, because the error is synchronous - the corrupting thread is much more likely to trap within 1x MMU page, or about 64KB.

Describe alternatives you've considered.

I won't write any more bugs ever again :)

Additional context.

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions