Linux Heap Memory Architecture: Chunks, Bins, and Allocators

Unlike stack memory which grows downward from high addresses and is automatically managed via function call frames, Heap memory grows upward from lower addresses and is managed explicitly at runtime via dynamic allocation. Understanding heap layout and allocator metadata is fundamental to analyzing heap exploitation primitives (such as use-after-free, heap overflows, fastbin dupes, and unlink exploitation). Core Allocation Primitives malloc(size): Requests size bytes from the heap and returns a generic pointer. The returned memory is uninitialized. calloc(num, size): Allocates memory for an array and initializes all bytes to zero (mitigates information disclosure bugs). realloc(ptr, size): Resizes an existing heap block, either expanding in-place or allocating a new region, copying existing data, and freeing the old chunk. free(ptr): Releases the allocated chunk back to the heap manager. Kernel Interface: brk/sbrk vs. mmap The userspace memory allocator (e.g., Glibc’s ptmalloc) interacts with the Linux kernel using two primary system calls: ...

May 22, 2020 · 3 min · 561 words · Ahmad Mahfouz

Deploying High-Availability Multi-Master MySQL NDB Clusters with MySQL Cluster Manager

Traditional MySQL replication architectures (active-passive or source-replica topologies) introduce replication lag and require failover orchestrators (e.g., Orchestrator or ProxySQL) to handle master crashes. MySQL NDB Cluster is a shared-nothing, distributed database that provides real-time in-memory performance, 99.999% high availability, and active-active multi-master read/write capabilities across all SQL nodes. This guide details configuring and scaling a multi-master NDB cluster using Oracle MySQL Cluster Manager (MCM). Core Architecture & Node Roles An NDB cluster consists of three distinct node types: ...

September 5, 2017 · 3 min · 528 words · Ahmad Mahfouz

Investigating SELinux AVC Denials with ausearch and Centralized Rsyslog

When SELinux operates in enforcing mode, policy violations are intercepted and logged as Access Vector Cache (AVC) denial records in the Linux audit subsystem (/var/log/audit/audit.log). Diagnosing blocked operations efficiently requires mastering ausearch and establishing structured log routing. 1. Querying AVC Denials with ausearch The ausearch utility parses the binary-formatted audit logs to isolate specific event types and translate raw numeric IDs into human-readable strings. Find All AVC Denials Generated Today ausearch -m avc -i -ts today -m avc: Filters events specifically matching the AVC (Access Vector Cache) audit record type. -i: Interprets numeric identifiers into human-readable text (resolves UIDs to usernames, GIDs to group names, and syscall numbers to system call names). -ts today: Limits the search timeframe to the current calendar day. Additional Useful Filters # Query denials by executable name ausearch -m avc -c httpd -ts recent # Query denials by process ID (PID) ausearch -m avc -p 1234 # Check for AVC denials alongside system audit messages ausearch -m avc,user_avc,selinux_err -i 2. Converting AVC Denials into Remediation Rules To examine why an operation was blocked and generate human-readable policy recommendations: ...

July 23, 2016 · 2 min · 357 words · Ahmad Mahfouz

Monitoring Linux Infrastructure with Performance Co-Pilot (PCP) and Web UI

Performance Co-Pilot (PCP) is an enterprise-grade system performance analysis and telemetry framework. Developed to monitor large distributed environments, PCP gathers live and historical metrics covering kernel internals, hardware subsystems, file systems, disk I/O, memory pressure, and networking. 1. Installation and Daemon Setup On Red Hat Enterprise Linux, CentOS, or Fedora, install the core PCP packages: sudo yum install -y pcp pcp-webjs Performance Metrics Collector Daemon (pmcd) pmcd acts as the primary coordinator, querying Performance Metric Domain Agents (PMDAs) for subsystem statistics: ...

July 23, 2016 · 2 min · 419 words · Ahmad Mahfouz

Advanced iptables: PREROUTING and POSTROUTING with DNAT and SNAT

When deploying jump hosts, transparent proxies, or network bridges across multi-homed Linux systems, standard routing tables are often insufficient. Using the Linux Netfilter framework via iptables, you can manipulate packets at both ingress (PREROUTING) and egress (POSTROUTING). Scenario 1: Basic Traffic Forwarding via DNAT and MASQUERADE In this setup, our Linux server acts as an intermediary bridge forwarding traffic from a client to a remote backend service: Client Source IP: 198.51.100.12 Intermediary Gateway (Our Server): 203.0.113.30 Final Backend Destination: 192.0.2.84 Client [198.51.100.12] ──► Gateway [203.0.113.30] ──► Backend [192.0.2.84] Step 1: Destination NAT in PREROUTING Intercept incoming packets destined for our gateway and rewrite the destination IP before routing lookup occurs: ...

July 14, 2016 · 2 min · 339 words · Ahmad Mahfouz

Fixing phpMyAdmin Error #1146: Table 'phpmyadmin.pma_tracking' Doesn't Exist

When navigating through phpMyAdmin, you may encounter the following error: #1146 - Table 'phpmyadmin.pma_tracking' doesn't exist Figure 1: Missing internal configuration storage tables in phpMyAdmin. This error indicates that phpMyAdmin’s internal metadata and configuration storage database (phpmyadmin) was either skipped during initial package installation or failed to execute its SQL initialization scripts. Solution 1: Reconfigure via dpkg-reconfigure (Recommended) On Debian and Ubuntu systems, the cleanest method to repair the metadata database is using dbconfig-common via dpkg-reconfigure: ...

June 26, 2016 · 1 min · 204 words · Ahmad Mahfouz

Enabling Passwordless Login in phpMyAdmin for Local Development

When configuring a local development environment (such as on a virtual machine or local development container) where MySQL root has an empty password, phpMyAdmin blocks authentication attempts by default with the following error: Login without a password is forbidden by configuration (see AllowNoPassword) This security safeguard prevents accidental deployment of passwordless database instances in publicly accessible environments. Enabling Empty Passwords in config.inc.php To enable passwordless authentication for local sandbox testing, modify the phpMyAdmin configuration file: ...

June 26, 2016 · 1 min · 153 words · Ahmad Mahfouz

Resolving PHP Mcrypt Extension Symlink Conflicts on Ubuntu Server

When configuring legacy PHP environments on Ubuntu Server and attempting to activate the mcrypt cryptographic module, administrators may encounter symlink collision warnings. The Error Condition After installing the extension packages: sudo apt-get install mcrypt php5-mcrypt Attempting to register the module via php5enmod produces the following error: root@ubuntu:~# php5enmod mcrypt WARNING: Not enabling the mcrypt module for apache2 SAPI since module symlink WARNING: already exists in /etc/php5/apache2/conf.d with different content. WARNING: Not enabling the mcrypt module for cli SAPI since module symlink WARNING: already exists in /etc/php5/cli/conf.d with different content. This error occurs when old or stale configuration symlinks pointing to prior configuration targets exist in the SAPI configuration directories (/etc/php5/apache2/conf.d/ and /etc/php5/cli/conf.d/), preventing the package manager from linking the canonical /etc/php5/mods-available/mcrypt.ini. ...

June 26, 2016 · 1 min · 178 words · Ahmad Mahfouz

Docker Architecture and Container Operations Crash Course

Unlike traditional Type-1 and Type-2 hypervisors that virtualize complete hardware stacks and boot independent operating system kernels, containers share the host Linux kernel while isolating processes using kernel Namespaces (PID, NET, IPC, MNT, UTS) and Control Groups (cgroups). Docker packages application dependencies, libraries, and runtime binaries into lightweight, immutable container images. Core Architecture Docker operates under a client-server model: Docker Client (docker): The CLI tool you execute to issue commands. Docker Daemon (dockerd): The background daemon listening for API requests to manage images, containers, networks, and storage volumes. Docker Registry: Public (Docker Hub) or private image repositories. A container lifecycle is tied directly to its primary foreground process (PID 1). When that process exits, the container stops. ...

May 30, 2016 · 2 min · 416 words · Ahmad Mahfouz

Auditing User Keystrokes with pam_tty_audit and Linux Auditd

Relying on standard shell history (~/.bash_history) for security auditing is fundamentally flawed: users can unset HISTFILE, launch sessions inside screen/tmux, prepend commands with spaces, or delete history files before logout. To reliably monitor user commands at the kernel level, Linux provides the pam_tty_audit PAM module. This module enables TTY input logging directly through the Linux Audit daemon (auditd), capturing keystrokes before the shell receives them. Module Parameters pam_tty_audit.so supports three key arguments: ...

October 7, 2015 · 2 min · 292 words · Ahmad Mahfouz