Replies: 4 comments 3 replies
-
|
IMO it is legal to r/w within the page even if above the heap, like it is in linux (you can r/w above the heap pointer withing the page). This could cause corruption, but heap management should be handled by the compiler (or by the developer, depending on the language) Proof: #include <unistd.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
void *hs = sbrk(128);
int* n_arr = (int*)hs;
for(int i=0;i<256;i++) {
n_arr[i] = 0xda;
}
printf("0x%02x\n", n_arr[255]);
return 0;
} |
Beta Was this translation helpful? Give feedback.
-
|
^ @koute |
Beta Was this translation helpful? Give feedback.
-
|
Irrelevant, since But to answer your original question as to what was the original intent: it works in page granularity, so if you, say, do But as I said - this is irrelevant now, because |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for the clarification @dakk @davxy and @koute! In that case the trace is correct. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Should memory access beyond sbrk allocation cause a panic?
The Scenario
sbrk(500)and receives address0x330000x33600(which is 256 bytes beyond the 500-byte allocation)My Initial Interpretation
YES - the program only allocated 500 bytes, so accessing byte 600 should panic.
The Problem
The graypaper defines memory permissions at page granularity (4096 bytes), not byte granularity:
ram_accessis a sequence of 2^32/4096 entries (one per page)sbrk(500)makes bytes[0x33000, 0x331f4)writable, it must mark the entire page writable[0x33000, 0x34000)haveram_access = W0x33600IS now writableThe Question
Is it legal for a program to read/write any byte within a page that was made writable by sbrk, even if those bytes are beyond the exact number of bytes requested?
Or should implementations track exact byte allocations and panic on access beyond that, which I assume is done by most implementation as they seem to pass this trace.
Beta Was this translation helpful? Give feedback.
All reactions