Blame SOURCES/ntp-4.2.6p5-cve-2016-1548.patch

6e16f6
diff -up ntp-4.2.6p5/ntpd/ntp_proto.c.cve-2016-1548 ntp-4.2.6p5/ntpd/ntp_proto.c
6e16f6
--- ntp-4.2.6p5/ntpd/ntp_proto.c.cve-2016-1548	2016-04-28 08:37:42.513561354 +0200
6e16f6
+++ ntp-4.2.6p5/ntpd/ntp_proto.c	2016-04-28 09:30:59.450347729 +0200
6e16f6
@@ -306,6 +306,7 @@ receive(
6e16f6
 	int	authlen;		/* offset of MAC field */
6e16f6
 	int	is_authentic = 0;	/* cryptosum ok */
6e16f6
 	int	retcode = AM_NOMATCH;	/* match code */
6e16f6
+	int	xleave_mismatch = 0;	/* mismatch in xleave mode */
6e16f6
 	keyid_t	skeyid = 0;		/* key IDs */
6e16f6
 	u_int32	opcode = 0;		/* extension field opcode */
6e16f6
 	sockaddr_u *dstadr_sin; 	/* active runway */
6e16f6
@@ -1067,9 +1068,8 @@ receive(
6e16f6
 		}
6e16f6
 
6e16f6
 	/*
6e16f6
-	 * Check for bogus packet in basic mode. If found, switch to
6e16f6
-	 * interleaved mode and resynchronize, but only after confirming
6e16f6
-	 * the packet is not bogus in symmetric interleaved mode.
6e16f6
+	 * Check for bogus packet in basic mode. If found, check if it's not
6e16f6
+	 * a valid packet in symmetric interleaved mode.
6e16f6
 	 */
6e16f6
 	} else if (peer->flip == 0) {
6e16f6
 		if (L_ISZERO(&p_org) || !L_ISEQU(&p_org, &peer->aorg)) {
6e16f6
@@ -1077,8 +1077,7 @@ receive(
6e16f6
 			peer->flash |= TEST2;	/* bogus */
6e16f6
 			if (!L_ISZERO(&peer->dst) && L_ISEQU(&p_org,
6e16f6
 			    &peer->dst)) {
6e16f6
-				peer->flip = 1;
6e16f6
-				report_event(PEVNT_XLEAVE, peer, NULL);
6e16f6
+				xleave_mismatch = 1;
6e16f6
 			}
6e16f6
 		} else {
6e16f6
 			L_CLR(&peer->aorg);
6e16f6
@@ -1152,6 +1151,16 @@ receive(
6e16f6
 	}
6e16f6
 
6e16f6
 	/*
6e16f6
+	 * If the packet is bogus in basic mode but not in symmetric
6e16f6
+	 * interleaved mode and it passed the authentication check,
6e16f6
+	 * enable the mode and resynchronize.
6e16f6
+	 */
6e16f6
+	if (xleave_mismatch && hismode == MODE_ACTIVE) {
6e16f6
+		peer->flip = 1;
6e16f6
+		report_event(PEVNT_XLEAVE, peer, NULL);
6e16f6
+	}
6e16f6
+
6e16f6
+	/*
6e16f6
 	 * Update the state variables.
6e16f6
 	 */
6e16f6
 	if (peer->flip == 0) {
6e16f6
@@ -1715,5 +1723,12 @@ clock_update(
6e16f6
 	sys_rootdelay = peer->delay + peer->rootdelay;
6e16f6
 	sys_reftime = peer->dst;
6e16f6
+	
6e16f6
+	/* Randomize the fraction part of the reference time to not reveal
6e16f6
+	   peer->dst to NTP clients as it could be used in a DoS attack
6e16f6
+	   enabling the symmetric interleaved mode with spoofed packets */
6e16f6
+	ntp_crypto_random_buf(&sys_reftime.l_uf, sizeof (sys_reftime.l_uf));
6e16f6
+	if (L_ISHIS(&sys_reftime, &peer->dst))
6e16f6
+		sys_reftime.l_ui--;
6e16f6
 
6e16f6
 #ifdef DEBUG
6e16f6
 	if (debug)