⬢ DragonFlyBSD Kernel Audit
DF-2752 / fix.diff
← back to finding ↓ download raw
--- sys/kern/sys_pipe.c	2026-06-29 12:51:19.000000000 +0000
+++ /tmp/opencode/v26/fixtree/sys/kern/sys_pipe.c	2026-10-24 16:33:07.733716274 +0000
@@ -370,6 +370,18 @@
 	if (size > 1024*1024)
 		size = 1024*1024;
 
+	/*
+	 * DF-2752: the FIFO index masks are (size - 1); a non-power-of-2
+	 * size aliases slots and silently corrupts in-flight pipe data.
+	 * Round up to a power of 2 (16K..1M are already powers of 2).
+	 */
+	if (size & (size - 1)) {
+		size_t p2 = 16384;
+		while (p2 < size)
+			p2 <<= 1;
+		size = p2;
+	}
+
 	npages = round_page(size) / PAGE_SIZE;
 	object = pb->object;