]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Sec 3043] Autokey association reset. perlinger@ntp.org
authorJuergen Perlinger <perlinger@ntp.org>
Sun, 8 May 2016 09:59:28 +0000 (11:59 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Sun, 8 May 2016 09:59:28 +0000 (11:59 +0200)
 (fixes [Sec 3044] and [Sec 3045], too)

bk: 572f0e00tPCCm3gAK4z5KNe0suIVsg

ChangeLog
ntpd/ntp_proto.c

index dc7b627a61e8569eba246199c91e011e83f814a5..e930510b4c1674eac9b92daf7d38805fcd808bd1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 ---
 
+* [Sec 3043]  Autokey association reset. perlinger@ntp.org
+  (fixes [Sec 3044] and [Sec 3045], too)
 * [Sec 3046] CRYPTO_NAK crash.  stenn@ntp.org
 * [Bug 3038] NTP fails to build in VS2015. perlinger@ntp.org
   - provide build environment
index 4b50f5ae2c34b9f583c62b96b5419f3b3306f6d6..3ef52251b9ba6b1bc22d6bdf87f16cd25e339d7d 100644 (file)
@@ -277,10 +277,12 @@ valid_NAK(
          u_char hismode
          )
 {
-       int base_packet_length = MIN_V4_PKT_LEN;
-       int remainder_size;
-       struct pkt *rpkt;
-       int keyid;
+       int             base_packet_length = MIN_V4_PKT_LEN;
+       int             remainder_size;
+       struct pkt *    rpkt;
+       int             keyid;
+       l_fp            p_org;  /* origin timestamp */
+       const l_fp *    myorg;  /* selected peer origin */
 
        /*
         * Check to see if there is something beyond the basic packet
@@ -320,13 +322,29 @@ valid_NAK(
        /* 
         * Only valid if peer uses a key
         */
-       if (   peer
-           && (peer->keyid > 0 || peer->flags & FLAG_SKEY)) {
-               return (VALIDNAK);
+       if (!peer || !peer->keyid || !(peer->flags & FLAG_SKEY)) {
+               return (INVALIDNAK);
        }
-       else {
+
+       /*
+        * The ORIGIN must match, or this cannot be a valid NAK, either.
+        */
+       NTOHL_FP(&rpkt->org, &p_org);
+       if (peer->flip > 0)
+               myorg = &peer->borg;
+       else
+               myorg = &peer->aorg;
+       
+       if (L_ISZERO(&p_org) ||
+           L_ISZERO( myorg) ||
+           !L_ISEQU(&p_org, myorg)) {
                return (INVALIDNAK);
        }
+
+       /* If we ever passed all that checks, we should be safe. Well,
+        * as safe as we can ever be with an unauthenticated crypto-nak.
+        */
+       return (VALIDNAK);
 }
 
 
@@ -1682,13 +1700,11 @@ receive(
                peer->flash |= TEST5;           /* bad auth */
                peer->badauth++;
                if (peer->flags & FLAG_PREEMPT) {
-                       if (unpeer_crypto_nak_early) {
+                       if (unpeer_crypto_nak_early)
                                unpeer(peer);
-                       }
-                       return;
                }
 #ifdef AUTOKEY
-               if (peer->crypto)
+               else if (peer->crypto)
                        peer_clear(peer, "AUTH");
 #endif /* AUTOKEY */
                return;
@@ -1709,16 +1725,6 @@ receive(
                if (   has_mac
                    && (hismode == MODE_ACTIVE || hismode == MODE_PASSIVE))
                        fast_xmit(rbufp, MODE_ACTIVE, 0, restrict_mask);
-               if (peer->flags & FLAG_PREEMPT) {
-                       if (unpeer_digest_early) {
-                               unpeer(peer);
-                       }
-                       return;
-               }
-#ifdef AUTOKEY
-               if (peer->crypto)
-                       peer_clear(peer, "AUTH");
-#endif /* AUTOKEY */
                return;
        }