Skip to content
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

Mark sbrk region as uninitialized #300

Open
ramidzkh opened this issue Jan 15, 2024 · 0 comments
Open

Mark sbrk region as uninitialized #300

ramidzkh opened this issue Jan 15, 2024 · 0 comments

Comments

@ramidzkh
Copy link

Making the region revealed by sbrk filled with uninitialized by default is possibly sufficient.

A heap allocator using sbrk could allocate extra memory to ensure subsequent sbrk addresses remain well-aligned. Rather than filling the gap between the requested memory and the end of the allocation with nulls, or clear marker bytes, it would be useful for debugging purposes to mark this gap as uninitialized. In fact, the entire region should probably be uninitialized and set by the code.

main:
        addiu   $sp, $sp, -4
        sw $ra, 0($sp)

        addiu   $a0, $zero, 1           # 1 byte
        jal     malloc                  # sbrk's 16 bytes header + 1 byte + 7 byte padding for 8 byte alignment
        lb      $t0, 0($v0)             # Access first byte (uninitialized, should die)
        lb      $t1, 1($v0)             # Access padding (uninitialized and padding, should die)
        lb      $t1, 8($v0)             # Access 8th byte (out of bounds, dies here)

        move    $a0, $v0
        jal     free

        addiu   $v0, $zero, 0           # Return 0

        lw      $ra, 0($sp)
        addiu   $sp, $sp, 4
        jr      $ra
[mipsy] run
error: segmentation fault

this happened because you tried to read from
the address `0x10040018`, which is not a valid address to read from

the instruction that failed was:
0x00400290 208 [0x80490008]    lb     $t1, 8($v0)       #  lb      $t1, 8($v0)             # Access 8th byte (out of bounds, dies here)


tip: the address `0x10040018` is part of the DATA segment


[mipsy] x 0x10040000
0x10040000: 0000 0000 0000 0000 1800 0000 01__ ____  .............___
0x10040010: ____ ____ ____ ____ ____ ____ ____ ____  ________________
0x10040020: ____ ____ ____ ____ ____ ____ ____ ____  ________________
0x10040030: ____ ____ ____ ____ ____ ____ ____ ____  ________________
0x10040040: ____ ____ ____ ____ ____ ____ ____ ____  ________________
0x10040050: ____ ____ ____ ____ ____ ____ ____ ____  ________________
0x10040060: ____ ____ ____ ____ ____ ____ ____ ____  ________________
0x10040070: ____ ____ ____ ____ ____ ____ ____ ____  ________________
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant