DragonFlyBSD Kernel Audit
DF-0831 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/vfs/udf/udf_vnops.c b/sys/vfs/udf/udf_vnops.c
--- a/sys/vfs/udf/udf_vnops.c
+++ b/sys/vfs/udf/udf_vnops.c
@@ -541,6 +541,16 @@
 
 		/* Copy what we have of the fid into a buffer */
 		frag_size = ds->size - ds->off;
+		/*
+		 * A previous FID's 4-byte alignment (udf_vnops.c:605) can advance
+		 * ds->off up to 3 bytes PAST ds->size, making frag_size negative.
+		 * The current FID then begins in the next extent, so there is no
+		 * fragment to copy from this one.  Clamp to zero so the bcopy()
+		 * below -- whose length is promoted int -> size_t -- can never
+		 * receive a huge sign-extended value (size_t(-3) ~= 16 EB).
+		 */
+		if (frag_size < 0)
+			frag_size = 0;
 		if (frag_size >= ds->udfmp->bsize) {
 			kprintf("udf: invalid FID fragment\n");
 			ds->error = EINVAL;