git: 922fd62ec363 - main - ppp: drop config packets whose options overrun the packet

From: Nick Price <nprice_at_FreeBSD.org>
Date: Sun, 08 Nov 2026 01:34:42 UTC
The branch main has been updated by nprice:

URL: https://cgit.FreeBSD.org/src/commit/?id=922fd62ec36351929c273792971219e301021843

commit 922fd62ec36351929c273792971219e301021843
Author:     Nick Price <nprice@FreeBSD.org>
AuthorDate: 2026-11-08 01:34:05 +0000
Commit:     Nick Price <nprice@FreeBSD.org>
CommitDate: 2026-11-08 01:34:10 +0000

    ppp: drop config packets whose options overrun the packet
    
    fsm_readopt() advanced the decode cursor by the option length without
    checking it against the end of the packet.  A crafted LCP/CCP/IPCP
    option could then make the Config-Reject/Nak echo copy past the
    received packet into adjacent heap, disclosing heap bytes to the peer
    before authentication.
    
    Check the option framing once in fsm_Input() and drop the packet before
    decoding per RFC1661
    
    Reviewed by:    adrian, markj
    Differential Revision:  https://reviews.freebsd.org/D61008
    Approved by:    adrian (mentor)
    Signed-off-by: Nick Price <nprice@FreeBSD.org>
---
 usr.sbin/ppp/fsm.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/usr.sbin/ppp/fsm.c b/usr.sbin/ppp/fsm.c
index 060a9149a6af..0aaf8e2a7c1b 100644
--- a/usr.sbin/ppp/fsm.c
+++ b/usr.sbin/ppp/fsm.c
@@ -1040,10 +1040,22 @@ FsmRecvResetAck(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
   m_freem(bp);
 }
 
+static int
+FsmCheckOptions(const u_char *cp, const u_char *end)
+{
+  while (end - cp >= (int)sizeof(struct fsm_opt_hdr)) {
+    if (cp[1] < sizeof(struct fsm_opt_hdr) || cp[1] > end - cp)
+      return 0;
+    cp += cp[1];
+  }
+  return cp == end;
+}
+
 void
 fsm_Input(struct fsm *fp, struct mbuf *bp)
 {
   size_t len;
+  u_char *cp;
   struct fsmheader lh;
   const struct fsmcodedesc *codep;
 
@@ -1083,6 +1095,18 @@ fsm_Input(struct fsm *fp, struct mbuf *bp)
   }
 
   codep = FsmCodes + lh.code - 1;
+  if (lh.code >= CODE_CONFIGREQ && lh.code <= CODE_CONFIGREJ &&
+      ntohs(lh.length) > sizeof lh) {
+    bp = m_pullup(bp);
+    cp = MBUF_CTOP(bp);
+    if (!FsmCheckOptions(cp, cp + ntohs(lh.length) - sizeof lh)) {
+      log_Printf(LogWARN, "%s: Recv%s(%d): bad option length - dropped\n",
+                 fp->link->name, codep->name, lh.id);
+      m_freem(bp);
+      return;
+    }
+  }
+
   if (lh.id != fp->reqid && codep->check_reqid &&
       Enabled(fp->bundle, OPT_IDCHECK)) {
     log_Printf(fp->LogLevel, "%s: Recv%s(%d), dropped (expected %d)\n",