DragonFlyBSD Kernel Audit
DF-0562 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/netgraph7/lmi/ng_lmi.c b/sys/netgraph7/lmi/ng_lmi.c
--- a/sys/netgraph7/lmi/ng_lmi.c
+++ b/sys/netgraph7/lmi/ng_lmi.c
@@ -750,6 +750,17 @@
 
 	packetlen = m->m_len;
 	data = mtod(m, const u_char *);
+	/*
+	 * Enforce the minimum LMI frame length that the fixed-header
+	 * parsing below assumes (LMI_MIN_LENGTH). Without this guard,
+	 * a short frame causes STEPBY() to underflow `packetlen`
+	 * (u_short 0 -> 0xFFFF) and the IE loop then reads adjacent
+	 * kernel heap.
+	 */
+	if (packetlen < LMI_MIN_LENGTH) {
+		log(LOG_WARNING, "nglmi: too short (%u)\n", packetlen);
+		goto reject;
+	}
 	if (*data != 0x03) {
 		log(LOG_WARNING, "nglmi: unexpected value in LMI(%d)\n", 1);
 		goto reject;