Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungConnect Claude to Perplexity AI Pro with Zero Search API Fees(24.09.2026 um 09:57 Uhr)
Sichere ProgrammierungInvestigating Fraud with a Graph, Not Just a Prompt(24.09.2026 um 10:01 Uhr)
Sichere ProgrammierungA .docx does not store where its pages end(24.09.2026 um 10:01 Uhr)
Sichere Programmierung9 Best Enterprise AI Gateways With SSO, RBAC, and Audit Logs (2026)(24.09.2026 um 10:01 Uhr)
Sichere ProgrammierungThe Signal Contract for a 5-Minute TWAP Market(24.09.2026 um 10:03 Uhr)
Sichere ProgrammierungRemoteMac(24.09.2026 um 10:06 Uhr)
Sichere ProgrammierungDesigning a Batch Move That Handles Partial Failure(24.09.2026 um 10:07 Uhr)
Sichere ProgrammierungThe Model Was Never the Problem(24.09.2026 um 10:07 Uhr)
Sichere ProgrammierungConnect Claude to Perplexity AI Pro with Zero Search API Fees(24.09.2026 um 09:57 Uhr)
Sichere ProgrammierungInvestigating Fraud with a Graph, Not Just a Prompt(24.09.2026 um 10:01 Uhr)
Sichere ProgrammierungA .docx does not store where its pages end(24.09.2026 um 10:01 Uhr)
Sichere Programmierung9 Best Enterprise AI Gateways With SSO, RBAC, and Audit Logs (2026)(24.09.2026 um 10:01 Uhr)
Sichere ProgrammierungThe Signal Contract for a 5-Minute TWAP Market(24.09.2026 um 10:03 Uhr)
Sichere ProgrammierungRemoteMac(24.09.2026 um 10:06 Uhr)
Sichere ProgrammierungDesigning a Batch Move That Handles Partial Failure(24.09.2026 um 10:07 Uhr)
Sichere ProgrammierungThe Model Was Never the Problem(24.09.2026 um 10:07 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Observing Malloc - Phase 0 Mini Malloc

This is a journey of how I built my first memory allocator. Note: The clues and guidance I mention below were given to me by an AI assistant, used purely to guide my understanding of concepts and syntax. The entire code is written…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

This is a journey of how I built my first memory allocator.







Note:

The clues and guidance I mention below were given to me by an AI assistant, used purely to guide my understanding of concepts and syntax. The entire code is written by me, referencing the official glibc documentation throughout.

I'm mentioning this explicitly because I believe in being honest about the learning process.




The entire process and my code has been uploaded to my github account:

[https://github.com/moonlitpath1/mini-malloc]





Let's start!



First, I'll build a mental model of what malloc does at the systems level by observing it's behavior.





0.1 : Using strace to see how kernel manages memory for ls



Command to run




anu@laptop:~$ strace -e trace=brk,mmap,munmap ls 2>&1 | head -40






[[dump/strace mmap, brk, munmap|Actual code output]]




  • there are 2 ways to give memory to a program



    • brk: extending the heap


    • mmap: maps all the shared library files .so (that ls depends on)









── PHASE 1: Library Loading ──────────────────────────────────
brk(NULL) = 0x555555579000 ← "where does my heap end?" (just a question, heap doesn't grow yet)
mmap(NULL, 8192, ..., -1, 0) ← anonymous memory for the loader itself
mmap(NULL, 81463, ..., 3, 0) ← loading a .so file (fd=3 means a library file)
mmap(NULL, 181960,..., 3, 0) ← loading another .so file
mmap(..., 118784,..., 3, 0x6000) ← loading another .so file
... (10 more mmap lines, all fd=3) ...

── PHASE 2: Heap Actually Grows ──────────────────────────────
brk(NULL) = 0x555555579000 ← asking again: "where is my heap?"
brk(0x55555559a000) = 0x55555559a000 ← NOW the heap actually moves forward ✅

── PHASE 3: Last Big mmap (locale/directory data) ────────────
mmap(NULL, 5719296, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7ffff7600000

── OUTPUT ────────────────────────────────────────────────────
anu
backup.log
Desktop
...













0.2 Watching the heap using a C program



Theory:

brk() is a kernel syscall. The kernel maintains a pointer called program break - the official boundary marking the end of the process' heap segment in the virtual memory




Virtual Memory Layout (kernel's view):
┌─────────────┐
│ stack │ ← grows downward
│ ↓ │
│ (gap) │
│ ↑ │
│ heap │ ← grows upward
│─────────────│ ← PROGRAM BREAK (brk moves this line)
│ data/bss │
│ text │
└─────────────┘






brk() moves that line up or down. the kernel just manages this boundary.



sbrk(0) is a C library wrapper that asks the kernel where the program break is rn.
























What it is

brk / program break
End of the heap segment in virtual memory
Top chunk end End of glibc's usable unallocated space

sbrk(0) return value
Just reads the program break


These all point to the same address, but for different reasons.



The heap that we refer to here is both the Cs heap and the kernel's heap. According to the kernel, we are accessing the data segment, that's a range of addresses owned by the processor

glibc calls it heap and imposes structures on it - chunks, bins, top chunk



The kernel has no knowledge of the internal structures made by glibc. It's just a collection of bytes for it.



This was my C program:




#include<stdio.h>
#include
<unistd.h>
#include
<stdlib.h>

int main()
{
printf("Heap Pointer locataion:\nBefore:%p", sbrk(0));
malloc(1000);

printf("\nAfter:%p", sbrk(0));
return 0;

}







and this is my what my compiled file when traced with strace looks like




strace -e trace=brk ./heap_spy









brk(NULL)                               = 0x555555559000
brk(NULL) = 0x555555559000
brk(0x55555557a000) = 0x55555557a000

Heap Pointer locataion:
Before:0x555555559000
After:0x55555557a000+++ exited with 0 +++







I asked for 1000 bytes using malloc however, the difference:



0x55555557a000 - 0x555555559000 = 0x21000 = 135,168 bytes ≈ 132 KB



I got wayyy more than what I asked for!

this is because glibc is greedy. system calls are expensive so it stocks up some more memory for future use.



aka glibc buys memory in wholesale, and stores it in its private stock.



Why were there 2 brk calls?




brk(NULL)  = 0x555555559000   ← not from your code
brk(NULL) = 0x555555559000 ← your sbrk(0) call
brk(...) = 0x55555557a000 ← your malloc(1000)






The 1st brk happened before my code ran. it a part of glibc's startup routine to check where the current heap pointer is.

//notice glibc is doing stuff before main







Experiment 0.3 - Breaking the pattern





#include<stdio.h>
#include
<unistd.h>
#include
<stdio.h>
#include
<unistd.h>
#include
<stdlib.h>

int main()
{
printf("Heap Pointer locataion:\nBefore:%p", sbrk(0));

printf("\n1st malloc\nMalloc Pointer Address: %p\n", malloc(1000));
printf("Heap Pointer location:%p", sbrk(0));

printf("\n2nd malloc\nMalloc Pointer Address: %p\n", malloc(1000));
printf("Heap Pointer location:%p", sbrk(0));

printf("\n3rd malloc\nMalloc Pointer Address: %p\n", malloc(1000));
printf("Heap Pointer location:%p", sbrk(0));


char cmd[64]; //creates a character buffer

//proc -- linux virtual file system -- you are getting memory mappings of a process that containt the word "heap" using current pid

sprintf(cmd, "cat /proc/%d/maps | grep heap", getpid());
system(cmd); //executes the command using /bin/sh

return 0;

}







OUTPUT traced with strace:




strace -e trace=brk ./out
brk(NULL) = 0x555555559000
brk(NULL) = 0x555555559000
brk(0x55555557a000) = 0x55555557a000
Heap Pointer locataion:
Before:0x555555559000

--- 1st malloc
Malloc Pointer Address: 0x5555555596b0
Heap Pointer location:0x55555557a000

--- 2nd malloc
Malloc Pointer Address: 0x555555559aa0
Heap Pointer location:0x55555557a000

--- 3rd malloc
Malloc Pointer Address: 0x555555559e90

555555559000-55555557a000 rw-p 00000000 00:00 0 [heap]
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=11441, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
Heap Pointer location:0x55555557a000+++ exited with 0 +++







We notice that all 3 malloc pointer addresses are within the initial 132kb reigion.



The 132KB call had set up the arena, wherein my data was packed neatly. the memory malloc got was from the arena's top chunk



brk() was called just once to set up the arena, and after that glibc gave the memory as needed to malloc.






Extra:

Previously, my code looked like this:




#include <stdio.h>
#include
<unistd.h>
#include
<stdlib.h>

int main()
{
printf("Heap Pointer location:\nBefore:%p", sbrk(0));
printf("\n1st malloc\nMalloc Pointer Address: %p\nHeap Pointer location:%p", malloc(1000), sbrk(0));
printf("\n2nd malloc\nMalloc Pointer Address: %p\nHeap Pointer location:%p", malloc(1000), sbrk(0));
printf("\n3rd malloc\nMalloc Pointer Address: %p\nHeap Pointer location:%p", malloc(1000), sbrk(0));

return 0;
}






and for some reason, the strace looked like this when I ran it, after rebooting however, looked like the previous strace, no brk() calls after malloc(). I have absolutely no clue why as of now, but I'll explore it in the future.




Heap Pointer locataion:
Before:0x555555559000
1st malloc
Malloc Pointer Address: 0x5555555596b0
Heap Pointer location:0x55555557a000
2nd malloc
Malloc Pointer Address: 0x555555559aa0
Heap Pointer location:0x55555557a3e8
3rd malloc
Malloc Pointer Address: 0x555555559e90
Heap Pointer location:0x55555557a7d0
Press ENTER or type command to continue
brk(NULL) = 0x555555559000
brk(NULL) = 0x555555559000
brk(0x55555557a000) = 0x55555557a000
Heap Pointer locataion:
brk(0x55555557a3e8) = 0x55555557a3e8
Before:0x555555559000
1st malloc
Malloc Pointer Address: 0x5555555596b0
brk(0x55555557a7d0) = 0x55555557a7d0
Heap Pointer location:0x55555557a000
2nd malloc
Malloc Pointer Address: 0x555555559aa0
brk(0x55555557abb8) = 0x55555557abb8
Heap Pointer location:0x55555557a3e8
3rd malloc
Malloc Pointer Address: 0x555555559e90
Heap Pointer location:0x55555557a7d0+++ exited with 0 +++
Heap Pointer locataion:
Before:0x555555559000
1st malloc
Malloc Pointer Address: 0x5555555596b0
Heap Pointer location:0x55555557a000
2nd malloc
Malloc Pointer Address: 0x555555559aa0
Heap Pointer location:0x55555557a3e8
3rd malloc
Malloc Pointer Address: 0x555555559e90
Heap Pointer location:0x55555557a7d0


CTI Threat Relationship Graph3 Knoten / 2 Relationen
CVE / Incident Software MITRE ATT&CK CWE Weakness IoC
SOC Incident Playbook: Vulnerability Remediation & Verification
title: Detect Exploitation - Observing Malloc - Phase 0 Mini Malloc
id: e1d932d5-6967-40e7-8286-b2660f5f5238
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-24
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-24"
        description = "YARA Signature for "
    strings:
        $str = "Observing Malloc - Phase 0 Min" ascii wide
    condition:
        any of them
}
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Observing Malloc - Phase 0 Mini Malloc.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Observing Malloc - Phase 0 Mini Malloc

Thematisch verwandte Begriffe: Observing, Malloc, Phase, Mini · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-97056 | SigNoz versions from v0.98.0 up to (but not including) v0.143.0, when co…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick