diff --git a/share/security/advisories/FreeBSD-EN-16:01.filemon.asc b/share/security/advisories/FreeBSD-EN-16:01.filemon.asc new file mode 100644 index 0000000000..11783e493b --- /dev/null +++ b/share/security/advisories/FreeBSD-EN-16:01.filemon.asc @@ -0,0 +1,124 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +============================================================================= +FreeBSD-EN-16:01.filemon Errata Notice + The FreeBSD Project + +Topic: filemon and bmake meta-mode stability issues + +Category: core +Module: filemon +Announced: 2016-01-14 +Credits: Bryan Drewery +Affects: FreeBSD 10.2-RELEASE +Corrected: 2015-09-09 17:15:13 UTC (stable/10, 10.2-STABLE) + 2016-01-14 09:10:46 UTC (releng/10.2, 10.2-RELEASE-p9) + +For general information regarding FreeBSD Errata Notices and Security +Advisories, including descriptions of the fields above, security branches, +and the following sections, please visit +. + +I. Background + +In FreeBSD 10.2, /usr/bin/make is the NetBSD bmake utility. bmake has +a feature called meta-mode [1], which can make use of the filemon(4) kernel +module to perform reliable update builds and provide better build +dependencies. +[1] http://www.crufty.net/sjg/blog/freebsd-meta-mode.htm + +II. Problem Description + +Multiple stability and locking problems have been fixed in the filemon(4) +kernel module. Without these fixes, using meta-mode and filemon(4) on a +FreeBSD 10.2 system may result in kernel panics. + +III. Impact + +For the jails and virtual machines used by the FreeBSD Jenkins Continuous +Integration builders, it is desirable to use released versions FreeBSD. +This will allow us to set up builders to test building FreeBSD-CURRENT with +meta-mode, using a FreeBSD 10.2-RELEASE-p9 build host. + +IV. Workaround + +No workaround is available for the filemon stability problems. + +V. Solution + +Perform one of the following: + +1) Upgrade your system to a supported FreeBSD stable or release / security +branch (releng) dated after the correction date. + +2) To update your present system via a binary patch: + +Systems running a RELEASE version of FreeBSD on the i386 or amd64 +platforms can be updated via the freebsd-update(8) utility: + +# freebsd-update fetch +# freebsd-update install + +3) To update your present system via a source code patch: + +The following patches have been verified to apply to the applicable +FreeBSD release branches. + +a) Download the relevant patch from the location below, and verify the +detached PGP signature using your PGP utility. + +# fetch https://security.FreeBSD.org/patches/EN-16:01/filemon.patch +# fetch https://security.FreeBSD.org/patches/EN-16:01/filemon.patch.asc +# gpg --verify filemon.patch.asc + +b) Apply the patch. Execute the following commands as root: + +# cd /usr/src +# patch < /path/to/patch + +c) Recompile your kernel as described in + and reboot the +system. + +VI. Correction details + +The following list contains the correction revision numbers for each +affected branch. + +Branch/path Revision +- ------------------------------------------------------------------------- +stable/10 r287598 +releng/10.2 r293893 +- ------------------------------------------------------------------------- + +To see which files were modified by a particular revision, run the +following command, replacing NNNNNN with the revision number, on a +machine with Subversion installed: + +# svn diff -cNNNNNN --summarize svn://svn.freebsd.org/base + +Or visit the following URL, replacing NNNNNN with the revision number: + + + +VII. References + +The latest revision of this Errata Notice is available at + +-----BEGIN PGP SIGNATURE----- + +iQIcBAEBCgAGBQJWl2jlAAoJEO1n7NZdz2rnF6kQAJEgtPKwowupOd3QV2UvMJ4T +PP/UK9tvF+Tbmow+5z9vV8ghh/oHc/AUWxhbIcnOFO7YldwrYJDXAHWF5VoTgatb +Ycg+R10Kyg8loZZuAAaGsY+zS78BIXunKVduWealz6TV978sZ5mr7qVJjX03Bvdh +9s3dX6PLfA0ZtqxXuhJ3oMj1Nt7UoGyNNNg23TWhQDMzpueB1EihhjzcLEk8UCjR +OlZElMXsnI/c9zG0eaSDPqfUuQrZDasQ+kM4eWaEXxcZVHSEQtU7vJ6SjxAkeCHT +fzRcAilzQBQJzObzpdXCxrd3OmKL52Ml44Kll2k31QQM3YDHw5g+mMJ+G6BoD5HZ +hQktb7Y064s/SQ0S91aTCgdSBzlTOny7IjsE1W+T6WD4Dohc1aY5y5u2UDBIRIS9 +BvovQF9k0PXIqpA3DjV1cGp3oYLpmJc5NYqHuJ9hkQWSp8FntfuQ1gKpieznyg25 +mb7fsOU693Dglcodtz1uQcwwgh/0s7bEcP6o7ejzsd4bzhe9CTLgD5qp0MD8htiH +Li+i9O5hUS8nheJt03btw/mq7CPbr66JWnpVHmPe8kL8SU7qmwBwq6d3buk5Hyr1 +tOmpuTyW+dq4iWweG411/j9M8Q03fD/DI4Ez2KS5OTizNAWb2wq8e+OZIk6TDE37 +Aam3KrksQZjG+sqL7NVp +=INcx +-----END PGP SIGNATURE----- diff --git a/share/security/advisories/FreeBSD-EN-16:02.pf.asc b/share/security/advisories/FreeBSD-EN-16:02.pf.asc new file mode 100644 index 0000000000..0337dae215 --- /dev/null +++ b/share/security/advisories/FreeBSD-EN-16:02.pf.asc @@ -0,0 +1,149 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +============================================================================= +FreeBSD-EN-16:02.pf Errata Notice + The FreeBSD Project + +Topic: Invalid TCP checksums with pf(4) + +Category: core +Module: pf +Announced: 2016-01-14 +Credits: Kristof Provost +Affects: All supported versions of FreeBSD. +Corrected: 2015-11-11 12:36:42 UTC (stable/10, 10.2-STABLE) + 2016-01-14 09:10:46 UTC (releng/10.2, 10.2-RELEASE-p9) + 2016-01-14 09:11:16 UTC (releng/10.1, 10.1-RELEASE-p26) + 2015-12-25 15:12:54 UTC (stable/9, 9.3-STABLE) + 2016-01-14 09:11:26 UTC (releng/9.3, 9.3-RELEASE-p33) + +For general information regarding FreeBSD Errata Notices and Security +Advisories, including descriptions of the fields above, security +branches, and the following sections, please visit +. + +I. Background + +The pf(4) is one of several packet filters available in FreeBSD, originally +written for OpenBSD. In addition to filtering packets, it also has packet +normalization capabilities. + +II. Problem Description + +When running with certain network interfaces, capable for hardware transmit +checksum offloading, or TCP segmentation offload, pf(4) produces packets with +invalid TCP checksums. + +III. Impact + +The TCP packets with invalid checksums are rejected by the remote host, +leading to large performance impacts or inability to successfully run +a TCP connection. + +IV. Workaround + +Disable transmit checksum offloading and TSO support on the affected +network interface: + +# ifconfig ue0 -txcsum -tso + +V. Solution + +Perform one of the following: + +1) Upgrade your system to a supported FreeBSD stable or release / security +branch (releng) dated after the correction date. + +Reboot the system or unload and reload the pf.ko kernel module. + +2) To update your system via a binary patch: + +Systems running a RELEASE version of FreeBSD on the i386 or amd64 +platforms can be updated via the freebsd-update(8) utility: + +# freebsd-update fetch +# freebsd-update install + +Reboot the system or unload and reload the pf.ko kernel module. + +3) To update your system via a source code patch: + +The following patches have been verified to apply to the applicable +FreeBSD release branches. + +a) Download the relevant patch from the location below, and verify the +detached PGP signature using your PGP utility. + +[FreeBSD 10.2] +# fetch https://security.FreeBSD.org/patches/EN-16:02/pf-10.2.patch +# fetch https://security.FreeBSD.org/patches/EN-16:02/pf-10.2.patch.asc +# gpg --verify pf-10.2.patch.asc + +[FreeBSD 10.1] +# fetch https://security.FreeBSD.org/patches/EN-16:02/pf-10.1.patch +# fetch https://security.FreeBSD.org/patches/EN-16:02/pf-10.1.patch.asc +# gpg --verify pf-10.1.patch.asc + +[FreeBSD 9.3] +# fetch https://security.FreeBSD.org/patches/EN-16:02/pf-9.3.patch +# fetch https://security.FreeBSD.org/patches/EN-16:02/pf-9.3.patch.asc +# gpg --verify pf-9.3.patch.asc + +b) Apply the patch. Execute the following commands as root: + +# cd /usr/src +# patch < /path/to/patch + +c) Recompile your kernel as described in + and reboot the +system or unload and reload the pf.ko kernel module. + +VI. Correction details + +The following list contains the correction revision numbers for each +affected branch. + +Branch/path Revision +- ------------------------------------------------------------------------- +stable/9/ r292732 +releng/9.3/ r293896 +stable/10/ r290669 +releng/10.1/ r293894 +releng/10.2/ r293893 +- ------------------------------------------------------------------------- + +To see which files were modified by a particular revision, run the +following command, replacing NNNNNN with the revision number, on a +machine with Subversion installed: + +# svn diff -cNNNNNN --summarize svn://svn.freebsd.org/base + +Or visit the following URL, replacing NNNNNN with the revision number: + + + +VII. References + + + + + +The latest revision of this advisory is available at + +-----BEGIN PGP SIGNATURE----- + +iQIcBAEBCgAGBQJWl2rlAAoJEO1n7NZdz2rnv0QP/RXPzKbSRsyyX3914BJv/W4V +coLFodRd62WxPvFIOXaLbNsVSi1yqRqNS3BPNTXnldEvjZWS5HsRlY5inq7hCjOn +NzZFIBVD3aL3eIXBUghNHTcCp3Ml5zIzcGUwJ0wW4F8j3D8Ty0YbJs+E7Ku63DIb +3rR2Mj1Jcoxi4JNVaQ962JlRrqauQUIiFbS0bSmP/cQCUlvhm+uk8Yj1KgSYesSu +n+lQAipH2zZWGjVj1xxvqi4cUcr6J6LEF0eTmg+UoM24vhq+QNql5aactYMOORiW +f+80HOWm6R8F/6TI2xs7HpNfnQNuNBRTfmfViQB8GgzgV2juElcTXW4NKXALrkWy +HxAfv6wdhDxclOXzumUXDOXC90o62Jv5gWiToJWLyETHI1vTe4UuE0egejFHSDJB +bmFpbYeuvXJ5/3dAYHHtnjtIPE9PXG+c16eJr3XDkY4plreL/hpyDHFRd3scqWew +EvPnkYcXZmzpCC/wZbDM5sI76YAfX7vayVqsUI0X4WRueYyIljRQGwygwfmHWiac +HIrgLgJvXZCGXiiuSpZq5874er0/UN9czGuMVOFZoXZ45yuj99pO1rJNZryO926A +UAOsC76m78myPrM+a4dJDrnWKgZjputCEBHXXNS8Yxt1cimrrbAb2wy0gt1CIMFm +cuAfikAwdNj3JAvjS4oA +=Aw1R +-----END PGP SIGNATURE----- diff --git a/share/security/advisories/FreeBSD-EN-16:03.yplib.asc b/share/security/advisories/FreeBSD-EN-16:03.yplib.asc new file mode 100644 index 0000000000..8cbc2fe16a --- /dev/null +++ b/share/security/advisories/FreeBSD-EN-16:03.yplib.asc @@ -0,0 +1,139 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +============================================================================= +FreeBSD-EN-16:03.ypclnt Errata Notice + The FreeBSD Project + +Topic: YP/NIS client library critical bug + +Category: core +Module: ypclnt +Announced: 2016-01-14 +Credits: Ravi Pokala, + Lakshmi Narasimhan Sundararajan, + Fred Lewis, + Pushkar Kothavade +Affects: All supported versions of FreeBSD. +Corrected: 2015-12-21 14:32:29 UTC (stable/10, 10.2-STABLE) + 2016-01-14 09:10:46 UTC (releng/10.2, 10.2-RELEASE-p9) + 2016-01-14 09:11:16 UTC (releng/10.1, 10.1-RELEASE-p26) + 2016-01-13 05:32:24 UTC (stable/9, 9.3-STABLE) + 2016-01-14 09:11:26 UTC (releng/9.3, 9.3-RELEASE-p33) + +For general information regarding FreeBSD Errata Notices and Security +Advisories, including descriptions of the fields above, security +branches, and the following sections, please visit +. + +I. Background + +The YP/NIS subsystem allows network management of passwd, group, netgroup, +hosts, services, rpc, bootparams and ethers file entries. The ypclnt suite +provides an interface to the YP subsystem. + +The standard NIS protocol limits its database entries to YPMAXRECORD (1024 +characters). + +II. Problem Description + +There is a bug with the NIS client library, which can lead to an infinite +loop. + +III. Impact + +A server that is deliberately configured to violate the NIS/YP protocol can +cause a FreeBSD NIS client to be stuck forever. + +IV. Workaround + +No workaround is available, but systems that are not configured to use +NIS/YP are not affected. + +V. Solution + +Perform one of the following: + +1) Upgrade your system to a supported FreeBSD stable or release / security +branch (releng) dated after the correction date. + +A reboot is recommended. + +2) To update your system via a binary patch: + +Systems running a RELEASE version of FreeBSD on the i386 or amd64 +platforms can be updated via the freebsd-update(8) utility: + +# freebsd-update fetch +# freebsd-update install + +A reboot is recommended. + +3) To update your system via a source code patch: + +The following patches have been verified to apply to the applicable +FreeBSD release branches. + +a) Download the relevant patch from the location below, and verify the +detached PGP signature using your PGP utility. + +# fetch https://security.FreeBSD.org/patches/EN-16:03/yplib.patch +# fetch https://security.FreeBSD.org/patches/EN-16:03/yplib.patch.asc +# gpg --verify yplib.patch.asc + +b) Apply the patch. Execute the following commands as root: + +# cd /usr/src +# patch < /path/to/patch + +c) Recompile the operating system using buildworld and installworld as +described in . + +A reboot is recommended. + +VI. Correction details + +The following list contains the correction revision numbers for each +affected branch. + +Branch/path Revision +- ------------------------------------------------------------------------- +stable/9/ r293804 +releng/9.3/ r293896 +stable/10/ r292547 +releng/10.1/ r293894 +releng/10.2/ r293893 +- ------------------------------------------------------------------------- + +To see which files were modified by a particular revision, run the +following command, replacing NNNNNN with the revision number, on a +machine with Subversion installed: + +# svn diff -cNNNNNN --summarize svn://svn.freebsd.org/base + +Or visit the following URL, replacing NNNNNN with the revision number: + + + +VII. References + + + +The latest revision of this advisory is available at + +-----BEGIN PGP SIGNATURE----- + +iQIcBAEBCgAGBQJWl2j1AAoJEO1n7NZdz2rnRZQP/iZq/xlDFZrxwpW4S0GimmmK +CdB9yE8rITW2XRWIaTW+fj4aqQ8cvD3IpqtgPe1wCXe69XgmICPwwBh/zNB4w0qu +xmyihP6/2qTLatIq886StqXRkS+05U5y4VoEwFaRkBCy3IWDVXgM41DsRhOuYq3y +Y72VNeJFSuD+qb0i0B56PpPhaVd7hyEgvuXLXxi3l/BiUMD9t4Z36W8a2IPrF1wa +wviTB6cr614dzH+Jou+d9ffKoD6TWeZtbcf1jrw12YVBJhPx3vCqPVJGerGRUwVF +TeD4cUyHmY1nRa4zssKJcbAbgbYGtumRZTysa50eXBVsd7MTloZk0o8Angr6uGeR +rRo8Sop8PbwWm81Zykb4lIBOVUB4TsEfMjusKhgcJ5kmd+gK8z1ZzE/ZlOes2UJ8 +eH+LOEKjux3c9UKkz6RDWinM277J5fhZ5Zi6jO6n/LrJRKiqKud6VeHQLOElXye7 +/8KFqCaym8JpZ0P3Cywid+2EyqjlNwvsZleDs8EE/d1+60yX+Qm2j+BKAfqhSyLD +a9TimJTsEMA47Rf3af2lx1q4bnrKJVSBGhNaNzDHe5UIge0FAt8uUwgL/yIDpBlS +/5TtnD3F30B34482sAf4u/WW/1ipppIFEe8i6d9uwIGjG9Z5eVVom2FJbAHHdVA6 +w8xVZil5irkB2fdI1DOi +=A4Qy +-----END PGP SIGNATURE----- diff --git a/share/security/advisories/FreeBSD-SA-16:01.sctp.asc b/share/security/advisories/FreeBSD-SA-16:01.sctp.asc new file mode 100644 index 0000000000..adcfec8722 --- /dev/null +++ b/share/security/advisories/FreeBSD-SA-16:01.sctp.asc @@ -0,0 +1,145 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +============================================================================= +FreeBSD-SA-16:01.sctp Security Advisory + The FreeBSD Project + +Topic: SCTP ICMPv6 error message vulnerability + +Category: core +Module: SCTP +Announced: 2016-01-14 +Credits: Jonathan T. Looney +Affects: All supported versions of FreeBSD +Corrected: 2016-01-14 09:11:42 UTC (stable/10, 10.2-STABLE) + 2016-01-14 09:10:46 UTC (releng/10.2, 10.2-RELEASE-p9) + 2016-01-14 09:11:16 UTC (releng/10.1, 10.1-RELEASE-p26) + 2016-01-14 09:11:48 UTC (stable/9, 9.3-STABLE) + 2016-01-14 09:11:26 UTC (releng/9.3, 9.3-RELEASE-p33) +CVE Name: CVE-2016-1879 + +For general information regarding FreeBSD Security Advisories, +including descriptions of the fields above, security branches, and the +following sections, please visit . + +I. Background + +The Stream Control Transmission Protocol (SCTP) protocol provides reliable, +flow-controlled, two-way transmission of data. + +The Internet Control Message Protocol for IPv6 (ICMPv6) provides a way for +hosts on the Internet to exchange control information. Among other uses, +a host or router can use ICMPv6 to inform a host when there is an error +delivering a packet sent by that host. + +II. Problem Description + +A lack of proper input checks in the ICMPv6 processing in the SCTP stack +can lead to either a failed kernel assertion or to a NULL pointer +dereference. In either case, a kernel panic will follow. + +III. Impact + +A remote, unauthenticated attacker can reliably trigger a kernel panic +in a vulnerable system running IPv6. Any kernel compiled with both IPv6 +and SCTP support is vulnerable. There is no requirement to have an SCTP +socket open. + +IPv4 ICMP processing is not impacted by this vulnerability. + +IV. Workaround + +No workaround is available, but systems using a kernel compiled without +SCTP support or IPv6 support are not vulnerable. + +In addition, some stateful firewalls may block ICMPv6 messages that are +not responding to a legitimate connection. (However, this may not +completely block the problem, as an ICMPv6 message could still be sent +in response to a legitimate SCTP connection.) + +V. Solution + +Perform one of the following: + +1) Upgrade your vulnerable system to a supported FreeBSD stable or +release / security branch (releng) dated after the correction date. +Rebooting to the new kernel is required. + +2) To update your vulnerable system via a binary patch: + +Systems running a RELEASE version of FreeBSD on the i386 or amd64 +platforms can be updated via the freebsd-update(8) utility: + +# freebsd-update fetch +# freebsd-update install + +Rebooting to the new kernel is required. + +3) To update your vulnerable system via a source code patch: + +The following patches have been verified to apply to the applicable +FreeBSD release branches. + +a) Download the relevant patch from the location below, and verify the +detached PGP signature using your PGP utility. + +# fetch https://security.FreeBSD.org/patches/SA-16:01/sctp.patch +# fetch https://security.FreeBSD.org/patches/SA-16:01/sctp.patch.asc +# gpg --verify sctp.patch.asc + +b) Apply the patch. Execute the following commands as root: + +# cd /usr/src +# patch < /path/to/patch + +c) Recompile your kernel as described in + and reboot the +system. + +VI. Correction details + +The following list contains the correction revision numbers for each +affected branch. + +Branch/path Revision +- ------------------------------------------------------------------------- +stable/9/ r293898 +releng/9.3/ r293896 +stable/10/ r293897 +releng/10.1/ r293894 +releng/10.2/ r293893 +- ------------------------------------------------------------------------- + +To see which files were modified by a particular revision, run the +following command, replacing NNNNNN with the revision number, on a +machine with Subversion installed: + +# svn diff -cNNNNNN --summarize svn://svn.freebsd.org/base + +Or visit the following URL, replacing NNNNNN with the revision number: + + + +VII. References + + + +The latest revision of this advisory is available at + +-----BEGIN PGP SIGNATURE----- + +iQIcBAEBCgAGBQJWl2j1AAoJEO1n7NZdz2rnIfoQAOZTLX3VovQPGj9wr7PspLQi +Tazu6vRnjzdOdjpeWwSgYlq6DJGjT71c/BRyCWCoijr2uyBWRlANqzMO64thuTzx +gc6juRlChLDF4sNVWbNDMRwuHTfCpgDH2/4hQeR/9CmiQxHJyqL0gXc889D206i9 +KzgmYrSALEVK0E2kDBeRMsadtqPIEzCw4LygWd4qrtYNPjAfBR/a9U4rg7ZN0ICZ +RCPnkAF6qI09B931QfHaI4C9wdBF8DJ6nKN/2aU9ATdOJJb7oUkpaHht8kmbdZS+ +Tn12nEXkQvNxuAKT7Fb87M14s7LUR12V5wgDeMd2UtOfkeSpGEDFACdhYW3IpKan +gD+2IlzLRhoQTJ7lQWMRTKh3OiDDR2kLwvbEU7BGecDSG6fVkgumn6NlHYybdH7L +axpDOxPz8ITfcdRipIXLOQEC308ckdmaEwqi4ikgBGwEkSgIwj1flGStswvcMrim +vT0xof2dv1y6RW5xYnJF7Mtn/rEcqrql/BeBp/kxJZ2Qt3hkppQnjWD6kvrEj00s +CajzxdBTM7J3buDzu++RL2GL9p5Cwo1kDmUJdWimIbSecL62J9+PwFCDYp/dOy25 +GAPGnf7gk8YhwM8pHwLtcX0b9UundkXLWnLBN7R12fL7Ch2CmPbgPcoFc5CSbcIx +TBRU+4TGcNGxigXyzIHT +=G0DD +-----END PGP SIGNATURE----- diff --git a/share/security/advisories/FreeBSD-SA-16:02.ntp.asc b/share/security/advisories/FreeBSD-SA-16:02.ntp.asc new file mode 100644 index 0000000000..aefd38e3ac --- /dev/null +++ b/share/security/advisories/FreeBSD-SA-16:02.ntp.asc @@ -0,0 +1,155 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +============================================================================= +FreeBSD-SA-16:02.ntp Security Advisory + The FreeBSD Project + +Topic: ntp panic threshold bypass vulnerability + +Category: contrib +Module: ntp +Announced: 2016-01-14 +Credits: Network Time Foundation +Affects: All supported versions of FreeBSD. +Corrected: 2016-01-11 01:09:50 UTC (stable/10, 10.2-STABLE) + 2016-01-14 09:10:46 UTC (releng/10.2, 10.2-RELEASE-p9) + 2016-01-14 09:11:16 UTC (releng/10.1, 10.1-RELEASE-p26) + 2016-01-11 01:48:16 UTC (stable/9, 9.3-STABLE) + 2016-01-14 09:11:26 UTC (releng/9.3, 9.3-RELEASE-p33) +CVE Name: CVE-2015-5300 + +For general information regarding FreeBSD Security Advisories, +including descriptions of the fields above, security branches, and the +following sections, please visit . + +I. Background + +The ntpd(8) daemon is an implementation of the Network Time Protocol (NTP) +used to synchronize the time of a computer system to a reference time +source. + +II. Problem Description + +The ntpd(8) daemon has a safety feature to prevent excessive stepping of +the clock called the "panic threshold". If ever ntpd(8) determines the +system clock is incorrect by more than this threshold, the daemon exits. +There is an implementation error within the ntpd(8) implementation of this +feature, which allows the system time be adjusted in certain circumstances. + +III. Impact + +When ntpd(8) is started with the '-g' option specified, the system time will +be corrected regardless of if the time offset exceeds the panic threshold (by +default, 1000 seconds). The FreeBSD rc(8) subsystem allows specifying the +'-g' option by either including '-g' in the ntpd_flags list or by enabling +ntpd_sync_on_start in the system rc.conf(5) file. + +If at the moment ntpd(8) is restarted, an attacker can immediately respond to +enough requests from enough sources trusted by the target, which is difficult +and not common, there is a window of opportunity where the attacker can cause +ntpd(8) to set the time to an arbitrary value. + +IV. Workaround + +No workaround is available, but systems not running ntpd(8), or running +ntpd(8) but do not use ntpd_sync_on_start="YES" or specify the '-g' option in +ntpd_flags are not affected. Neither of these are set by default. + +V. Solution + +Perform one of the following: + +1) Upgrade your vulnerable system to a supported FreeBSD stable or +release / security branch (releng) dated after the correction date. + +The ntpd service has to be restarted after the update. A reboot is +recommended but not required. + +2) To update your vulnerable system via a binary patch: + +Systems running a RELEASE version of FreeBSD on the i386 or amd64 +platforms can be updated via the freebsd-update(8) utility: + +# freebsd-update fetch +# freebsd-update install + +The ntpd service has to be restarted after the update. A reboot is +recommended but not required. + +3) To update your vulnerable system via a source code patch: + +The following patches have been verified to apply to the applicable +FreeBSD release branches. + +a) Download the relevant patch from the location below, and verify the +detached PGP signature using your PGP utility. + +[FreeBSD 10.1 and 10.2] +# fetch https://security.FreeBSD.org/patches/SA-16:02/ntp-10.patch +# fetch https://security.FreeBSD.org/patches/SA-16:02/ntp-10.patch.asc +# gpg --verify ntp-10.patch.asc + +[FreeBSD 9.3] +# fetch https://security.FreeBSD.org/patches/SA-16:02/ntp-9.patch +# fetch https://security.FreeBSD.org/patches/SA-16:02/ntp-9.patch.asc +# gpg --verify ntp-9.patch.asc + +b) Apply the patch. Execute the following commands as root: + +# cd /usr/src +# patch < /path/to/patch + +c) Recompile the operating system using buildworld and installworld as +described in . + +Restart the applicable daemons, or reboot the system. + +VI. Correction details + +The following list contains the correction revision numbers for each +affected branch. + +Branch/path Revision +- ------------------------------------------------------------------------- +stable/9/ r293652 +releng/9.3/ r293896 +stable/10/ r293650 +releng/10.1/ r293894 +releng/10.2/ r293893 +- ------------------------------------------------------------------------- + +To see which files were modified by a particular revision, run the +following command, replacing NNNNNN with the revision number, on a +machine with Subversion installed: + +# svn diff -cNNNNNN --summarize svn://svn.freebsd.org/base + +Or visit the following URL, replacing NNNNNN with the revision number: + + + +VII. References + + + + + +The latest revision of this advisory is available at + +-----BEGIN PGP SIGNATURE----- + +iQIcBAEBCgAGBQJWl2j2AAoJEO1n7NZdz2rnyg4QAJ/x3xs+pNGXxTT63hbBqLcB +NTSljW5+hFpL94Nr+rHrelvcT3HkvdWUC+7BvMksoUYCZv0vClp5W7tsfuojDPr0 +GechK1BpLwxeLnRexulWEuvDQpbr6BN9ABdfSl4h3AaUwGYbBVLMY8aT5JpTiE3I +UZg/5iPXVGFPcfdFhzaPgCpZxQtGI3QV7m5jx+Pf8r0ifuTNi8bAbwHCRzmOV8rA +1LM4fvlCPd6TiP3UANWM7PFGbX8UArgzXlb8jSwkxEVC02oZitol4UhcLgacwVrO +0/0q71pyn8W3NBQ1QPUaUg1M81sE501NCTCP3rEg+o6g7oxiq+GpgB0FKwCJxrTk +n3EL7tyhbvVcsglPLRkIXkGz3o5XdelFJ66+qS+mZAiPozkzEFUIdxd8rHKsA1e4 +ZIFARDvDgi8iTArbJnPsQH0CgK8+/2RV2ILFW00Zcu7batvSWJtAUNNFqTSN34tk +JJzHWYwKfGwRIMyEABsy9wLez9K2tRIG0fX75p82dVbRcRZwwSfPmFdfDPuMRRmc +dsNF3133TA92uxwZ177cZk537g+Q0/0I6bts8us3GlCdY2HBuIc+HvRJQyEEqGEv +v1GfEdnwGLp4rmPI8uY+JQ87now7KYhAK1SVil9AXm3tLrIqJsHYayA9nI8mjxfY +Mh1utEeP+TMuievDMQNo +=il8c +-----END PGP SIGNATURE----- diff --git a/share/security/advisories/FreeBSD-SA-16:03.linux.asc b/share/security/advisories/FreeBSD-SA-16:03.linux.asc new file mode 100644 index 0000000000..30873fdb22 --- /dev/null +++ b/share/security/advisories/FreeBSD-SA-16:03.linux.asc @@ -0,0 +1,133 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +============================================================================= +FreeBSD-SA-16:03.linux Security Advisory + The FreeBSD Project + +Topic: Linux compatibility layer incorrect futex handling + +Category: core +Module: kernel +Announced: 2016-01-14 +Credits: Mateusz Guzik +Affects: All supported versions of FreeBSD. +Corrected: 2016-01-14 09:11:42 UTC (stable/10, 10.2-STABLE) + 2016-01-14 09:10:46 UTC (releng/10.2, 10.2-RELEASE-p9) + 2016-01-14 09:11:16 UTC (releng/10.1, 10.1-RELEASE-p26) + 2016-01-14 09:11:48 UTC (stable/9, 9.3-STABLE) + 2016-01-14 09:11:26 UTC (releng/9.3, 9.3-RELEASE-p33) +CVE Name: CVE-2016-1880 + +For general information regarding FreeBSD Security Advisories, +including descriptions of the fields above, security branches, and the +following sections, please visit . + +I. Background + +FreeBSD is binary-compatible with the Linux operating system through a +loadable kernel module/optional kernel component. The support is +provided on amd64 and i386 machines. + +II. Problem Description + +A programming error in the handling of Linux futex robust lists may result +in incorrect memory locations being accessed. + +III. Impact + +It is possible for a local attacker to read portions of kernel memory, which +may result in a privilege escalation. + +IV. Workaround + +No workaround is available, but systems not using the Linux binary +compatibility layer are not vulnerable. + +The following command can be used to test if the Linux binary +compatibility layer is loaded: + +# kldstat -m linuxelf + +V. Solution + +Perform one of the following: + +1) Upgrade your vulnerable system to a supported FreeBSD stable or +release / security branch (releng) dated after the correction date. + +Reboot the system or unload and reload the linux.ko kernel module. + +2) To update your vulnerable system via a binary patch: + +Systems running a RELEASE version of FreeBSD on the i386 or amd64 +platforms can be updated via the freebsd-update(8) utility: + +# freebsd-update fetch +# freebsd-update install + +Reboot the system or unload and reload the linux.ko kernel module. + +2) To update your vulnerable system via a source code patch: + +The following patches have been verified to apply to the applicable +FreeBSD release branches. + +a) Download the relevant patch from the location below, and verify the +detached PGP signature using your PGP utility. + +# fetch http://security.FreeBSD.org/patches/SA-16:03/linux.patch +# fetch http://security.FreeBSD.org/patches/SA-16:03/linux.patch.asc + +b) Apply the patch. + +# cd /usr/src +# patch < /path/to/patch +# cd /usr/src/amd64/linux32 +# make sysent +# cd /usr/src/i386/linux +# make sysent + +c) Recompile your kernel and modules as described in +. + +Reboot the system or unload and reload the linux.ko kernel module. + +VI. Correction details + +The following list contains the revision numbers of each file that was +corrected in FreeBSD. + +Subversion: + +Branch/path Revision +- --------------------------------------------------------------------------- +stable/9/ r293898 +releng/9.3/ r293896 +stable/10/ r293897 +releng/10.1/ r293894 +releng/10.2/ r293893 +- --------------------------------------------------------------------------- + +VII. References + + + +The latest revision of this advisory is available at + +-----BEGIN PGP SIGNATURE----- + +iQIcBAEBCgAGBQJWl2j2AAoJEO1n7NZdz2rngkcQAJ8yxlxYd+qZPf+pbP+0Kj6w ++Sy8BrSUrYLMFynrs4vRPTJobLnVGpwkp6I6ZCDL/yoI/7Xkl3ld7HWfH7MAJ6WP +x0j5/bC+AlWGpKfL6wqeddxjHgmaAlDznN1MyO+3byVfP1Y8VVppbzqPNw9AW17Q +kNqNAMsVuk3OMpoE7CYEsaH6rzHzbMGAPuR+KN5J55Mth6dNkIYSIFJ0sCae5cnv +P6SoMKjn7ffcHymmX/Yj7K0FTOrJOePR0eLbTITivJT1uZ3bYbbYyK1bYslE6bwF +EQ3Ij+LhZdM5D7GBOpILBZ9ojvVMq8PiW9yY3zo7DRrwWajBy8pe/3ow0u7igoOK +/0XUFmRT0Q0iCxlGhXPxEGcc40g6oE6oVz1m3Ewgqc2+iZm+w6N/w88dRqiBHNgL +AiCqleI10eRNgP1uq7XT/5PEslmQLxSCrDPFDOgmSZc3uY7H5LBb6O9fb7YTpn6J +bfL7yyJFei/lAlY1s2b+4/DW9PE1OwxNw/R85mSUpbP5my5wwZR+s3mGTLI2JAlk +74Nw/OR9HLLHoEO5JlagfEclKp7O+JzhHYkAcBm7yRMRr1LV+7JZQEaTCeWTkm6L +YvL8Ca1PAL6qNLZbxQ26Gjka7KCrFhhNfR22c3Lz4pLtkg9YmDRb4sy6i+q3ellG +0mLi0OqTu2gn+25xhidf +=OQft +-----END PGP SIGNATURE----- diff --git a/share/security/advisories/FreeBSD-SA-16:04.linux.asc b/share/security/advisories/FreeBSD-SA-16:04.linux.asc new file mode 100644 index 0000000000..bfd01b913e --- /dev/null +++ b/share/security/advisories/FreeBSD-SA-16:04.linux.asc @@ -0,0 +1,145 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +============================================================================= +FreeBSD-SA-16:04.linux Security Advisory + The FreeBSD Project + +Topic: Linux compatibility layer setgroups(2) system call + vulnerability + +Category: core +Module: kernel +Announced: 2016-01-14 +Credits: Dmitry Chagin +Affects: All supported versions of FreeBSD +Corrected: 2016-01-14 09:11:42 UTC (stable/10, 10.2-STABLE) + 2016-01-14 09:10:46 UTC (releng/10.2, 10.2-RELEASE-p9) + 2016-01-14 09:11:16 UTC (releng/10.1, 10.1-RELEASE-p26) + 2016-01-14 09:11:48 UTC (stable/9, 9.3-STABLE) + 2016-01-14 09:11:26 UTC (releng/9.3, 9.3-RELEASE-p33) +CVE Name: CVE-2016-1881 + +For general information regarding FreeBSD Security Advisories, +including descriptions of the fields above, security branches, and the +following sections, please visit . + +I. Background + +FreeBSD is binary-compatible with the Linux operating system through a +loadable kernel module/optional kernel component. The support is +provided on amd64 and i386 machines. + +II. Problem Description + +A programming error in the Linux compatibility layer setgroups(2) system +call can lead to an unexpected results, such as overwriting random kernel +memory contents. + +III. Impact + +It is possible for a local attacker to overwrite portions of kernel +memory, which may result in a privilege escalation or cause a system +panic. + +IV. Workaround + +No workaround is available, but systems not using the Linux binary +compatibility layer are not vulnerable. + +The following command can be used to test if the Linux binary +compatibility layer is loaded: + +# kldstat -m linuxelf + +V. Solution + +Perform one of the following: + +1) Upgrade your vulnerable system to a supported FreeBSD stable or +release / security branch (releng) dated after the correction date. + +Reboot the system or unload and reload the linux.ko kernel module. + +2) To update your vulnerable system via a binary patch: + +Systems running a RELEASE version of FreeBSD on the i386 or amd64 +platforms can be updated via the freebsd-update(8) utility: + +# freebsd-update fetch +# freebsd-update install + +Reboot the system or unload and reload the linux.ko kernel module. + +3) To update your vulnerable system via a source code patch: + +The following patches have been verified to apply to the applicable +FreeBSD release branches. + +a) Download the relevant patch from the location below, and verify the +detached PGP signature using your PGP utility. + +# fetch https://security.FreeBSD.org/patches/SA-16:04/linux.patch +# fetch https://security.FreeBSD.org/patches/SA-16:04/linux.patch.asc +# gpg --verify linux.patch.asc + +b) Apply the patch. Execute the following commands as root: + +# cd /usr/src +# patch < /path/to/patch +# cd /usr/src/amd64/linux32 +# make sysent +# cd /usr/src/i386/linux +# make sysent + +c) Recompile your kernel as described in +. + +Reboot the system or unload and reload the linux.ko kernel module. + +VI. Correction details + +The following list contains the correction revision numbers for each +affected branch. + +Branch/path Revision +- ------------------------------------------------------------------------- +stable/9/ r293898 +releng/9.3/ r293896 +stable/10/ r293897 +releng/10.1/ r293894 +releng/10.2/ r293893 +- ------------------------------------------------------------------------- + +To see which files were modified by a particular revision, run the +following command, replacing NNNNNN with the revision number, on a +machine with Subversion installed: + +# svn diff -cNNNNNN --summarize svn://svn.freebsd.org/base + +Or visit the following URL, replacing NNNNNN with the revision number: + + + +VII. References + + + +The latest revision of this advisory is available at + +-----BEGIN PGP SIGNATURE----- + +iQIcBAEBCgAGBQJWl2j3AAoJEO1n7NZdz2rnstMP/jddSJehSXe9rlL2qhYfRrQY +XZSuoOtolvcl2xSQCZYprXN95/i890VOdJ9x4+iYJA2IQO55a8MjS1DcJjjonV7J +zJa7Apnu1jaK1jDx+RL6C3eVDff0ss1B7NvZTXmjHn+nIsIRxd6vzxDp2NujTnWS +XHNinNAPcVK9Hy/AJh1W+mClvgLg+lyMICuraMjTDc5ML3+fxUmXfDUWq1mm2Chq +uYXMXcIBXBJx1mnnm9n2izExr7j7AHaVJywe/UYk+KCNbSeags76pt1vuPfoOjdE +BaSlX9KNMouYU0JNfv/wC7/UnuQ/BY1XzxheVpIqmXwlFstAmSiKYIQkpIuypVF1 +yUmf8CjN6AOx9P5CjxX88eeY3F6J1yohch1AI4IMqT3F3fd5LbJ5WqOjritt0J96 +hDjnsiVhw4ozQE6SWTY8TKlokOOEfJC+yhNIJ0cNaHnkLSCUuDDErtGzp1CYoYmt +Q8D1VJ1UEaVPaKcaNAo4+sjiE1uK6svPiWa1+W9VbKGvc3Y7PbcuVIzU0aI4ySgj +VecEFM1O5wr3WXIYnDQNwkWVxbCQdxOIPyW0rqMGQVpu1h7MKk0oMboY1bLcQYFy +Aa9okOl+D7ItpEpRUgnIT06B6krC5sUQuzkUxnVIBPKtcl1OZ4B8KidLjEqu4BSx +3qOQSGqZzr8TFcwPIJv4 +=JKVW +-----END PGP SIGNATURE----- diff --git a/share/security/advisories/FreeBSD-SA-16:05.tcp.asc b/share/security/advisories/FreeBSD-SA-16:05.tcp.asc new file mode 100644 index 0000000000..8035177ba4 --- /dev/null +++ b/share/security/advisories/FreeBSD-SA-16:05.tcp.asc @@ -0,0 +1,129 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +============================================================================= +FreeBSD-SA-16:05.tcp Security Advisory + The FreeBSD Project + +Topic: TCP MD5 signature denial of service + +Category: core +Module: kernel +Announced: 2016-01-14 +Credits: Ryan Stone, + Jonathan T. Looney +Affects: All supported versions of FreeBSD. +Corrected: 2016-01-14 09:11:42 UTC (stable/10, 10.2-STABLE) + 2016-01-14 09:10:46 UTC (releng/10.2, 10.2-RELEASE-p9) + 2016-01-14 09:11:16 UTC (releng/10.1, 10.1-RELEASE-p26) + 2016-01-14 09:11:48 UTC (stable/9, 9.3-STABLE) + 2016-01-14 09:11:26 UTC (releng/9.3, 9.3-RELEASE-p33) +CVE Name: CVE-2016-1882 + +For general information regarding FreeBSD Security Advisories, +including descriptions of the fields above, security branches, and the +following sections, please visit . + +I. Background + +The Transmission Control Protocol (TCP) of the TCP/IP protocol suite +provides a connection-oriented, reliable, sequence-preserving data +stream service. An optional extension to TCP described in RFC 2385 allows +protecting data streams against spoofed packets with MD5 signature. + +Support for TCP MD5 signatures is not enabled in default kernel. + +II. Problem Description + +A programming error in processing a TCP connection with both TCP_MD5SIG +and TCP_NOOPT socket options may lead to kernel crash. + +III. Impact + +A local attacker can crash the kernel, resulting in a denial-of-service. + +A remote attack is theoretically possible, if server has a listening +socket with TCP_NOOPT set, and server is either out of SYN cache entries, +or SYN cache is disabled by configuration. + +IV. Workaround + +No workaround is available, but installations running a default kernel, +or a custom kernel without TCP_SIGNATURE option are not vulnerable. + +V. Solution + +Perform one of the following: + +1) Upgrade your vulnerable system to a supported FreeBSD stable or +release / security branch (releng) dated after the correction date. + +System reboot is required. + +2) To update your vulnerable system via a source code patch: + +The following patches have been verified to apply to the applicable +FreeBSD release branches. + +a) Download the relevant patch from the location below, and verify the +detached PGP signature using your PGP utility. + +# fetch https://security.FreeBSD.org/patches/SA-16:05/tcp.patch +# fetch https://security.FreeBSD.org/patches/SA-16:05/tcp.patch.asc +# gpg --verify tcp.patch.asc + +b) Apply the patch. Execute the following commands as root: + +# cd /usr/src +# patch < /path/to/patch + +c) Recompile your kernel as described in + and reboot the +system. + +VI. Correction details + +The following list contains the correction revision numbers for each +affected branch. + +Branch/path Revision +- ------------------------------------------------------------------------- +stable/9/ r293898 +releng/9.3/ r293896 +stable/10/ r293897 +releng/10.1/ r293894 +releng/10.2/ r293893 +- ------------------------------------------------------------------------- + +To see which files were modified by a particular revision, run the +following command, replacing NNNNNN with the revision number, on a +machine with Subversion installed: + +# svn diff -cNNNNNN --summarize svn://svn.freebsd.org/base + +Or visit the following URL, replacing NNNNNN with the revision number: + + + +VII. References + + + +The latest revision of this advisory is available at + +-----BEGIN PGP SIGNATURE----- + +iQIcBAEBCgAGBQJWl2j3AAoJEO1n7NZdz2rnrWcQAN+QX6wEvC7FkTXyX2LHFWas +CVOI/KkxkHSVwYMMScmorG27OxDsHTkvrGfqyVbYDczmC5NY+AorMiZMoo7CHn5J +gYmS8NZvBPeMKmFt45lBTBDnKT6mOvHBz6UPhyyHruvR6VZ2h3fyLqYzbMKcy12i +Onmk/nm3vgrqOCmnqYQN8Xo2v2x4KcKU3/jegK+pdfOwd9Q1bmxzBWwFx8yc7pZ0 +3YItalkiMsuRppSuNS9fGoRSoB/Ybf/8pu6SDnhvJnw4CIRGAl3IDKpBanB7F/9E +sofcI499s+uyOHPY8TrQ62L4UjteEukwaV8EJh6vPaLm3pns0cSURzKczgytTH3G +Nz9GcI3hYdfbXRBgJvwtZv9JY5s3ZtPiqqTwHta7AdplXwiOJJ1Ylso5lZ4beiJh +q7Sv+YMJr9cNfnYmSGv33rKN4hdae7XfJm+Ipde4bpgCLFpKkb/aQaGxGlowjDaW +0C77qCg+se3TzwGl0A7ClEq4dLaadTsiShQCpZGQOgc6Wgz9QUBGxU811e3KQHLo +3XQgxGSB9+3d7YiK/ZNkzi8d89VXMgUOx4HoOZ7+SkVBg1+qpbiYnk8VJjLmXyOz +dPtDbzWG68wluWcSc7TD5yIYx2Lw4E9ZMWzh2boOxEWrcd9mxCUPiU9nsF+PIAPG +kTcLnX0+iXijpKMnQpgP +=UjjC +-----END PGP SIGNATURE----- diff --git a/share/security/advisories/FreeBSD-SA-16:06.bsnmpd.asc b/share/security/advisories/FreeBSD-SA-16:06.bsnmpd.asc new file mode 100644 index 0000000000..fd9b6d8dc7 --- /dev/null +++ b/share/security/advisories/FreeBSD-SA-16:06.bsnmpd.asc @@ -0,0 +1,142 @@ +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA512 + +============================================================================= +FreeBSD-SA-16:06.bsnmpd Security Advisory + The FreeBSD Project + +Topic: Insecure default bsnmpd.conf permissions + +Category: contrib +Module: bsnmpd +Announced: 2016-01-14 +Credits: Pierre Kim +Affects: All supported versions of FreeBSD. +Corrected: 2016-01-14 09:11:42 UTC (stable/10, 10.2-STABLE) + 2016-01-14 09:10:46 UTC (releng/10.2, 10.2-RELEASE-p9) + 2016-01-14 09:11:16 UTC (releng/10.1, 10.1-RELEASE-p26) + 2016-01-14 09:11:48 UTC (stable/9, 9.3-STABLE) + 2016-01-14 09:11:26 UTC (releng/9.3, 9.3-RELEASE-p33) +CVE Name: CVE-2015-5677 + +For general information regarding FreeBSD Security Advisories, +including descriptions of the fields above, security branches, and the +following sections, please visit . + +I. Background + +The bsnmpd daemon serves the Internet SNMP (Simple Network Management +Protocol). It is intended to serve only the absolute basic MIBs and +implements all other MIBs through loadable modules. + +II. Problem Description + +The SNMP protocol supports an authentication model called USM, which relies +on a shared secret. The default permission of the bsnmpd configuration file, +/etc/bsnmpd.conf, is weak and does not provide adequate protection against +local unprivileged users. + +III. Impact + +A local user may be able to read the shared secret, if configured and used +by the system administrator. + +IV. Workaround + +No workaround is available, but systems that do not use bsnmpd with its USM +authentication model are not vulnerable. + +V. Solution + +This vulnerability can be fixed by modifying the permission on +/etc/bsnmpd.conf to owner root:wheel and permission 0600. + +The patch is provided mainly for third party vendors who deploy FreeBSD +and provide a safe default. The patch itself DOES NOT fix the permissions +for existing installations. + +The patch can be applied by performing one of the following: + +1) Upgrade your vulnerable system to a supported FreeBSD stable or +release / security branch (releng) dated after the correction date. + +The system administrator should change the permission on /etc/bsnmpd.conf +to root:wheel and 0600. + +2) To update your vulnerable system via a binary patch: + +Systems running a RELEASE version of FreeBSD on the i386 or amd64 +platforms can be updated via the freebsd-update(8) utility: + +# freebsd-update fetch +# freebsd-update install + +The system administrator should change the permission on /etc/bsnmpd.conf +to root:wheel and 0600. + +3) To update your vulnerable system via a source code patch: + +The following patches have been verified to apply to the applicable +FreeBSD release branches. + +a) Download the relevant patch from the location below, and verify the +detached PGP signature using your PGP utility. + +# fetch https://security.FreeBSD.org/patches/SA-16:06/bsnmpd.patch +# fetch https://security.FreeBSD.org/patches/SA-16:06/bsnmpd.patch.asc +# gpg --verify bsnmpd.patch.asc + +b) Apply the patch. Execute the following commands as root: + +# cd /usr/src +# patch < /path/to/patch + +c) Recompile the operating system using buildworld and installworld as +described in . + +VI. Correction details + +The following list contains the correction revision numbers for each +affected branch. + +Branch/path Revision +- ------------------------------------------------------------------------- +stable/9/ r293898 +releng/9.3/ r293896 +stable/10/ r293897 +releng/10.1/ r293894 +releng/10.2/ r293893 +- ------------------------------------------------------------------------- + +To see which files were modified by a particular revision, run the +following command, replacing NNNNNN with the revision number, on a +machine with Subversion installed: + +# svn diff -cNNNNNN --summarize svn://svn.freebsd.org/base + +Or visit the following URL, replacing NNNNNN with the revision number: + + + +VII. References + + + +The latest revision of this advisory is available at + +-----BEGIN PGP SIGNATURE----- + +iQIcBAEBCgAGBQJWl2j4AAoJEO1n7NZdz2rnkaQP/3K9kqYY1YoHQ++uzFPnfuZQ +mkGPJ0frGG46pTL806QJidky6D0LP0zNCzhtU45ZlFMguJ3B3QYp/62Cw61dBG22 +x0uEkvI2F2F39IPA/clspyUHg3Y1RYgTpJrxey0JLrK0yxelyI8vMwB4tCB2eEDW +ZGVU6rvFQcWJOWHABXVYcc+4Yy5ucudp0QbJsVHAKLtF7MLuntVlUj+x4Nncog5k +kmGt6W7tzFn2gNsWcmntmG/LWyPkPURWhYfIj3fgcRrpMTVIDFX5PTgQyJR7DwOM +/beIoQxxKBUwTW1ZRgvcCqFBu7DKSCMABoHgpqLj1gdeiJ1LaO4dErtWXvdBEAAP ++XLi5OkRG3OKzIAIRnkz/SrkAUoRkzHEK1dI0coyw7AdXXjDBWtX+n9lzRXs7hqT +LC3riK/Km9OYVn3+T7tCWnvKN45f+FnD8zxZDE+33Jv9wI8X+CCs9GjJdoJ0HDSd +b6rg8E4gGPzfwFxSNXZQKfDSSuVBECIp3av1gp6hN3qZNOX/sadMsxro8VVGFLPg +81rC+JfKNTeVtxF8oJi9eg3FQ/eupxQv4RvC2c37R7LcErAU1KKxZyNrwv6xDEMx +QVnx74o+luxXSirLxq276pfBQJdMjxYzWCj6E8ztcAZenz3M4WNiRFlt7hdq/3YO +bDBdQPe4eYSHHSGyGcz/ +=LDPU +-----END PGP SIGNATURE----- diff --git a/share/security/patches/EN-16:01/filemon.patch b/share/security/patches/EN-16:01/filemon.patch new file mode 100644 index 0000000000..f73de625fb --- /dev/null +++ b/share/security/patches/EN-16:01/filemon.patch @@ -0,0 +1,625 @@ +--- sys/dev/filemon/filemon.c.orig ++++ sys/dev/filemon/filemon.c +@@ -1,6 +1,7 @@ + /*- + * Copyright (c) 2011, David E. O'Brien. + * Copyright (c) 2009-2011, Juniper Networks, Inc. ++ * Copyright (c) 2015, EMC Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without +@@ -39,6 +40,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -45,6 +47,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -85,12 +88,8 @@ + + struct filemon { + TAILQ_ENTRY(filemon) link; /* Link into the in-use list. */ +- struct mtx mtx; /* Lock mutex for this filemon. */ +- struct cv cv; /* Lock condition variable for this +- filemon. */ ++ struct sx lock; /* Lock mutex for this filemon. */ + struct file *fp; /* Output file pointer. */ +- struct thread *locker; /* Ptr to the thread locking this +- filemon. */ + pid_t pid; /* The process ID being monitored. */ + char fname1[MAXPATHLEN]; /* Temporary filename buffer. */ + char fname2[MAXPATHLEN]; /* Temporary filename buffer. */ +@@ -99,11 +98,7 @@ + + static TAILQ_HEAD(, filemon) filemons_inuse = TAILQ_HEAD_INITIALIZER(filemons_inuse); + static TAILQ_HEAD(, filemon) filemons_free = TAILQ_HEAD_INITIALIZER(filemons_free); +-static int n_readers = 0; +-static struct mtx access_mtx; +-static struct cv access_cv; +-static struct thread *access_owner = NULL; +-static struct thread *access_requester = NULL; ++static struct sx access_lock; + + static struct cdev *filemon_dev; + +@@ -203,8 +198,7 @@ + + filemon->fp = NULL; + +- mtx_init(&filemon->mtx, "filemon", "filemon", MTX_DEF); +- cv_init(&filemon->cv, "filemon"); ++ sx_init(&filemon->lock, "filemon"); + } + + filemon->pid = curproc->p_pid; +@@ -234,8 +228,7 @@ + static void + filemon_load(void *dummy __unused) + { +- mtx_init(&access_mtx, "filemon", "filemon", MTX_DEF); +- cv_init(&access_cv, "filemon"); ++ sx_init(&access_lock, "filemons_inuse"); + + /* Install the syscall wrappers. */ + filemon_wrapper_install(); +@@ -270,14 +263,12 @@ + filemon_lock_write(); + while ((filemon = TAILQ_FIRST(&filemons_free)) != NULL) { + TAILQ_REMOVE(&filemons_free, filemon, link); +- mtx_destroy(&filemon->mtx); +- cv_destroy(&filemon->cv); ++ sx_destroy(&filemon->lock); + free(filemon, M_FILEMON); + } + filemon_unlock_write(); + +- mtx_destroy(&access_mtx); +- cv_destroy(&access_cv); ++ sx_destroy(&access_lock); + } + + return (error); +--- sys/dev/filemon/filemon_lock.c.orig ++++ sys/dev/filemon/filemon_lock.c +@@ -1,5 +1,6 @@ + /*- + * Copyright (c) 2009-2011, Juniper Networks, Inc. ++ * Copyright (c) 2015, EMC Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without +@@ -27,96 +28,44 @@ + #include + __FBSDID("$FreeBSD$"); + +-static void ++static __inline void + filemon_filemon_lock(struct filemon *filemon) + { +- mtx_lock(&filemon->mtx); + +- while (filemon->locker != NULL && filemon->locker != curthread) +- cv_wait(&filemon->cv, &filemon->mtx); +- +- filemon->locker = curthread; +- +- mtx_unlock(&filemon->mtx); ++ sx_xlock(&filemon->lock); + } + +-static void ++static __inline void + filemon_filemon_unlock(struct filemon *filemon) + { +- mtx_lock(&filemon->mtx); + +- if (filemon->locker == curthread) +- filemon->locker = NULL; +- +- /* Wake up threads waiting. */ +- cv_broadcast(&filemon->cv); +- +- mtx_unlock(&filemon->mtx); ++ sx_xunlock(&filemon->lock); + } + +-static void ++static __inline void + filemon_lock_read(void) + { +- mtx_lock(&access_mtx); + +- while (access_owner != NULL || access_requester != NULL) +- cv_wait(&access_cv, &access_mtx); +- +- n_readers++; +- +- /* Wake up threads waiting. */ +- cv_broadcast(&access_cv); +- +- mtx_unlock(&access_mtx); ++ sx_slock(&access_lock); + } + +-static void ++static __inline void + filemon_unlock_read(void) + { +- mtx_lock(&access_mtx); + +- if (n_readers > 0) +- n_readers--; +- +- /* Wake up a thread waiting. */ +- cv_broadcast(&access_cv); +- +- mtx_unlock(&access_mtx); ++ sx_sunlock(&access_lock); + } + +-static void ++static __inline void + filemon_lock_write(void) + { +- mtx_lock(&access_mtx); + +- while (access_owner != curthread) { +- if (access_owner == NULL && +- (access_requester == NULL || +- access_requester == curthread)) { +- access_owner = curthread; +- access_requester = NULL; +- } else { +- if (access_requester == NULL) +- access_requester = curthread; +- +- cv_wait(&access_cv, &access_mtx); +- } +- } +- +- mtx_unlock(&access_mtx); ++ sx_xlock(&access_lock); + } + +-static void ++static __inline void + filemon_unlock_write(void) + { +- mtx_lock(&access_mtx); + +- /* Sanity check that the current thread actually has the write lock. */ +- if (access_owner == curthread) +- access_owner = NULL; +- +- /* Wake up a thread waiting. */ +- cv_broadcast(&access_cv); +- +- mtx_unlock(&access_mtx); ++ sx_xunlock(&access_lock); + } +--- sys/dev/filemon/filemon_wrapper.c.orig ++++ sys/dev/filemon/filemon_wrapper.c +@@ -1,6 +1,7 @@ + /*- + * Copyright (c) 2011, David E. O'Brien. + * Copyright (c) 2009-2011, Juniper Networks, Inc. ++ * Copyright (c) 2015, EMC Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without +@@ -86,11 +87,18 @@ + { + struct filemon *filemon; + ++ filemon_lock_read(); ++ if (TAILQ_EMPTY(&filemons_inuse)) { ++ filemon_unlock_read(); ++ return (NULL); ++ } + sx_slock(&proctree_lock); + while (p != initproc) { + TAILQ_FOREACH(filemon, &filemons_inuse, link) { + if (p->p_pid == filemon->pid) { + sx_sunlock(&proctree_lock); ++ filemon_filemon_lock(filemon); ++ filemon_unlock_read(); + return (filemon); + } + } +@@ -97,6 +105,7 @@ + p = proc_realparent(p); + } + sx_sunlock(&proctree_lock); ++ filemon_unlock_read(); + return (NULL); + } + +@@ -109,9 +118,6 @@ + /* Load timestamp before locking. Less accurate but less contention. */ + getmicrotime(&now); + +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + /* Lock the found filemon structure. */ + filemon_filemon_lock(filemon); + +@@ -124,9 +130,6 @@ + + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + static int +@@ -138,13 +141,7 @@ + struct filemon *filemon; + + if ((ret = sys_chdir(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + copyinstr(uap->path, filemon->fname1, + sizeof(filemon->fname1), &done); + +@@ -157,9 +154,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -177,13 +171,7 @@ + copyinstr(uap->fname, fname, sizeof(fname), &done); + + if ((ret = sys_execve(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + len = snprintf(filemon->msgbufr, + sizeof(filemon->msgbufr), "E %d %s\n", + curproc->p_pid, fname); +@@ -193,9 +181,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -215,13 +200,7 @@ + copyinstr(uap->fname, fname, sizeof(fname), &done); + + if ((ret = freebsd32_execve(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + len = snprintf(filemon->msgbufr, + sizeof(filemon->msgbufr), "E %d %s\n", + curproc->p_pid, fname); +@@ -231,9 +210,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -248,13 +224,7 @@ + struct filemon *filemon; + + if ((ret = sys_fork(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + len = snprintf(filemon->msgbufr, + sizeof(filemon->msgbufr), "F %d %ld\n", + curproc->p_pid, (long)curthread->td_retval[0]); +@@ -264,9 +234,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -281,13 +248,7 @@ + struct filemon *filemon; + + if ((ret = sys_open(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + copyinstr(uap->path, filemon->fname1, + sizeof(filemon->fname1), &done); + +@@ -313,9 +274,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -330,13 +288,7 @@ + struct filemon *filemon; + + if ((ret = sys_openat(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + copyinstr(uap->path, filemon->fname1, + sizeof(filemon->fname1), &done); + +@@ -375,9 +327,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -392,13 +341,7 @@ + struct filemon *filemon; + + if ((ret = sys_rename(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + copyinstr(uap->from, filemon->fname1, + sizeof(filemon->fname1), &done); + copyinstr(uap->to, filemon->fname2, +@@ -413,9 +356,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -430,13 +370,7 @@ + struct filemon *filemon; + + if ((ret = sys_link(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + copyinstr(uap->path, filemon->fname1, + sizeof(filemon->fname1), &done); + copyinstr(uap->link, filemon->fname2, +@@ -451,9 +385,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -468,13 +399,7 @@ + struct filemon *filemon; + + if ((ret = sys_symlink(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + copyinstr(uap->path, filemon->fname1, + sizeof(filemon->fname1), &done); + copyinstr(uap->link, filemon->fname2, +@@ -489,9 +414,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -507,13 +429,7 @@ + struct filemon *filemon; + + if ((ret = sys_linkat(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + copyinstr(uap->path1, filemon->fname1, + sizeof(filemon->fname1), &done); + copyinstr(uap->path2, filemon->fname2, +@@ -528,9 +444,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -546,13 +459,7 @@ + struct filemon *filemon; + + if ((ret = sys_stat(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + copyinstr(uap->path, filemon->fname1, + sizeof(filemon->fname1), &done); + +@@ -565,9 +472,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -584,13 +488,7 @@ + struct filemon *filemon; + + if ((ret = freebsd32_stat(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + copyinstr(uap->path, filemon->fname1, + sizeof(filemon->fname1), &done); + +@@ -603,9 +501,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -622,13 +517,7 @@ + /* Get timestamp before locking. */ + getmicrotime(&now); + +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + len = snprintf(filemon->msgbufr, sizeof(filemon->msgbufr), + "X %d %d\n", curproc->p_pid, uap->rval); + +@@ -649,9 +538,6 @@ + filemon_filemon_unlock(filemon); + } + +- /* Release the read lock. */ +- filemon_unlock_read(); +- + sys_sys_exit(td, uap); + } + +@@ -664,13 +550,7 @@ + struct filemon *filemon; + + if ((ret = sys_unlink(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + copyinstr(uap->path, filemon->fname1, + sizeof(filemon->fname1), &done); + +@@ -683,9 +563,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); +@@ -699,13 +576,7 @@ + struct filemon *filemon; + + if ((ret = sys_vfork(td, uap)) == 0) { +- /* Grab a read lock on the filemon inuse list. */ +- filemon_lock_read(); +- + if ((filemon = filemon_pid_check(curproc)) != NULL) { +- /* Lock the found filemon structure. */ +- filemon_filemon_lock(filemon); +- + len = snprintf(filemon->msgbufr, + sizeof(filemon->msgbufr), "F %d %ld\n", + curproc->p_pid, (long)curthread->td_retval[0]); +@@ -715,9 +586,6 @@ + /* Unlock the found filemon structure. */ + filemon_filemon_unlock(filemon); + } +- +- /* Release the read lock. */ +- filemon_unlock_read(); + } + + return (ret); diff --git a/share/security/patches/EN-16:01/filemon.patch.asc b/share/security/patches/EN-16:01/filemon.patch.asc new file mode 100644 index 0000000000..f16e99d943 --- /dev/null +++ b/share/security/patches/EN-16:01/filemon.patch.asc @@ -0,0 +1,16 @@ +-----BEGIN PGP SIGNATURE----- + +iQIcBAABCgAGBQJWl2vPAAoJEO1n7NZdz2rnKwUQAKVHEkB285VYYoYqJKoy8Pr6 +SG71lY59IZ1YRuFoSQq8RkizrskBDNhSqEXdDgjdMOIqSdaJqXaIHMwtKAv+/I1Y +oRgUtIyLZYhuEUgsbjInNpd7Wk7Y2TQYjb1ZsI3hrNwFLxt5jzrYZCs0Ouk0RkB3 +nR++SMIrBtI5Ak48I8q0KZFPnIralqTmASo8m7QYvqI3Jmq6L06F5LHQ8t/oXVlB +Dubf/SndnZnHtGV2a1qg9uuYvoqEaaH7kY6ZheRrhP5s1AduEWZB4fTiB0Yz9dtv ++hYEO+cP2ynkSispljvtDDC717tOZeWhCisl/D1R+ohlKHiwtQRSLObeKHue27Fx +Ku8c6BvpR311c9WazHIMT9CguvU3WEWnUgm1j+CyRb6KXgCuRaRIDl5vOwvFvGNW +83imL3UY7Z0khlPZKicWWPqhC/Mn0MR5mKza0nyeTTRpWh4ynTZn6fWyU4RO99ic +Zv1bRB6OS5LrL4uFConTXk+n5qo2hILGZfnFODlUZ8QasC/BB6SC+1R0a6kx9dOs +1XYyoZBnjKgn8P/yEqpjOa/KMTDp90jkocjP35HkJBoKftewR2eAtceY4lbw1/Tl +07YYbBmoKjNH4qTH5Rp76m9Dd+vDVpyHQ+Ov5Wm9h8/WUDP3p6aahGh1s5qPYBN3 +AZ3ZmnOKIHgNp1vtWbDq +=j+SB +-----END PGP SIGNATURE----- diff --git a/share/security/patches/EN-16:02/pf-10.1.patch b/share/security/patches/EN-16:02/pf-10.1.patch new file mode 100644 index 0000000000..8d4136b405 --- /dev/null +++ b/share/security/patches/EN-16:02/pf-10.1.patch @@ -0,0 +1,392 @@ +--- sys/net/pfvar.h.orig ++++ sys/net/pfvar.h +@@ -1558,6 +1558,8 @@ + extern void pf_print_flags(u_int8_t); + extern u_int16_t pf_cksum_fixup(u_int16_t, u_int16_t, u_int16_t, + u_int8_t); ++extern u_int16_t pf_proto_cksum_fixup(struct mbuf *, u_int16_t, ++ u_int16_t, u_int16_t, u_int8_t); + + VNET_DECLARE(struct ifnet *, sync_ifp); + #define V_sync_ifp VNET(sync_ifp); +@@ -1582,6 +1584,9 @@ + void *pf_pull_hdr(struct mbuf *, int, void *, int, u_short *, u_short *, + sa_family_t); + void pf_change_a(void *, u_int16_t *, u_int32_t, u_int8_t); ++void pf_change_proto_a(struct mbuf *, void *, u_int16_t *, u_int32_t, ++ u_int8_t); ++void pf_change_tcp_a(struct mbuf *, void *, u_int16_t *, u_int32_t); + void pf_send_deferred_syn(struct pf_state *); + int pf_match_addr(u_int8_t, struct pf_addr *, struct pf_addr *, + struct pf_addr *, sa_family_t); +--- sys/netinet6/ip6_output.c.orig ++++ sys/netinet6/ip6_output.c +@@ -184,7 +184,7 @@ + }\ + } while (/*CONSTCOND*/ 0) + +-static void ++void + in6_delayed_cksum(struct mbuf *m, uint32_t plen, u_short offset) + { + u_short csum; +--- sys/netinet6/ip6_var.h.orig ++++ sys/netinet6/ip6_var.h +@@ -456,6 +456,7 @@ + struct rtentry **, u_int); + u_int32_t ip6_randomid(void); + u_int32_t ip6_randomflowlabel(void); ++void in6_delayed_cksum(struct mbuf *m, uint32_t plen, u_short offset); + #endif /* _KERNEL */ + + #endif /* !_NETINET6_IP6_VAR_H_ */ +--- sys/netpfil/pf/pf.c.orig ++++ sys/netpfil/pf/pf.c +@@ -203,7 +203,7 @@ + static void pf_add_threshold(struct pf_threshold *); + static int pf_check_threshold(struct pf_threshold *); + +-static void pf_change_ap(struct pf_addr *, u_int16_t *, ++static void pf_change_ap(struct mbuf *, struct pf_addr *, u_int16_t *, + u_int16_t *, u_int16_t *, struct pf_addr *, + u_int16_t, u_int8_t, sa_family_t); + static int pf_modulate_sack(struct mbuf *, int, struct pf_pdesc *, +@@ -1966,6 +1966,22 @@ + } + } + ++/** ++ * Checksum updates are a little complicated because the checksum in the TCP/UDP ++ * header isn't always a full checksum. In some cases (i.e. output) it's a ++ * pseudo-header checksum, which is a partial checksum over src/dst IP ++ * addresses, protocol number and length. ++ * ++ * That means we have the following cases: ++ * * Input or forwarding: we don't have TSO, the checksum fields are full ++ * checksums, we need to update the checksum whenever we change anything. ++ * * Output (i.e. the checksum is a pseudo-header checksum): ++ * x The field being updated is src/dst address or affects the length of ++ * the packet. We need to update the pseudo-header checksum (note that this ++ * checksum is not ones' complement). ++ * x Some other field is being modified (e.g. src/dst port numbers): We ++ * don't have to update anything. ++ **/ + u_int16_t + pf_cksum_fixup(u_int16_t cksum, u_int16_t old, u_int16_t new, u_int8_t udp) + { +@@ -1981,9 +1997,20 @@ + return (l); + } + ++u_int16_t ++pf_proto_cksum_fixup(struct mbuf *m, u_int16_t cksum, u_int16_t old, ++ u_int16_t new, u_int8_t udp) ++{ ++ if (m->m_pkthdr.csum_flags & (CSUM_DELAY_DATA | CSUM_DELAY_DATA_IPV6)) ++ return (cksum); ++ ++ return (pf_cksum_fixup(cksum, old, new, udp)); ++} ++ + static void +-pf_change_ap(struct pf_addr *a, u_int16_t *p, u_int16_t *ic, u_int16_t *pc, +- struct pf_addr *an, u_int16_t pn, u_int8_t u, sa_family_t af) ++pf_change_ap(struct mbuf *m, struct pf_addr *a, u_int16_t *p, u_int16_t *ic, ++ u_int16_t *pc, struct pf_addr *an, u_int16_t pn, u_int8_t u, ++ sa_family_t af) + { + struct pf_addr ao; + u_int16_t po = *p; +@@ -1991,6 +2018,9 @@ + PF_ACPY(&ao, a, af); + PF_ACPY(a, an, af); + ++ if (m->m_pkthdr.csum_flags & (CSUM_DELAY_DATA | CSUM_DELAY_DATA_IPV6)) ++ *pc = ~*pc; ++ + *p = pn; + + switch (af) { +@@ -2000,10 +2030,12 @@ + ao.addr16[0], an->addr16[0], 0), + ao.addr16[1], an->addr16[1], 0); + *p = pn; +- *pc = pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup(*pc, ++ ++ *pc = pf_cksum_fixup(pf_cksum_fixup(*pc, + ao.addr16[0], an->addr16[0], u), +- ao.addr16[1], an->addr16[1], u), +- po, pn, u); ++ ao.addr16[1], an->addr16[1], u); ++ ++ *pc = pf_proto_cksum_fixup(m, *pc, po, pn, u); + break; + #endif /* INET */ + #ifdef INET6 +@@ -2010,7 +2042,7 @@ + case AF_INET6: + *pc = pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup( + pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup( +- pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup(*pc, ++ pf_cksum_fixup(pf_cksum_fixup(*pc, + ao.addr16[0], an->addr16[0], u), + ao.addr16[1], an->addr16[1], u), + ao.addr16[2], an->addr16[2], u), +@@ -2018,14 +2050,21 @@ + ao.addr16[4], an->addr16[4], u), + ao.addr16[5], an->addr16[5], u), + ao.addr16[6], an->addr16[6], u), +- ao.addr16[7], an->addr16[7], u), +- po, pn, u); ++ ao.addr16[7], an->addr16[7], u); ++ ++ *pc = pf_proto_cksum_fixup(m, *pc, po, pn, u); + break; + #endif /* INET6 */ + } ++ ++ if (m->m_pkthdr.csum_flags & (CSUM_DELAY_DATA | ++ CSUM_DELAY_DATA_IPV6)) { ++ *pc = ~*pc; ++ if (! *pc) ++ *pc = 0xffff; ++ } + } + +- + /* Changes a u_int32_t. Uses a void * so there are no align restrictions */ + void + pf_change_a(void *a, u_int16_t *c, u_int32_t an, u_int8_t u) +@@ -2038,6 +2077,19 @@ + ao % 65536, an % 65536, u); + } + ++void ++pf_change_proto_a(struct mbuf *m, void *a, u_int16_t *c, u_int32_t an, u_int8_t udp) ++{ ++ u_int32_t ao; ++ ++ memcpy(&ao, a, sizeof(ao)); ++ memcpy(a, &an, sizeof(u_int32_t)); ++ ++ *c = pf_proto_cksum_fixup(m, ++ pf_proto_cksum_fixup(m, *c, ao / 65536, an / 65536, udp), ++ ao % 65536, an % 65536, udp); ++} ++ + #ifdef INET6 + static void + pf_change_a6(struct pf_addr *a, u_int16_t *c, struct pf_addr *an, u_int8_t u) +@@ -2183,12 +2235,10 @@ + for (i = 2; i + TCPOLEN_SACK <= olen; + i += TCPOLEN_SACK) { + memcpy(&sack, &opt[i], sizeof(sack)); +- pf_change_a(&sack.start, &th->th_sum, +- htonl(ntohl(sack.start) - +- dst->seqdiff), 0); +- pf_change_a(&sack.end, &th->th_sum, +- htonl(ntohl(sack.end) - +- dst->seqdiff), 0); ++ pf_change_proto_a(m, &sack.start, &th->th_sum, ++ htonl(ntohl(sack.start) - dst->seqdiff), 0); ++ pf_change_proto_a(m, &sack.end, &th->th_sum, ++ htonl(ntohl(sack.end) - dst->seqdiff), 0); + memcpy(&opt[i], &sack, sizeof(sack)); + } + copyback = 1; +@@ -3092,7 +3142,7 @@ + + if (PF_ANEQ(saddr, &nk->addr[pd->sidx], af) || + nk->port[pd->sidx] != sport) { +- pf_change_ap(saddr, &th->th_sport, pd->ip_sum, ++ pf_change_ap(m, saddr, &th->th_sport, pd->ip_sum, + &th->th_sum, &nk->addr[pd->sidx], + nk->port[pd->sidx], 0, af); + pd->sport = &th->th_sport; +@@ -3101,7 +3151,7 @@ + + if (PF_ANEQ(daddr, &nk->addr[pd->didx], af) || + nk->port[pd->didx] != dport) { +- pf_change_ap(daddr, &th->th_dport, pd->ip_sum, ++ pf_change_ap(m, daddr, &th->th_dport, pd->ip_sum, + &th->th_sum, &nk->addr[pd->didx], + nk->port[pd->didx], 0, af); + dport = th->th_dport; +@@ -3115,7 +3165,7 @@ + + if (PF_ANEQ(saddr, &nk->addr[pd->sidx], af) || + nk->port[pd->sidx] != sport) { +- pf_change_ap(saddr, &pd->hdr.udp->uh_sport, ++ pf_change_ap(m, saddr, &pd->hdr.udp->uh_sport, + pd->ip_sum, &pd->hdr.udp->uh_sum, + &nk->addr[pd->sidx], + nk->port[pd->sidx], 1, af); +@@ -3125,7 +3175,7 @@ + + if (PF_ANEQ(daddr, &nk->addr[pd->didx], af) || + nk->port[pd->didx] != dport) { +- pf_change_ap(daddr, &pd->hdr.udp->uh_dport, ++ pf_change_ap(m, daddr, &pd->hdr.udp->uh_dport, + pd->ip_sum, &pd->hdr.udp->uh_sum, + &nk->addr[pd->didx], + nk->port[pd->didx], 1, af); +@@ -3477,7 +3527,7 @@ + if ((s->src.seqdiff = pf_tcp_iss(pd) - s->src.seqlo) == + 0) + s->src.seqdiff = 1; +- pf_change_a(&th->th_seq, &th->th_sum, ++ pf_change_proto_a(m, &th->th_seq, &th->th_sum, + htonl(s->src.seqlo + s->src.seqdiff), 0); + *rewrite = 1; + } else +@@ -3786,9 +3836,9 @@ + while ((src->seqdiff = arc4random() - seq) == 0) + ; + ack = ntohl(th->th_ack) - dst->seqdiff; +- pf_change_a(&th->th_seq, &th->th_sum, htonl(seq + ++ pf_change_proto_a(m, &th->th_seq, &th->th_sum, htonl(seq + + src->seqdiff), 0); +- pf_change_a(&th->th_ack, &th->th_sum, htonl(ack), 0); ++ pf_change_proto_a(m, &th->th_ack, &th->th_sum, htonl(ack), 0); + *copyback = 1; + } else { + ack = ntohl(th->th_ack); +@@ -3838,9 +3888,9 @@ + ack = ntohl(th->th_ack) - dst->seqdiff; + if (src->seqdiff) { + /* Modulate sequence numbers */ +- pf_change_a(&th->th_seq, &th->th_sum, htonl(seq + ++ pf_change_proto_a(m, &th->th_seq, &th->th_sum, htonl(seq + + src->seqdiff), 0); +- pf_change_a(&th->th_ack, &th->th_sum, htonl(ack), 0); ++ pf_change_proto_a(m, &th->th_ack, &th->th_sum, htonl(ack), 0); + *copyback = 1; + } + end = seq + pd->p_len; +@@ -4294,14 +4344,14 @@ + + if (PF_ANEQ(pd->src, &nk->addr[pd->sidx], pd->af) || + nk->port[pd->sidx] != th->th_sport) +- pf_change_ap(pd->src, &th->th_sport, pd->ip_sum, +- &th->th_sum, &nk->addr[pd->sidx], ++ pf_change_ap(m, pd->src, &th->th_sport, ++ pd->ip_sum, &th->th_sum, &nk->addr[pd->sidx], + nk->port[pd->sidx], 0, pd->af); + + if (PF_ANEQ(pd->dst, &nk->addr[pd->didx], pd->af) || + nk->port[pd->didx] != th->th_dport) +- pf_change_ap(pd->dst, &th->th_dport, pd->ip_sum, +- &th->th_sum, &nk->addr[pd->didx], ++ pf_change_ap(m, pd->dst, &th->th_dport, ++ pd->ip_sum, &th->th_sum, &nk->addr[pd->didx], + nk->port[pd->didx], 0, pd->af); + copyback = 1; + } +@@ -4365,13 +4415,13 @@ + + if (PF_ANEQ(pd->src, &nk->addr[pd->sidx], pd->af) || + nk->port[pd->sidx] != uh->uh_sport) +- pf_change_ap(pd->src, &uh->uh_sport, pd->ip_sum, ++ pf_change_ap(m, pd->src, &uh->uh_sport, pd->ip_sum, + &uh->uh_sum, &nk->addr[pd->sidx], + nk->port[pd->sidx], 1, pd->af); + + if (PF_ANEQ(pd->dst, &nk->addr[pd->didx], pd->af) || + nk->port[pd->didx] != uh->uh_dport) +- pf_change_ap(pd->dst, &uh->uh_dport, pd->ip_sum, ++ pf_change_ap(m, pd->dst, &uh->uh_dport, pd->ip_sum, + &uh->uh_sum, &nk->addr[pd->didx], + nk->port[pd->didx], 1, pd->af); + m_copyback(m, off, sizeof(*uh), (caddr_t)uh); +@@ -5487,6 +5537,13 @@ + if (ifp->if_flags & IFF_LOOPBACK) + m0->m_flags |= M_SKIP_FIREWALL; + ++ if (m0->m_pkthdr.csum_flags & CSUM_DELAY_DATA_IPV6 & ++ ~ifp->if_hwassist) { ++ uint32_t plen = m0->m_pkthdr.len - sizeof(*ip6); ++ in6_delayed_cksum(m0, plen, sizeof(struct ip6_hdr)); ++ m0->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA_IPV6; ++ } ++ + /* + * If the packet is too large for the outgoing interface, + * send back an icmp6 error. +--- sys/netpfil/pf/pf_ioctl.c.orig ++++ sys/netpfil/pf/pf_ioctl.c +@@ -3571,12 +3571,6 @@ + { + int chk; + +- /* We need a proper CSUM befor we start (s. OpenBSD ip_output) */ +- if ((*m)->m_pkthdr.csum_flags & CSUM_DELAY_DATA) { +- in_delayed_cksum(*m); +- (*m)->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA; +- } +- + chk = pf_test(PF_OUT, ifp, m, inp); + if (chk && *m) { + m_freem(*m); +@@ -3615,14 +3609,6 @@ + { + int chk; + +- /* We need a proper CSUM before we start (s. OpenBSD ip_output) */ +- if ((*m)->m_pkthdr.csum_flags & CSUM_DELAY_DATA) { +-#ifdef INET +- /* XXX-BZ copy&paste error from r126261? */ +- in_delayed_cksum(*m); +-#endif +- (*m)->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA; +- } + CURVNET_SET(ifp->if_vnet); + chk = pf_test6(PF_OUT, ifp, m, inp); + CURVNET_RESTORE(); +--- sys/netpfil/pf/pf_norm.c.orig ++++ sys/netpfil/pf/pf_norm.c +@@ -1374,13 +1374,14 @@ + th->th_x2 = 0; + nv = *(u_int16_t *)(&th->th_ack + 1); + +- th->th_sum = pf_cksum_fixup(th->th_sum, ov, nv, 0); ++ th->th_sum = pf_proto_cksum_fixup(m, th->th_sum, ov, nv, 0); + rewrite = 1; + } + + /* Remove urgent pointer, if TH_URG is not set */ + if (!(flags & TH_URG) && th->th_urp) { +- th->th_sum = pf_cksum_fixup(th->th_sum, th->th_urp, 0, 0); ++ th->th_sum = pf_proto_cksum_fixup(m, th->th_sum, th->th_urp, ++ 0, 0); + th->th_urp = 0; + rewrite = 1; + } +@@ -1581,7 +1582,7 @@ + (src->scrub->pfss_flags & + PFSS_TIMESTAMP)) { + tsval = ntohl(tsval); +- pf_change_a(&opt[2], ++ pf_change_proto_a(m, &opt[2], + &th->th_sum, + htonl(tsval + + src->scrub->pfss_ts_mod), +@@ -1597,7 +1598,7 @@ + PFSS_TIMESTAMP)) { + tsecr = ntohl(tsecr) + - dst->scrub->pfss_ts_mod; +- pf_change_a(&opt[6], ++ pf_change_proto_a(m, &opt[6], + &th->th_sum, htonl(tsecr), + 0); + copyback = 1; +@@ -1924,8 +1925,8 @@ + case TCPOPT_MAXSEG: + mss = (u_int16_t *)(optp + 2); + if ((ntohs(*mss)) > r->max_mss) { +- th->th_sum = pf_cksum_fixup(th->th_sum, +- *mss, htons(r->max_mss), 0); ++ th->th_sum = pf_proto_cksum_fixup(m, ++ th->th_sum, *mss, htons(r->max_mss), 0); + *mss = htons(r->max_mss); + rewrite = 1; + } diff --git a/share/security/patches/EN-16:02/pf-10.1.patch.asc b/share/security/patches/EN-16:02/pf-10.1.patch.asc new file mode 100644 index 0000000000..17964e3713 --- /dev/null +++ b/share/security/patches/EN-16:02/pf-10.1.patch.asc @@ -0,0 +1,16 @@ +-----BEGIN PGP SIGNATURE----- + +iQIcBAABCgAGBQJWl2vRAAoJEO1n7NZdz2rneQkP/A5c7Q56gNdajrwxyWwV4jmN +cNtmgLfs9dp2IpyBHkh+kAr+TCiI9ymX7XjxfHr2VZsrzEOiOObj8eRUivORybo2 +Qq7I1ALXUxL2RLzJHRDunWc7h7JC5uAikrv8DCKZ5h3Hu2e5s07fHZqYXbPJyMcb +xzfB6GNXpCSutDnJgHOZqgCefokb5O+J2ER8Zk4Q4Q0ILs1MO6aiseDEoFapFTBk +2rxf1dEzwYxRTpDkqbnVNQb3JNg9YemnlX265kOYUf10sG969EB+W3cOfuP/mRZS +5ff+S7si+5sHFn/0TVc4yN3iEqjxUlYX5IlzRENQEXztxoqLQDuuQ4nF92703loH +5Ay6kp+fci2UiIaK5PNnEWtvNpvgeuK9kY5H40P+qEMPv5nCrGtKzumKy6tlPuIo +ppSc3QCTWjvIbs2MYbonDooCo4z7WQ7P2OJT0kUbHYwaez0gullOt8nv9GgNvLIX +hbox02nWvHV/x9pCtBpFW8qxKVmrNvvYkujhr5G8sf/xmNtUNK8xv2vpKRmatJWC +jzUmJl+UZC6fy60ThaosZO7uZlsC6POtSzQVA4DcIATB/LMNRhf4Z4q8qut0ur64 +YQnKDch1mepEmr/+mTkLf8nk/8kQMHpmij6Dv9xN+dCA5rPozjCervjjiKjRDD4G +gRBpo4VOn2B/ApFDzCP8 +=wyiX +-----END PGP SIGNATURE----- diff --git a/share/security/patches/EN-16:02/pf-10.2.patch b/share/security/patches/EN-16:02/pf-10.2.patch new file mode 100644 index 0000000000..881326dffb --- /dev/null +++ b/share/security/patches/EN-16:02/pf-10.2.patch @@ -0,0 +1,368 @@ +--- sys/net/pfvar.h.orig ++++ sys/net/pfvar.h +@@ -1554,6 +1554,8 @@ + extern void pf_print_flags(u_int8_t); + extern u_int16_t pf_cksum_fixup(u_int16_t, u_int16_t, u_int16_t, + u_int8_t); ++extern u_int16_t pf_proto_cksum_fixup(struct mbuf *, u_int16_t, ++ u_int16_t, u_int16_t, u_int8_t); + + VNET_DECLARE(struct ifnet *, sync_ifp); + #define V_sync_ifp VNET(sync_ifp); +@@ -1583,6 +1585,9 @@ + void *pf_pull_hdr(struct mbuf *, int, void *, int, u_short *, u_short *, + sa_family_t); + void pf_change_a(void *, u_int16_t *, u_int32_t, u_int8_t); ++void pf_change_proto_a(struct mbuf *, void *, u_int16_t *, u_int32_t, ++ u_int8_t); ++void pf_change_tcp_a(struct mbuf *, void *, u_int16_t *, u_int32_t); + void pf_send_deferred_syn(struct pf_state *); + int pf_match_addr(u_int8_t, struct pf_addr *, struct pf_addr *, + struct pf_addr *, sa_family_t); +--- sys/netpfil/pf/pf.c.orig ++++ sys/netpfil/pf/pf.c +@@ -203,7 +203,7 @@ + static void pf_add_threshold(struct pf_threshold *); + static int pf_check_threshold(struct pf_threshold *); + +-static void pf_change_ap(struct pf_addr *, u_int16_t *, ++static void pf_change_ap(struct mbuf *, struct pf_addr *, u_int16_t *, + u_int16_t *, u_int16_t *, struct pf_addr *, + u_int16_t, u_int8_t, sa_family_t); + static int pf_modulate_sack(struct mbuf *, int, struct pf_pdesc *, +@@ -1989,6 +1989,22 @@ + } + } + ++/** ++ * Checksum updates are a little complicated because the checksum in the TCP/UDP ++ * header isn't always a full checksum. In some cases (i.e. output) it's a ++ * pseudo-header checksum, which is a partial checksum over src/dst IP ++ * addresses, protocol number and length. ++ * ++ * That means we have the following cases: ++ * * Input or forwarding: we don't have TSO, the checksum fields are full ++ * checksums, we need to update the checksum whenever we change anything. ++ * * Output (i.e. the checksum is a pseudo-header checksum): ++ * x The field being updated is src/dst address or affects the length of ++ * the packet. We need to update the pseudo-header checksum (note that this ++ * checksum is not ones' complement). ++ * x Some other field is being modified (e.g. src/dst port numbers): We ++ * don't have to update anything. ++ **/ + u_int16_t + pf_cksum_fixup(u_int16_t cksum, u_int16_t old, u_int16_t new, u_int8_t udp) + { +@@ -2004,9 +2020,20 @@ + return (l); + } + ++u_int16_t ++pf_proto_cksum_fixup(struct mbuf *m, u_int16_t cksum, u_int16_t old, ++ u_int16_t new, u_int8_t udp) ++{ ++ if (m->m_pkthdr.csum_flags & (CSUM_DELAY_DATA | CSUM_DELAY_DATA_IPV6)) ++ return (cksum); ++ ++ return (pf_cksum_fixup(cksum, old, new, udp)); ++} ++ + static void +-pf_change_ap(struct pf_addr *a, u_int16_t *p, u_int16_t *ic, u_int16_t *pc, +- struct pf_addr *an, u_int16_t pn, u_int8_t u, sa_family_t af) ++pf_change_ap(struct mbuf *m, struct pf_addr *a, u_int16_t *p, u_int16_t *ic, ++ u_int16_t *pc, struct pf_addr *an, u_int16_t pn, u_int8_t u, ++ sa_family_t af) + { + struct pf_addr ao; + u_int16_t po = *p; +@@ -2014,6 +2041,9 @@ + PF_ACPY(&ao, a, af); + PF_ACPY(a, an, af); + ++ if (m->m_pkthdr.csum_flags & (CSUM_DELAY_DATA | CSUM_DELAY_DATA_IPV6)) ++ *pc = ~*pc; ++ + *p = pn; + + switch (af) { +@@ -2023,17 +2053,19 @@ + ao.addr16[0], an->addr16[0], 0), + ao.addr16[1], an->addr16[1], 0); + *p = pn; +- *pc = pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup(*pc, ++ ++ *pc = pf_cksum_fixup(pf_cksum_fixup(*pc, + ao.addr16[0], an->addr16[0], u), +- ao.addr16[1], an->addr16[1], u), +- po, pn, u); ++ ao.addr16[1], an->addr16[1], u); ++ ++ *pc = pf_proto_cksum_fixup(m, *pc, po, pn, u); + break; + #endif /* INET */ + #ifdef INET6 + case AF_INET6: + *pc = pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup( + pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup( +- pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup(*pc, ++ pf_cksum_fixup(pf_cksum_fixup(*pc, + ao.addr16[0], an->addr16[0], u), + ao.addr16[1], an->addr16[1], u), + ao.addr16[2], an->addr16[2], u), +@@ -2041,13 +2073,20 @@ + ao.addr16[4], an->addr16[4], u), + ao.addr16[5], an->addr16[5], u), + ao.addr16[6], an->addr16[6], u), +- ao.addr16[7], an->addr16[7], u), +- po, pn, u); ++ ao.addr16[7], an->addr16[7], u); ++ ++ *pc = pf_proto_cksum_fixup(m, *pc, po, pn, u); + break; + #endif /* INET6 */ + } +-} + ++ if (m->m_pkthdr.csum_flags & (CSUM_DELAY_DATA | ++ CSUM_DELAY_DATA_IPV6)) { ++ *pc = ~*pc; ++ if (! *pc) ++ *pc = 0xffff; ++ } ++} + + /* Changes a u_int32_t. Uses a void * so there are no align restrictions */ + void +@@ -2061,6 +2100,19 @@ + ao % 65536, an % 65536, u); + } + ++void ++pf_change_proto_a(struct mbuf *m, void *a, u_int16_t *c, u_int32_t an, u_int8_t udp) ++{ ++ u_int32_t ao; ++ ++ memcpy(&ao, a, sizeof(ao)); ++ memcpy(a, &an, sizeof(u_int32_t)); ++ ++ *c = pf_proto_cksum_fixup(m, ++ pf_proto_cksum_fixup(m, *c, ao / 65536, an / 65536, udp), ++ ao % 65536, an % 65536, udp); ++} ++ + #ifdef INET6 + static void + pf_change_a6(struct pf_addr *a, u_int16_t *c, struct pf_addr *an, u_int8_t u) +@@ -2206,12 +2258,10 @@ + for (i = 2; i + TCPOLEN_SACK <= olen; + i += TCPOLEN_SACK) { + memcpy(&sack, &opt[i], sizeof(sack)); +- pf_change_a(&sack.start, &th->th_sum, +- htonl(ntohl(sack.start) - +- dst->seqdiff), 0); +- pf_change_a(&sack.end, &th->th_sum, +- htonl(ntohl(sack.end) - +- dst->seqdiff), 0); ++ pf_change_proto_a(m, &sack.start, &th->th_sum, ++ htonl(ntohl(sack.start) - dst->seqdiff), 0); ++ pf_change_proto_a(m, &sack.end, &th->th_sum, ++ htonl(ntohl(sack.end) - dst->seqdiff), 0); + memcpy(&opt[i], &sack, sizeof(sack)); + } + copyback = 1; +@@ -3115,7 +3165,7 @@ + + if (PF_ANEQ(saddr, &nk->addr[pd->sidx], af) || + nk->port[pd->sidx] != sport) { +- pf_change_ap(saddr, &th->th_sport, pd->ip_sum, ++ pf_change_ap(m, saddr, &th->th_sport, pd->ip_sum, + &th->th_sum, &nk->addr[pd->sidx], + nk->port[pd->sidx], 0, af); + pd->sport = &th->th_sport; +@@ -3124,7 +3174,7 @@ + + if (PF_ANEQ(daddr, &nk->addr[pd->didx], af) || + nk->port[pd->didx] != dport) { +- pf_change_ap(daddr, &th->th_dport, pd->ip_sum, ++ pf_change_ap(m, daddr, &th->th_dport, pd->ip_sum, + &th->th_sum, &nk->addr[pd->didx], + nk->port[pd->didx], 0, af); + dport = th->th_dport; +@@ -3138,7 +3188,7 @@ + + if (PF_ANEQ(saddr, &nk->addr[pd->sidx], af) || + nk->port[pd->sidx] != sport) { +- pf_change_ap(saddr, &pd->hdr.udp->uh_sport, ++ pf_change_ap(m, saddr, &pd->hdr.udp->uh_sport, + pd->ip_sum, &pd->hdr.udp->uh_sum, + &nk->addr[pd->sidx], + nk->port[pd->sidx], 1, af); +@@ -3148,7 +3198,7 @@ + + if (PF_ANEQ(daddr, &nk->addr[pd->didx], af) || + nk->port[pd->didx] != dport) { +- pf_change_ap(daddr, &pd->hdr.udp->uh_dport, ++ pf_change_ap(m, daddr, &pd->hdr.udp->uh_dport, + pd->ip_sum, &pd->hdr.udp->uh_sum, + &nk->addr[pd->didx], + nk->port[pd->didx], 1, af); +@@ -3500,7 +3550,7 @@ + if ((s->src.seqdiff = pf_tcp_iss(pd) - s->src.seqlo) == + 0) + s->src.seqdiff = 1; +- pf_change_a(&th->th_seq, &th->th_sum, ++ pf_change_proto_a(m, &th->th_seq, &th->th_sum, + htonl(s->src.seqlo + s->src.seqdiff), 0); + *rewrite = 1; + } else +@@ -3824,9 +3874,9 @@ + while ((src->seqdiff = arc4random() - seq) == 0) + ; + ack = ntohl(th->th_ack) - dst->seqdiff; +- pf_change_a(&th->th_seq, &th->th_sum, htonl(seq + ++ pf_change_proto_a(m, &th->th_seq, &th->th_sum, htonl(seq + + src->seqdiff), 0); +- pf_change_a(&th->th_ack, &th->th_sum, htonl(ack), 0); ++ pf_change_proto_a(m, &th->th_ack, &th->th_sum, htonl(ack), 0); + *copyback = 1; + } else { + ack = ntohl(th->th_ack); +@@ -3876,9 +3926,9 @@ + ack = ntohl(th->th_ack) - dst->seqdiff; + if (src->seqdiff) { + /* Modulate sequence numbers */ +- pf_change_a(&th->th_seq, &th->th_sum, htonl(seq + ++ pf_change_proto_a(m, &th->th_seq, &th->th_sum, htonl(seq + + src->seqdiff), 0); +- pf_change_a(&th->th_ack, &th->th_sum, htonl(ack), 0); ++ pf_change_proto_a(m, &th->th_ack, &th->th_sum, htonl(ack), 0); + *copyback = 1; + } + end = seq + pd->p_len; +@@ -4332,14 +4382,14 @@ + + if (PF_ANEQ(pd->src, &nk->addr[pd->sidx], pd->af) || + nk->port[pd->sidx] != th->th_sport) +- pf_change_ap(pd->src, &th->th_sport, pd->ip_sum, +- &th->th_sum, &nk->addr[pd->sidx], ++ pf_change_ap(m, pd->src, &th->th_sport, ++ pd->ip_sum, &th->th_sum, &nk->addr[pd->sidx], + nk->port[pd->sidx], 0, pd->af); + + if (PF_ANEQ(pd->dst, &nk->addr[pd->didx], pd->af) || + nk->port[pd->didx] != th->th_dport) +- pf_change_ap(pd->dst, &th->th_dport, pd->ip_sum, +- &th->th_sum, &nk->addr[pd->didx], ++ pf_change_ap(m, pd->dst, &th->th_dport, ++ pd->ip_sum, &th->th_sum, &nk->addr[pd->didx], + nk->port[pd->didx], 0, pd->af); + copyback = 1; + } +@@ -4403,13 +4453,13 @@ + + if (PF_ANEQ(pd->src, &nk->addr[pd->sidx], pd->af) || + nk->port[pd->sidx] != uh->uh_sport) +- pf_change_ap(pd->src, &uh->uh_sport, pd->ip_sum, ++ pf_change_ap(m, pd->src, &uh->uh_sport, pd->ip_sum, + &uh->uh_sum, &nk->addr[pd->sidx], + nk->port[pd->sidx], 1, pd->af); + + if (PF_ANEQ(pd->dst, &nk->addr[pd->didx], pd->af) || + nk->port[pd->didx] != uh->uh_dport) +- pf_change_ap(pd->dst, &uh->uh_dport, pd->ip_sum, ++ pf_change_ap(m, pd->dst, &uh->uh_dport, pd->ip_sum, + &uh->uh_sum, &nk->addr[pd->didx], + nk->port[pd->didx], 1, pd->af); + m_copyback(m, off, sizeof(*uh), (caddr_t)uh); +@@ -5526,6 +5576,13 @@ + if (ifp->if_flags & IFF_LOOPBACK) + m0->m_flags |= M_SKIP_FIREWALL; + ++ if (m0->m_pkthdr.csum_flags & CSUM_DELAY_DATA_IPV6 & ++ ~ifp->if_hwassist) { ++ uint32_t plen = m0->m_pkthdr.len - sizeof(*ip6); ++ in6_delayed_cksum(m0, plen, sizeof(struct ip6_hdr)); ++ m0->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA_IPV6; ++ } ++ + /* + * If the packet is too large for the outgoing interface, + * send back an icmp6 error. +--- sys/netpfil/pf/pf_ioctl.c.orig ++++ sys/netpfil/pf/pf_ioctl.c +@@ -3561,12 +3561,6 @@ + { + int chk; + +- /* We need a proper CSUM befor we start (s. OpenBSD ip_output) */ +- if ((*m)->m_pkthdr.csum_flags & CSUM_DELAY_DATA) { +- in_delayed_cksum(*m); +- (*m)->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA; +- } +- + chk = pf_test(PF_OUT, ifp, m, inp); + if (chk && *m) { + m_freem(*m); +@@ -3605,13 +3599,6 @@ + { + int chk; + +- /* We need a proper CSUM before we start (s. OpenBSD ip_output) */ +- if ((*m)->m_pkthdr.csum_flags & CSUM_DELAY_DATA_IPV6) { +- in6_delayed_cksum(*m, +- (*m)->m_pkthdr.len - sizeof(struct ip6_hdr), +- sizeof(struct ip6_hdr)); +- (*m)->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA_IPV6; +- } + CURVNET_SET(ifp->if_vnet); + chk = pf_test6(PF_OUT, ifp, m, inp); + CURVNET_RESTORE(); +--- sys/netpfil/pf/pf_norm.c.orig ++++ sys/netpfil/pf/pf_norm.c +@@ -1680,13 +1680,14 @@ + th->th_x2 = 0; + nv = *(u_int16_t *)(&th->th_ack + 1); + +- th->th_sum = pf_cksum_fixup(th->th_sum, ov, nv, 0); ++ th->th_sum = pf_proto_cksum_fixup(m, th->th_sum, ov, nv, 0); + rewrite = 1; + } + + /* Remove urgent pointer, if TH_URG is not set */ + if (!(flags & TH_URG) && th->th_urp) { +- th->th_sum = pf_cksum_fixup(th->th_sum, th->th_urp, 0, 0); ++ th->th_sum = pf_proto_cksum_fixup(m, th->th_sum, th->th_urp, ++ 0, 0); + th->th_urp = 0; + rewrite = 1; + } +@@ -1887,7 +1888,7 @@ + (src->scrub->pfss_flags & + PFSS_TIMESTAMP)) { + tsval = ntohl(tsval); +- pf_change_a(&opt[2], ++ pf_change_proto_a(m, &opt[2], + &th->th_sum, + htonl(tsval + + src->scrub->pfss_ts_mod), +@@ -1903,7 +1904,7 @@ + PFSS_TIMESTAMP)) { + tsecr = ntohl(tsecr) + - dst->scrub->pfss_ts_mod; +- pf_change_a(&opt[6], ++ pf_change_proto_a(m, &opt[6], + &th->th_sum, htonl(tsecr), + 0); + copyback = 1; +@@ -2230,8 +2231,8 @@ + case TCPOPT_MAXSEG: + mss = (u_int16_t *)(optp + 2); + if ((ntohs(*mss)) > r->max_mss) { +- th->th_sum = pf_cksum_fixup(th->th_sum, +- *mss, htons(r->max_mss), 0); ++ th->th_sum = pf_proto_cksum_fixup(m, ++ th->th_sum, *mss, htons(r->max_mss), 0); + *mss = htons(r->max_mss); + rewrite = 1; + } diff --git a/share/security/patches/EN-16:02/pf-10.2.patch.asc b/share/security/patches/EN-16:02/pf-10.2.patch.asc new file mode 100644 index 0000000000..604f9757d5 --- /dev/null +++ b/share/security/patches/EN-16:02/pf-10.2.patch.asc @@ -0,0 +1,16 @@ +-----BEGIN PGP SIGNATURE----- + +iQIcBAABCgAGBQJWl2vVAAoJEO1n7NZdz2rnwAsP/jRzi56f90G3nCAJx18gorHB +unXB4gMVkQvFoEYrhn9N96HhvFPdvEm0/YwAJqWpiRH3OO9RtAjGIJUc1vpBzCIk +XROAzwV4EevwcqhfVpZlQ/SxrU1+TXAL/sLSgnaSapCaTadUGDbetDpCi6ZeWzb3 +Kn8xeYZcIGDxQgiDBvzq3xcpxoQNc5VzpTwfE5P3yrfjFEPhW13J+6+PZuQEr3Hd +44vqFI+me0g498CSuokctqidGTCqsd0ak6y6t1r1wRkBnZJ12kc1TQT0FCkTB38I +THgdpglmr2ZNN7RRw0L30N28XPUipoVfzIjv8c7bWFY6j7SzjIWdGQVbnzOdNUyg +YbR68yVA4uZ0/vpTHLlme3s90NdUufS7DVL7ner7hFjAuSMJU11UyLYRcZhMCsMs +V3Zssu49J7as/f5qvRCJOrR2DBQwX8XnvuMLBRf2GdseHhrNn8RSRIsMGgOu96XN +NriyyoV7XcM30Tn1OlLdPNlrIYi/OB8STstdWRnSDhimdkf/t7IGYKUdhNAadCQI +X0tsNalFP0ChbrKpooJ0wVExeS6mF+cWJqvS78y1we/3rQYBPDKA1vMptt7shHI7 +Cy1uZezwh5Pge2CeRgkyBvdplmZIbwNi3pah8JwE9cdlipEvf9qEydY8pooQIpZe +sk42yCvQAjd69q7VWdhx +=b/JC +-----END PGP SIGNATURE----- diff --git a/share/security/patches/EN-16:02/pf-9.patch b/share/security/patches/EN-16:02/pf-9.patch new file mode 100644 index 0000000000..c9a347aadf --- /dev/null +++ b/share/security/patches/EN-16:02/pf-9.patch @@ -0,0 +1,389 @@ +--- sys/contrib/pf/net/pf.c.orig ++++ sys/contrib/pf/net/pf.c +@@ -239,7 +239,7 @@ + void pf_add_threshold(struct pf_threshold *); + int pf_check_threshold(struct pf_threshold *); + +-void pf_change_ap(struct pf_addr *, u_int16_t *, ++void pf_change_ap(struct mbuf *, struct pf_addr *, u_int16_t *, + u_int16_t *, u_int16_t *, struct pf_addr *, + u_int16_t, u_int8_t, sa_family_t); + int pf_modulate_sack(struct mbuf *, int, struct pf_pdesc *, +@@ -2007,6 +2007,22 @@ + } + } + ++/** ++ * Checksum updates are a little complicated because the checksum in the TCP/UDP ++ * header isn't always a full checksum. In some cases (i.e. output) it's a ++ * pseudo-header checksum, which is a partial checksum over src/dst IP ++ * addresses, protocol number and length. ++ * ++ * That means we have the following cases: ++ * * Input or forwarding: we don't have TSO, the checksum fields are full ++ * checksums, we need to update the checksum whenever we change anything. ++ * * Output (i.e. the checksum is a pseudo-header checksum): ++ * x The field being updated is src/dst address or affects the length of ++ * the packet. We need to update the pseudo-header checksum (note that this ++ * checksum is not ones' complement). ++ * x Some other field is being modified (e.g. src/dst port numbers): We ++ * don't have to update anything. ++ **/ + u_int16_t + pf_cksum_fixup(u_int16_t cksum, u_int16_t old, u_int16_t new, u_int8_t udp) + { +@@ -2022,9 +2038,20 @@ + return (l); + } + ++u_int16_t ++pf_proto_cksum_fixup(struct mbuf *m, u_int16_t cksum, u_int16_t old, ++ u_int16_t new, u_int8_t udp) ++{ ++ if (m->m_pkthdr.csum_flags & (CSUM_DELAY_DATA | CSUM_DELAY_DATA_IPV6)) ++ return (cksum); ++ ++ return (pf_cksum_fixup(cksum, old, new, udp)); ++} ++ + void +-pf_change_ap(struct pf_addr *a, u_int16_t *p, u_int16_t *ic, u_int16_t *pc, +- struct pf_addr *an, u_int16_t pn, u_int8_t u, sa_family_t af) ++pf_change_ap(struct mbuf *m, struct pf_addr *a, u_int16_t *p, u_int16_t *ic, ++ u_int16_t *pc, struct pf_addr *an, u_int16_t pn, u_int8_t u, ++ sa_family_t af) + { + struct pf_addr ao; + u_int16_t po = *p; +@@ -2032,6 +2059,9 @@ + PF_ACPY(&ao, a, af); + PF_ACPY(a, an, af); + ++ if (m->m_pkthdr.csum_flags & (CSUM_DELAY_DATA | CSUM_DELAY_DATA_IPV6)) ++ *pc = ~*pc; ++ + *p = pn; + + switch (af) { +@@ -2041,17 +2071,19 @@ + ao.addr16[0], an->addr16[0], 0), + ao.addr16[1], an->addr16[1], 0); + *p = pn; +- *pc = pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup(*pc, ++ ++ *pc = pf_cksum_fixup(pf_cksum_fixup(*pc, + ao.addr16[0], an->addr16[0], u), +- ao.addr16[1], an->addr16[1], u), +- po, pn, u); ++ ao.addr16[1], an->addr16[1], u); ++ ++ *pc = pf_proto_cksum_fixup(m, *pc, po, pn, u); + break; + #endif /* INET */ + #ifdef INET6 + case AF_INET6: + *pc = pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup( + pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup( +- pf_cksum_fixup(pf_cksum_fixup(pf_cksum_fixup(*pc, ++ pf_cksum_fixup(pf_cksum_fixup(*pc, + ao.addr16[0], an->addr16[0], u), + ao.addr16[1], an->addr16[1], u), + ao.addr16[2], an->addr16[2], u), +@@ -2059,13 +2091,20 @@ + ao.addr16[4], an->addr16[4], u), + ao.addr16[5], an->addr16[5], u), + ao.addr16[6], an->addr16[6], u), +- ao.addr16[7], an->addr16[7], u), +- po, pn, u); ++ ao.addr16[7], an->addr16[7], u); ++ ++ *pc = pf_proto_cksum_fixup(m, *pc, po, pn, u); + break; + #endif /* INET6 */ + } +-} + ++ if (m->m_pkthdr.csum_flags & (CSUM_DELAY_DATA | ++ CSUM_DELAY_DATA_IPV6)) { ++ *pc = ~*pc; ++ if (! *pc) ++ *pc = 0xffff; ++ } ++} + + /* Changes a u_int32_t. Uses a void * so there are no align restrictions */ + void +@@ -2079,6 +2118,19 @@ + ao % 65536, an % 65536, u); + } + ++void ++pf_change_proto_a(struct mbuf *m, void *a, u_int16_t *c, u_int32_t an, u_int8_t udp) ++{ ++ u_int32_t ao; ++ ++ memcpy(&ao, a, sizeof(ao)); ++ memcpy(a, &an, sizeof(u_int32_t)); ++ ++ *c = pf_proto_cksum_fixup(m, ++ pf_proto_cksum_fixup(m, *c, ao / 65536, an / 65536, udp), ++ ao % 65536, an % 65536, udp); ++} ++ + #ifdef INET6 + void + pf_change_a6(struct pf_addr *a, u_int16_t *c, struct pf_addr *an, u_int8_t u) +@@ -2228,12 +2280,10 @@ + for (i = 2; i + TCPOLEN_SACK <= olen; + i += TCPOLEN_SACK) { + memcpy(&sack, &opt[i], sizeof(sack)); +- pf_change_a(&sack.start, &th->th_sum, +- htonl(ntohl(sack.start) - +- dst->seqdiff), 0); +- pf_change_a(&sack.end, &th->th_sum, +- htonl(ntohl(sack.end) - +- dst->seqdiff), 0); ++ pf_change_proto_a(m, &sack.start, &th->th_sum, ++ htonl(ntohl(sack.start) - dst->seqdiff), 0); ++ pf_change_proto_a(m, &sack.end, &th->th_sum, ++ htonl(ntohl(sack.end) - dst->seqdiff), 0); + memcpy(&opt[i], &sack, sizeof(sack)); + } + copyback = 1; +@@ -3400,7 +3450,7 @@ + + if (PF_ANEQ(saddr, &nk->addr[pd->sidx], af) || + nk->port[pd->sidx] != sport) { +- pf_change_ap(saddr, &th->th_sport, pd->ip_sum, ++ pf_change_ap(m, saddr, &th->th_sport, pd->ip_sum, + &th->th_sum, &nk->addr[pd->sidx], + nk->port[pd->sidx], 0, af); + pd->sport = &th->th_sport; +@@ -3409,7 +3459,7 @@ + + if (PF_ANEQ(daddr, &nk->addr[pd->didx], af) || + nk->port[pd->didx] != dport) { +- pf_change_ap(daddr, &th->th_dport, pd->ip_sum, ++ pf_change_ap(m, daddr, &th->th_dport, pd->ip_sum, + &th->th_sum, &nk->addr[pd->didx], + nk->port[pd->didx], 0, af); + dport = th->th_dport; +@@ -3423,7 +3473,7 @@ + + if (PF_ANEQ(saddr, &nk->addr[pd->sidx], af) || + nk->port[pd->sidx] != sport) { +- pf_change_ap(saddr, &pd->hdr.udp->uh_sport, ++ pf_change_ap(m, saddr, &pd->hdr.udp->uh_sport, + pd->ip_sum, &pd->hdr.udp->uh_sum, + &nk->addr[pd->sidx], + nk->port[pd->sidx], 1, af); +@@ -3433,7 +3483,7 @@ + + if (PF_ANEQ(daddr, &nk->addr[pd->didx], af) || + nk->port[pd->didx] != dport) { +- pf_change_ap(daddr, &pd->hdr.udp->uh_dport, ++ pf_change_ap(m, daddr, &pd->hdr.udp->uh_dport, + pd->ip_sum, &pd->hdr.udp->uh_sum, + &nk->addr[pd->didx], + nk->port[pd->didx], 1, af); +@@ -3845,7 +3895,7 @@ + if ((s->src.seqdiff = pf_tcp_iss(pd) - s->src.seqlo) == + 0) + s->src.seqdiff = 1; +- pf_change_a(&th->th_seq, &th->th_sum, ++ pf_change_proto_a(m, &th->th_seq, &th->th_sum, + htonl(s->src.seqlo + s->src.seqdiff), 0); + *rewrite = 1; + } else +@@ -4175,9 +4225,9 @@ + while ((src->seqdiff = arc4random() - seq) == 0) + ; + ack = ntohl(th->th_ack) - dst->seqdiff; +- pf_change_a(&th->th_seq, &th->th_sum, htonl(seq + ++ pf_change_proto_a(m, &th->th_seq, &th->th_sum, htonl(seq + + src->seqdiff), 0); +- pf_change_a(&th->th_ack, &th->th_sum, htonl(ack), 0); ++ pf_change_proto_a(m, &th->th_ack, &th->th_sum, htonl(ack), 0); + *copyback = 1; + } else { + ack = ntohl(th->th_ack); +@@ -4227,9 +4277,9 @@ + ack = ntohl(th->th_ack) - dst->seqdiff; + if (src->seqdiff) { + /* Modulate sequence numbers */ +- pf_change_a(&th->th_seq, &th->th_sum, htonl(seq + ++ pf_change_proto_a(m, &th->th_seq, &th->th_sum, htonl(seq + + src->seqdiff), 0); +- pf_change_a(&th->th_ack, &th->th_sum, htonl(ack), 0); ++ pf_change_proto_a(m, &th->th_ack, &th->th_sum, htonl(ack), 0); + *copyback = 1; + } + end = seq + pd->p_len; +@@ -4729,14 +4779,14 @@ + + if (PF_ANEQ(pd->src, &nk->addr[pd->sidx], pd->af) || + nk->port[pd->sidx] != th->th_sport) +- pf_change_ap(pd->src, &th->th_sport, pd->ip_sum, +- &th->th_sum, &nk->addr[pd->sidx], ++ pf_change_ap(m, pd->src, &th->th_sport, ++ pd->ip_sum, &th->th_sum, &nk->addr[pd->sidx], + nk->port[pd->sidx], 0, pd->af); + + if (PF_ANEQ(pd->dst, &nk->addr[pd->didx], pd->af) || + nk->port[pd->didx] != th->th_dport) +- pf_change_ap(pd->dst, &th->th_dport, pd->ip_sum, +- &th->th_sum, &nk->addr[pd->didx], ++ pf_change_ap(m, pd->dst, &th->th_dport, ++ pd->ip_sum, &th->th_sum, &nk->addr[pd->didx], + nk->port[pd->didx], 0, pd->af); + copyback = 1; + } +@@ -4807,13 +4857,13 @@ + + if (PF_ANEQ(pd->src, &nk->addr[pd->sidx], pd->af) || + nk->port[pd->sidx] != uh->uh_sport) +- pf_change_ap(pd->src, &uh->uh_sport, pd->ip_sum, ++ pf_change_ap(m, pd->src, &uh->uh_sport, pd->ip_sum, + &uh->uh_sum, &nk->addr[pd->sidx], + nk->port[pd->sidx], 1, pd->af); + + if (PF_ANEQ(pd->dst, &nk->addr[pd->didx], pd->af) || + nk->port[pd->didx] != uh->uh_dport) +- pf_change_ap(pd->dst, &uh->uh_dport, pd->ip_sum, ++ pf_change_ap(m, pd->dst, &uh->uh_dport, pd->ip_sum, + &uh->uh_sum, &nk->addr[pd->didx], + nk->port[pd->didx], 1, pd->af); + #ifdef __FreeBSD__ +@@ -6290,6 +6340,13 @@ + ip6 = mtod(m0, struct ip6_hdr *); + } + ++ if (m0->m_pkthdr.csum_flags & CSUM_DELAY_DATA_IPV6 & ++ ~ifp->if_hwassist) { ++ uint32_t plen = m0->m_pkthdr.len - sizeof(*ip6); ++ in6_delayed_cksum(m0, plen, sizeof(struct ip6_hdr)); ++ m0->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA_IPV6; ++ } ++ + /* + * If the packet is too large for the outgoing interface, + * send back an icmp6 error. +--- sys/contrib/pf/net/pf_ioctl.c.orig ++++ sys/contrib/pf/net/pf_ioctl.c +@@ -4158,11 +4158,6 @@ + struct ip *h = NULL; + int chk; + +- /* We need a proper CSUM befor we start (s. OpenBSD ip_output) */ +- if ((*m)->m_pkthdr.csum_flags & CSUM_DELAY_DATA) { +- in_delayed_cksum(*m); +- (*m)->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA; +- } + if ((*m)->m_pkthdr.len >= (int)sizeof(*h)) { + /* if m_pkthdr.len is less than ip header, pf will handle. */ + h = mtod(*m, struct ip *); +@@ -4222,14 +4217,6 @@ + */ + int chk; + +- /* We need a proper CSUM before we start (s. OpenBSD ip_output) */ +- if ((*m)->m_pkthdr.csum_flags & CSUM_DELAY_DATA) { +-#ifdef INET +- /* XXX-BZ copy&paste error from r126261? */ +- in_delayed_cksum(*m); +-#endif +- (*m)->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA; +- } + CURVNET_SET(ifp->if_vnet); + chk = pf_test6(PF_OUT, ifp, m, NULL, inp); + CURVNET_RESTORE(); +--- sys/contrib/pf/net/pf_norm.c.orig ++++ sys/contrib/pf/net/pf_norm.c +@@ -1657,13 +1657,14 @@ + th->th_x2 = 0; + nv = *(u_int16_t *)(&th->th_ack + 1); + +- th->th_sum = pf_cksum_fixup(th->th_sum, ov, nv, 0); ++ th->th_sum = pf_proto_cksum_fixup(m, th->th_sum, ov, nv, 0); + rewrite = 1; + } + + /* Remove urgent pointer, if TH_URG is not set */ + if (!(flags & TH_URG) && th->th_urp) { +- th->th_sum = pf_cksum_fixup(th->th_sum, th->th_urp, 0, 0); ++ th->th_sum = pf_proto_cksum_fixup(m, th->th_sum, th->th_urp, ++ 0, 0); + th->th_urp = 0; + rewrite = 1; + } +@@ -1889,7 +1890,7 @@ + (src->scrub->pfss_flags & + PFSS_TIMESTAMP)) { + tsval = ntohl(tsval); +- pf_change_a(&opt[2], ++ pf_change_proto_a(m, &opt[2], + &th->th_sum, + htonl(tsval + + src->scrub->pfss_ts_mod), +@@ -1905,7 +1906,7 @@ + PFSS_TIMESTAMP)) { + tsecr = ntohl(tsecr) + - dst->scrub->pfss_ts_mod; +- pf_change_a(&opt[6], ++ pf_change_proto_a(m, &opt[6], + &th->th_sum, htonl(tsecr), + 0); + copyback = 1; +@@ -2286,8 +2287,8 @@ + case TCPOPT_MAXSEG: + mss = (u_int16_t *)(optp + 2); + if ((ntohs(*mss)) > r->max_mss) { +- th->th_sum = pf_cksum_fixup(th->th_sum, +- *mss, htons(r->max_mss), 0); ++ th->th_sum = pf_proto_cksum_fixup(m, ++ th->th_sum, *mss, htons(r->max_mss), 0); + *mss = htons(r->max_mss); + rewrite = 1; + } +--- sys/contrib/pf/net/pfvar.h.orig ++++ sys/contrib/pf/net/pfvar.h +@@ -1909,6 +1909,8 @@ + extern void pf_print_flags(u_int8_t); + extern u_int16_t pf_cksum_fixup(u_int16_t, u_int16_t, u_int16_t, + u_int8_t); ++extern u_int16_t pf_proto_cksum_fixup(struct mbuf *, u_int16_t, ++ u_int16_t, u_int16_t, u_int8_t); + + #ifdef __FreeBSD__ + VNET_DECLARE(struct ifnet *, sync_ifp); +@@ -1954,6 +1956,9 @@ + void *pf_pull_hdr(struct mbuf *, int, void *, int, u_short *, u_short *, + sa_family_t); + void pf_change_a(void *, u_int16_t *, u_int32_t, u_int8_t); ++void pf_change_proto_a(struct mbuf *, void *, u_int16_t *, u_int32_t, ++ u_int8_t); ++void pf_change_tcp_a(struct mbuf *, void *, u_int16_t *, u_int32_t); + int pflog_packet(struct pfi_kif *, struct mbuf *, sa_family_t, u_int8_t, + u_int8_t, struct pf_rule *, struct pf_rule *, struct pf_ruleset *, + struct pf_pdesc *); +--- sys/netinet6/ip6_output.c.orig ++++ sys/netinet6/ip6_output.c +@@ -184,7 +184,7 @@ + }\ + } while (/*CONSTCOND*/ 0) + +-static void ++void + in6_delayed_cksum(struct mbuf *m, uint32_t plen, u_short offset) + { + u_short csum; +--- sys/netinet6/ip6_var.h.orig ++++ sys/netinet6/ip6_var.h +@@ -456,6 +456,7 @@ + struct rtentry **, u_int); + u_int32_t ip6_randomid(void); + u_int32_t ip6_randomflowlabel(void); ++void in6_delayed_cksum(struct mbuf *m, uint32_t plen, u_short offset); + #endif /* _KERNEL */ + + #endif /* !_NETINET6_IP6_VAR_H_ */ diff --git a/share/security/patches/EN-16:02/pf-9.patch.asc b/share/security/patches/EN-16:02/pf-9.patch.asc new file mode 100644 index 0000000000..00b167a019 --- /dev/null +++ b/share/security/patches/EN-16:02/pf-9.patch.asc @@ -0,0 +1,16 @@ +-----BEGIN PGP SIGNATURE----- + +iQIcBAABCgAGBQJWl2vXAAoJEO1n7NZdz2rnWksQANG3wnvt9x7pSkzPczC76OlN +FVDRCnBNcBe4Jpr0KixCGBxY5ICVLPTbyS9REX3cNY5PokjKuFEqvX6EUtE0W6Jp +k3Y4AYRvCGCrCbn7HXwlbmRDKZNjvnC0Ek6SQYotcSGeY69RyusZ2tAZKQRv+TGR +JO95YKORnU4NvBtm6jDQAvdFodDG2yLpj5Q8V8/N7aA+0CKHp5+RkTUv/2THmrKD +8BeMWbtCJBVIAEuChfuDKj5fpWKaCAm7TmZZJHUviY1BmRu2z0CAya7Z//a74d+s +uvkDC2ohjqZ13EmC9dQ+WyRIlb8KbBGl5f8zM2wNX2Cqvlt0tAeoEHl/KAJTJ2Ap +PAJd6DCz2Fqu/vHzqzRW8zkjUOoRJ4CkwLjHqhxKJcJoG2x8nwCKYpKpF47/6Ys1 +UGfGva42YjEKqtK9vK7PjMUSFyvJVNQSEsj3kYBPW3cJdx7monF9kcLYpBRBFO4W +9RVT8xjHtJv76aWqnsyA5DIlNfIg3x7lMLnXE1hR+jifyZ1mDJxHYIaDzxq/klBt +cWIRlfCvtar8bGgNR1O/qncSNgn+3k32861AsfS/F0ca4lYdTAkE/5xXA2YesfyS +hWqjchvI6v36JyeshEqL68RXKsnoaB0SxJ3z19Qam0m3QSHNNANyQackPsiTZRxe +hLYgXohMz/V8yjbEgOOP +=rwun +-----END PGP SIGNATURE----- diff --git a/share/security/patches/EN-16:03/yplib.patch b/share/security/patches/EN-16:03/yplib.patch new file mode 100644 index 0000000000..f3e405ec47 --- /dev/null +++ b/share/security/patches/EN-16:03/yplib.patch @@ -0,0 +1,121 @@ +--- lib/libc/yp/yplib.c.orig ++++ lib/libc/yp/yplib.c +@@ -655,7 +655,7 @@ + struct timeval tv; + struct ypreq_key yprk; + int r; +- ++ int retries = 0; + *outval = NULL; + *outvallen = 0; + +@@ -700,6 +700,11 @@ + #endif + + again: ++ if (retries > MAX_RETRIES) { ++ YPUNLOCK(); ++ return (YPERR_RPC); ++ } ++ + if (_yp_dobind(indomain, &ysd) != 0) { + YPUNLOCK(); + return (YPERR_DOMAIN); +@@ -716,6 +721,7 @@ + if (r != RPC_SUCCESS) { + clnt_perror(ysd->dom_client, "yp_match: clnt_call"); + _yp_unbind(ysd); ++ retries++; + goto again; + } + +@@ -772,7 +778,7 @@ + struct dom_binding *ysd; + struct timeval tv; + int r; +- ++ int retries = 0; + /* Sanity check */ + + if (indomain == NULL || !strlen(indomain) || +@@ -784,6 +790,11 @@ + + YPLOCK(); + again: ++ if (retries > MAX_RETRIES) { ++ YPUNLOCK(); ++ return (YPERR_RPC); ++ } ++ + if (_yp_dobind(indomain, &ysd) != 0) { + YPUNLOCK(); + return (YPERR_DOMAIN); +@@ -802,6 +813,7 @@ + if (r != RPC_SUCCESS) { + clnt_perror(ysd->dom_client, "yp_first: clnt_call"); + _yp_unbind(ysd); ++ retries++; + goto again; + } + if (!(r = ypprot_err(yprkv.stat))) { +@@ -844,7 +856,7 @@ + struct dom_binding *ysd; + struct timeval tv; + int r; +- ++ int retries = 0; + /* Sanity check */ + + if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 || +@@ -857,6 +869,11 @@ + + YPLOCK(); + again: ++ if (retries > MAX_RETRIES) { ++ YPUNLOCK(); ++ return (YPERR_RPC); ++ } ++ + if (_yp_dobind(indomain, &ysd) != 0) { + YPUNLOCK(); + return (YPERR_DOMAIN); +@@ -877,6 +894,7 @@ + if (r != RPC_SUCCESS) { + clnt_perror(ysd->dom_client, "yp_next: clnt_call"); + _yp_unbind(ysd); ++ retries++; + goto again; + } + if (!(r = ypprot_err(yprkv.stat))) { +@@ -920,7 +938,7 @@ + CLIENT *clnt; + u_long status, savstat; + int clnt_sock; +- ++ int retries = 0; + /* Sanity check */ + + if (indomain == NULL || !strlen(indomain) || +@@ -929,6 +947,10 @@ + + YPLOCK(); + again: ++ if (retries > MAX_RETRIES) { ++ YPUNLOCK(); ++ return (YPERR_RPC); ++ } + + if (_yp_dobind(indomain, &ysd) != 0) { + YPUNLOCK(); +@@ -958,9 +980,10 @@ + if (clnt_call(clnt, YPPROC_ALL, + (xdrproc_t)xdr_ypreq_nokey, &yprnk, + (xdrproc_t)xdr_ypresp_all_seq, &status, tv) != RPC_SUCCESS) { +- clnt_perror(ysd->dom_client, "yp_all: clnt_call"); ++ clnt_perror(clnt, "yp_all: clnt_call"); + clnt_destroy(clnt); + _yp_unbind(ysd); ++ retries++; + goto again; + } + diff --git a/share/security/patches/EN-16:03/yplib.patch.asc b/share/security/patches/EN-16:03/yplib.patch.asc new file mode 100644 index 0000000000..c7f6acb6b3 --- /dev/null +++ b/share/security/patches/EN-16:03/yplib.patch.asc @@ -0,0 +1,16 @@ +-----BEGIN PGP SIGNATURE----- + +iQIcBAABCgAGBQJWl2vYAAoJEO1n7NZdz2rnxbYQAKxlkBfJnArM/ESwHCi9dvbC +Q4dsDErwVo2uIaxyB29Tl2uy2qR7npiXOCbuaKZHnFr87lTwi0zsELQ3OJEFbzsF +XTkRteKfM4el/s4UUzj0IIYnR7w97UvLM5stgrilIegg4yg0okOiGDDpentv/iPb +EGzt9PbWncsminLR0bbwMygE3Pb/5NVcdEUzZSEVVFjWt+8N4j1DMQolLIs/pgvh +TSWlztQqEFntia5LjBx05WOlg5cnM9NZGYW4ruQ2hVOjVdb/qEYyDKRzDOIkYIGl +vHjWltGQNAmB3+EpCg1m4dENBhQPwkmXI9x87c+M3MsgZafOwY9C/igjWyUngDjP +lquCAQq8pMk0OvtUctbjp3jMGVOUwhi4x3ZtknnHcR33/PCBTGIi7eekNdXp9g1G +0Iu/0meA1HEN3Zll+J4iGUoMIDPj247Lcqp3k/+V7sWDuHRszjW1Thk07OLS/+E4 +iJ1vLy9FuwBoVOuc5h3P2hc2dAR49rlSh/DC+CIosRWtBN3K5kEi3zGyTPx1jCb9 +KZnJLRjRsp7Pc8ttCXHprUn1EqqxeIsDHLAJ4v2FjieKawQXfeJPnzhUKL5W1B8F +N6GkwxhwwksHfwqOF6Lt7i4Zfy3+HSqO5sJlAvZ0H95in6/rdkC/au0FTYfoowkW +XCERr6GWLn+OElTN0zP6 +=m8uJ +-----END PGP SIGNATURE----- diff --git a/share/security/patches/SA-16:01/sctp.patch b/share/security/patches/SA-16:01/sctp.patch new file mode 100644 index 0000000000..be7ef8a30f --- /dev/null +++ b/share/security/patches/SA-16:01/sctp.patch @@ -0,0 +1,21 @@ +--- sys/netinet6/sctp6_usrreq.c.orig ++++ sys/netinet6/sctp6_usrreq.c +@@ -379,7 +379,6 @@ + * XXX: We assume that when IPV6 is non NULL, M and OFF are + * valid. + */ +- /* check if we can safely examine src and dst ports */ + struct sctp_inpcb *inp = NULL; + struct sctp_tcb *stcb = NULL; + struct sctp_nets *net = NULL; +@@ -388,6 +387,10 @@ + if (ip6cp->ip6c_m == NULL) + return; + ++ /* Check if we can safely examine the SCTP header. */ ++ if (ip6cp->ip6c_m->m_pkthdr.len < ip6cp->ip6c_off + sizeof(sh)) ++ return; ++ + bzero(&sh, sizeof(sh)); + bzero(&final, sizeof(final)); + inp = NULL; diff --git a/share/security/patches/SA-16:01/sctp.patch.asc b/share/security/patches/SA-16:01/sctp.patch.asc new file mode 100644 index 0000000000..fa17253a11 --- /dev/null +++ b/share/security/patches/SA-16:01/sctp.patch.asc @@ -0,0 +1,16 @@ +-----BEGIN PGP SIGNATURE----- + +iQIcBAABCgAGBQJWl2vZAAoJEO1n7NZdz2rnhLcQAKcsskSsuiYk43iZ3r+xYTxW +rnKNXWsg07vvgGTt7SuSieW+U+QJG7tlneksjFdOMlubaEzxhpSptsWYWy+jkR8U +revnF2SW1BItKYmXLtYAtyzvHxIuOlJKiyUKflA/MdrNdgPBpLcOgxJw1EJcaY6u +5YUTIg3N4KLNSNFlvOVPi9PtM8uf7gR+8rvvbPW/v9ni28qsp8un5biPtgr/ESuV +ya4nTFwYi6221na3dB/PyA97WKd7rvkDyZvUA5IDeNGDm1mT15YPRPaknAmlBsa6 +9vEnObj9oODKsdwsPS+Ov0By3X9CsW2dJlcLIHmC/DW89My3x/Q1pbquqTc5P8DF +eu4i0TuYgPlukjWqASi04zoOPibRxNadLaqPr6BKMDX4daUXmP6G+wnWAp89tj/3 +t1rAsB/z/OXq136vIEgRnEIVYMBk0Ie9Jc5wsm9ZA8WQ7w4+1NJOmhmR5V4hD+IX +m0FueELyEKje57ArwryjoBgHUgODQtI1QARPPAvvN1x81J76dQVT+fzBWychWzzk +OvvF2mbxwxfIQBB47OQVrrqctxfLZyekmpY6Ma6eCY5dzFdmI3ncHnkmXE2HHklU +Oi7NtuwkxQfARKDON3CWU9PBYQkV9aciTDYMO1Lk24ojwye0XL7XWGMPR+/GjT3v +cacygRjuFTVLcLIka2w+ +=AqPl +-----END PGP SIGNATURE----- diff --git a/share/security/patches/SA-16:02/ntp-10.patch b/share/security/patches/SA-16:02/ntp-10.patch new file mode 100644 index 0000000000..07d2a4db6f --- /dev/null +++ b/share/security/patches/SA-16:02/ntp-10.patch @@ -0,0 +1,15927 @@ +--- contrib/ntp/html/miscopt.html.orig ++++ contrib/ntp/html/miscopt.html +@@ -3,7 +3,7 @@ + + + Miscellaneous Commands and Options +- ++ + + + +@@ -11,7 +11,7 @@ + giffrom Pogo, Walt Kelly +

We have three, now looking for more.

+

Last update: +- 23-Sep-2015 10:20 ++ 17-Nov-2015 11:06 + UTC

+
+

Related Links

+@@ -57,7 +57,7 @@ +
interface [listen | ignore | drop] [all | ipv4 | ipv6 | wildcard | name | address[/prefixlen]]
+
This command controls which network addresses ntpd opens, and whether input is dropped without processing. The first parameter determines the action for addresses which match the second parameter. That parameter specifies a class of addresses, or a specific interface name, or an address. In the address case, prefixlen determines how many bits must match for this rule to apply. ignore prevents opening matching addresses, drop causes ntpd to open the address and drop all received packets without examination. Multiple interface commands can be used. The last rule which matches a particular address determines the action for it. interface commands are disabled if any -I, --interface, -L, or --novirtualips command-line options are used. If none of those options are used and no interface actions are specified in the configuration file, all available network addresses are opened. The nic command is an alias for interface.
+
leapfile leapfile
+-
This command loads the NIST leapseconds file and initializes the leapsecond values for the next leapsecond time, expiration time and TAI offset. The file can be obtained directly from NIST national time servers using ftp as the ASCII file pub/leap-seconds.
++
This command loads the IERS leapseconds file and initializes the leapsecond values for the next leapsecond time, expiration time and TAI offset. The file can be obtained directly from the IERS at https://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list or ftp://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list.
+
The leapfile is scanned when ntpd processes the leapfile directive or when ntpd detects that leapfile has changed. ntpd checks once a day to see if the leapfile has changed.
+
While not strictly a security function, the Autokey protocol provides means to securely retrieve the current or updated leapsecond values from a server.
+
leapsmearinterval seconds
+--- contrib/ntp/include/Makefile.am.orig ++++ contrib/ntp/include/Makefile.am +@@ -66,6 +66,7 @@ + recvbuff.h \ + refclock_atom.h \ + refidsmear.h \ ++ safecast.h \ + ssl_applink.c \ + timepps-SCO.h \ + timepps-Solaris.h \ +--- contrib/ntp/include/Makefile.in.orig ++++ contrib/ntp/include/Makefile.in +@@ -551,6 +551,7 @@ + recvbuff.h \ + refclock_atom.h \ + refidsmear.h \ ++ safecast.h \ + ssl_applink.c \ + timepps-SCO.h \ + timepps-Solaris.h \ +--- contrib/ntp/include/ntp_refclock.h.orig ++++ contrib/ntp/include/ntp_refclock.h +@@ -220,7 +220,7 @@ + extern void refclock_control(sockaddr_u *, + const struct refclockstat *, + struct refclockstat *); +-extern int refclock_open (char *, u_int, u_int); ++extern int refclock_open (const char *, u_int, u_int); + extern int refclock_setup (int, u_int, u_int); + extern void refclock_timer (struct peer *); + extern void refclock_transmit(struct peer *); +--- contrib/ntp/include/ntp_stdlib.h.orig ++++ contrib/ntp/include/ntp_stdlib.h +@@ -65,8 +65,8 @@ + /* authkeys.c */ + extern void auth_delkeys (void); + extern int auth_havekey (keyid_t); +-extern int authdecrypt (keyid_t, u_int32 *, int, int); +-extern int authencrypt (keyid_t, u_int32 *, int); ++extern int authdecrypt (keyid_t, u_int32 *, size_t, size_t); ++extern size_t authencrypt (keyid_t, u_int32 *, size_t); + extern int authhavekey (keyid_t); + extern int authistrusted (keyid_t); + extern int authreadkeys (const char *); +@@ -95,8 +95,8 @@ + extern int ymd2yd (int, int, int); + + /* a_md5encrypt.c */ +-extern int MD5authdecrypt (int, u_char *, u_int32 *, int, int); +-extern int MD5authencrypt (int, u_char *, u_int32 *, int); ++extern int MD5authdecrypt (int, const u_char *, u_int32 *, size_t, size_t); ++extern size_t MD5authencrypt (int, const u_char *, u_int32 *, size_t); + extern void MD5auth_setkey (keyid_t, int, const u_char *, size_t); + extern u_int32 addr2refid (sockaddr_u *); + +--- contrib/ntp/include/ntp_worker.h.orig ++++ contrib/ntp/include/ntp_worker.h +@@ -43,19 +43,22 @@ + } blocking_pipe_header; + + # ifdef WORK_THREAD +-# ifdef WORK_PIPE +-typedef pthread_t * thr_ref; +-typedef sem_t * sem_ref; ++# ifdef SYS_WINNT ++typedef struct { HANDLE thnd; } thread_type; ++typedef struct { HANDLE shnd; } sema_type; + # else +-typedef HANDLE thr_ref; +-typedef HANDLE sem_ref; ++typedef pthread_t thread_type; ++typedef sem_t sema_type; + # endif ++typedef thread_type *thr_ref; ++typedef sema_type *sem_ref; + # endif + + /* + * + */ +-#ifdef WORK_FORK ++#if defined(WORK_FORK) ++ + typedef struct blocking_child_tag { + int reusable; + int pid; +@@ -66,38 +69,59 @@ + int resp_write_pipe; + int ispipe; + } blocking_child; ++ + #elif defined(WORK_THREAD) ++ + typedef struct blocking_child_tag { + /* + * blocking workitems and blocking_responses are dynamically-sized + * one-dimensional arrays of pointers to blocking worker requests and + * responses. ++ * ++ * IMPORTANT: This structure is shared between threads, and all access ++ * that is not atomic (especially queue operations) must hold the ++ * 'accesslock' semaphore to avoid data races. ++ * ++ * The resource management (thread/semaphore creation/destruction) ++ * functions and functions just testing a handle are safe because these ++ * are only changed by the main thread when no worker is running on the ++ * same data structure. + */ + int reusable; +- thr_ref thread_ref; +- u_int thread_id; +- blocking_pipe_header * volatile * volatile ++ sem_ref accesslock; /* shared access lock */ ++ thr_ref thread_ref; /* thread 'handle' */ ++ ++ /* the reuest queue */ ++ blocking_pipe_header ** volatile + workitems; + volatile size_t workitems_alloc; +- size_t next_workitem; /* parent */ +- size_t next_workeritem; /* child */ +- blocking_pipe_header * volatile * volatile ++ size_t head_workitem; /* parent */ ++ size_t tail_workitem; /* child */ ++ sem_ref workitems_pending; /* signalling */ ++ ++ /* the response queue */ ++ blocking_pipe_header ** volatile + responses; + volatile size_t responses_alloc; +- size_t next_response; /* child */ +- size_t next_workresp; /* parent */ ++ size_t head_response; /* child */ ++ size_t tail_response; /* parent */ ++ + /* event handles / sem_t pointers */ +- /* sem_ref child_is_blocking; */ +- sem_ref blocking_req_ready; + sem_ref wake_scheduled_sleep; ++ ++ /* some systems use a pipe for notification, others a semaphore. ++ * Both employ the queue above for the actual data transfer. ++ */ + #ifdef WORK_PIPE +- int resp_read_pipe; /* parent */ +- int resp_write_pipe;/* child */ ++ int resp_read_pipe; /* parent */ ++ int resp_write_pipe; /* child */ + int ispipe; +- void * resp_read_ctx; /* child */ ++ void * resp_read_ctx; /* child */ + #else +- sem_ref blocking_response_ready; ++ sem_ref responses_pending; /* signalling */ + #endif ++ sema_type sem_table[4]; ++ thread_type thr_table[1]; + } blocking_child; + + #endif /* WORK_THREAD */ +@@ -111,7 +135,7 @@ + extern int queue_blocking_request(blocking_work_req, void *, + size_t, blocking_work_callback, + void *); +-extern int queue_blocking_response(blocking_child *, ++extern int queue_blocking_response(blocking_child *, + blocking_pipe_header *, size_t, + const blocking_pipe_header *); + extern void process_blocking_resp(blocking_child *); +--- contrib/ntp/include/ntpd.h.orig ++++ contrib/ntp/include/ntpd.h +@@ -156,7 +156,7 @@ + extern int freq_cnt; + + /* ntp_monitor.c */ +-#define MON_HASH_SIZE (1U << mon_hash_bits) ++#define MON_HASH_SIZE ((size_t)1U << mon_hash_bits) + #define MON_HASH_MASK (MON_HASH_SIZE - 1) + #define MON_HASH(addr) (sock_hash(addr) & MON_HASH_MASK) + extern void init_mon (void); +@@ -408,6 +408,7 @@ + extern int ext_enable; /* external clock enabled */ + extern int cal_enable; /* refclock calibrate enable */ + extern int allow_panic; /* allow panic correction (-g) */ ++extern int enable_panic_check; /* Can we check allow_panic's state? */ + extern int force_step_once; /* always step time once at startup (-G) */ + extern int mode_ntpdate; /* exit on first clock set (-q) */ + extern int peer_ntpdate; /* count of ntpdate peers */ +--- contrib/ntp/include/safecast.h.orig ++++ contrib/ntp/include/safecast.h +@@ -0,0 +1,34 @@ ++#ifndef SAFECAST_H ++#define SAFECAST_H ++ ++#include ++static inline int size2int_chk(size_t v) ++{ ++ if (v > INT_MAX) ++ abort(); ++ return (int)(v); ++} ++ ++static inline int size2int_sat(size_t v) ++{ ++ return (v > INT_MAX) ? INT_MAX : (int)v; ++} ++ ++/* Compilers can emit warning about increased alignment requirements ++ * when casting pointers. The impact is tricky: on machines where ++ * alignment is just a performance issue (x86,x64,...) this might just ++ * cause a performance penalty. On others, an address error can occur ++ * and the process dies... ++ * ++ * Still, there are many cases where the pointer arithmetic and the ++ * buffer alignment make sure this does not happen. OTOH, the compiler ++ * doesn't know this and still emits warnings. ++ * ++ * The following cast macros are going through void pointers to tell ++ * the compiler that there is no alignment requirement to watch. ++ */ ++#define UA_PTR(ptype,pval) ((ptype *)(void*)(pval)) ++#define UAC_PTR(ptype,pval) ((const ptype *)(const void*)(pval)) ++#define UAV_PTR(ptype,pval) ((volatile ptype *)(volatile void*)(pval)) ++ ++#endif +--- contrib/ntp/lib/isc/win32/interfaceiter.c.orig ++++ contrib/ntp/lib/isc/win32/interfaceiter.c +@@ -54,7 +54,7 @@ + IP_ADAPTER_ADDRESSES * ipaaCur; /* enumeration position */ + IP_ADAPTER_UNICAST_ADDRESS *ipuaCur; /* enumeration subposition */ + /* fields used for the older address enumeration ioctls */ +- int socket; ++ SOCKET socket; + INTERFACE_INFO IFData; /* Current Interface Info */ + int numIF; /* Current Interface count */ + int v4IF; /* Number of IPv4 Interfaces */ +--- contrib/ntp/lib/isc/win32/net.c.orig ++++ contrib/ntp/lib/isc/win32/net.c +@@ -216,7 +216,8 @@ + + static void + try_ipv6pktinfo(void) { +- int s, on; ++ SOCKET s; ++ int on; + char strbuf[ISC_STRERRORSIZE]; + isc_result_t result; + int optname; +--- contrib/ntp/lib/isc/backtrace.c.orig ++++ contrib/ntp/lib/isc/backtrace.c +@@ -278,7 +278,7 @@ + result = ISC_R_NOTFOUND; + else { + *symbolp = found->symbol; +- *offsetp = (const char *)addr - (char *)found->addr; ++ *offsetp = (u_long)((const char *)addr - (char *)found->addr); + } + + return (result); +--- contrib/ntp/lib/isc/buffer.c.orig ++++ contrib/ntp/lib/isc/buffer.c +@@ -406,7 +406,7 @@ + + void + isc__buffer_putstr(isc_buffer_t *b, const char *source) { +- unsigned int l; ++ size_t l; + unsigned char *cp; + + REQUIRE(ISC_BUFFER_VALID(b)); +@@ -421,7 +421,7 @@ + + cp = isc_buffer_used(b); + memcpy(cp, source, l); +- b->used += l; ++ b->used += (u_int)l; /* checked above - no overflow here */ + } + + isc_result_t +--- contrib/ntp/lib/isc/inet_aton.c.orig ++++ contrib/ntp/lib/isc/inet_aton.c +@@ -92,7 +92,7 @@ + int + isc_net_aton(const char *cp, struct in_addr *addr) { + unsigned long val; +- int base, n; ++ int base; + unsigned char c; + isc_uint8_t parts[4]; + isc_uint8_t *pp = parts; +@@ -166,8 +166,7 @@ + * Concoct the address according to + * the number of parts specified. + */ +- n = pp - parts + 1; +- switch (n) { ++ switch (pp - parts + 1) { + case 1: /* a -- 32 bits */ + break; + +--- contrib/ntp/lib/isc/inet_pton.c.orig ++++ contrib/ntp/lib/isc/inet_pton.c +@@ -92,7 +92,7 @@ + const char *pch; + + if ((pch = strchr(digits, ch)) != NULL) { +- unsigned int newv = *tp * 10 + (pch - digits); ++ size_t newv = *tp * 10 + (pch - digits); + + if (saw_digit && *tp == 0) + return (0); +@@ -197,12 +197,12 @@ + * Since some memmove()'s erroneously fail to handle + * overlapping regions, we'll do the shift by hand. + */ +- const int n = tp - colonp; ++ const size_t n = tp - colonp; + int i; + + if (tp == endp) + return (0); +- for (i = 1; i <= n; i++) { ++ for (i = 1; (size_t)i <= n; i++) { + endp[- i] = colonp[n - i]; + colonp[n - i] = 0; + } +--- contrib/ntp/lib/isc/log.c.orig ++++ contrib/ntp/lib/isc/log.c +@@ -1146,7 +1146,7 @@ + char *basenam, *digit_end; + const char *dirname; + int version, greatest = -1; +- unsigned int basenamelen; ++ size_t basenamelen; + isc_dir_t dir; + isc_result_t result; + char sep = '/'; +--- contrib/ntp/lib/isc/netaddr.c.orig ++++ contrib/ntp/lib/isc/netaddr.c +@@ -159,7 +159,7 @@ + if (r == NULL) + return (ISC_R_FAILURE); + +- alen = strlen(abuf); ++ alen = (unsigned int)strlen(abuf); /* no overflow possible */ + INSIST(alen < sizeof(abuf)); + + zlen = 0; +--- contrib/ntp/lib/isc/sockaddr.c.orig ++++ contrib/ntp/lib/isc/sockaddr.c +@@ -134,7 +134,7 @@ + break; + #ifdef ISC_PLAFORM_HAVESYSUNH + case AF_UNIX: +- plen = strlen(sockaddr->type.sunix.sun_path); ++ plen = (unsigned int)strlen(sockaddr->type.sunix.sun_path); + if (plen >= isc_buffer_availablelength(target)) + return (ISC_R_NOSPACE); + +@@ -153,7 +153,7 @@ + return (ISC_R_FAILURE); + } + +- plen = strlen(pbuf); ++ plen = (unsigned int)strlen(pbuf); + INSIST(plen < sizeof(pbuf)); + + isc_netaddr_fromsockaddr(&netaddr, sockaddr); +--- contrib/ntp/lib/isc/task.c.orig ++++ contrib/ntp/lib/isc/task.c +@@ -329,7 +329,7 @@ + isc__task_create(isc_taskmgr_t *manager0, unsigned int quantum, + isc_task_t **taskp) + { +- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; ++ isc__taskmgr_t *manager = (void*)manager0; + isc__task_t *task; + isc_boolean_t exiting; + isc_result_t result; +@@ -1463,7 +1463,7 @@ + */ + + REQUIRE(managerp != NULL); +- manager = (isc__taskmgr_t *)*managerp; ++ manager = (void*)(*managerp); + REQUIRE(VALID_MANAGER(manager)); + + #ifndef USE_WORKER_THREADS +@@ -1559,7 +1559,7 @@ + + ISC_TASKFUNC_SCOPE void + isc__taskmgr_setmode(isc_taskmgr_t *manager0, isc_taskmgrmode_t mode) { +- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; ++ isc__taskmgr_t *manager = (void*)manager0; + + LOCK(&manager->lock); + manager->mode = mode; +@@ -1568,7 +1568,7 @@ + + ISC_TASKFUNC_SCOPE isc_taskmgrmode_t + isc__taskmgr_mode(isc_taskmgr_t *manager0) { +- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; ++ isc__taskmgr_t *manager = (void*)manager0; + isc_taskmgrmode_t mode; + LOCK(&manager->lock); + mode = manager->mode; +@@ -1579,7 +1579,7 @@ + #ifndef USE_WORKER_THREADS + isc_boolean_t + isc__taskmgr_ready(isc_taskmgr_t *manager0) { +- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; ++ isc__taskmgr_t *manager = (void*)manager0; + isc_boolean_t is_ready; + + #ifdef USE_SHARED_MANAGER +@@ -1598,7 +1598,7 @@ + + isc_result_t + isc__taskmgr_dispatch(isc_taskmgr_t *manager0) { +- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; ++ isc__taskmgr_t *manager = (void*)manager0; + + #ifdef USE_SHARED_MANAGER + if (manager == NULL) +@@ -1615,7 +1615,7 @@ + #else + ISC_TASKFUNC_SCOPE void + isc__taskmgr_pause(isc_taskmgr_t *manager0) { +- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; ++ isc__taskmgr_t *manager = (void*)manager0; + LOCK(&manager->lock); + while (manager->tasks_running > 0) { + WAIT(&manager->paused, &manager->lock); +@@ -1626,7 +1626,7 @@ + + ISC_TASKFUNC_SCOPE void + isc__taskmgr_resume(isc_taskmgr_t *manager0) { +- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0; ++ isc__taskmgr_t *manager = (void*)manager0; + + LOCK(&manager->lock); + if (manager->pause_requested) { +--- contrib/ntp/libntp/a_md5encrypt.c.orig ++++ contrib/ntp/libntp/a_md5encrypt.c +@@ -16,12 +16,12 @@ + * + * Returns length of MAC including key ID and digest. + */ +-int ++size_t + MD5authencrypt( +- int type, /* hash algorithm */ +- u_char *key, /* key pointer */ +- u_int32 *pkt, /* packet pointer */ +- int length /* packet length */ ++ int type, /* hash algorithm */ ++ const u_char * key, /* key pointer */ ++ u_int32 * pkt, /* packet pointer */ ++ size_t length /* packet length */ + ) + { + u_char digest[EVP_MAX_MD_SIZE]; +@@ -44,7 +44,7 @@ + EVP_DigestInit(&ctx, EVP_get_digestbynid(type)); + #endif + EVP_DigestUpdate(&ctx, key, cache_secretsize); +- EVP_DigestUpdate(&ctx, (u_char *)pkt, (u_int)length); ++ EVP_DigestUpdate(&ctx, (u_char *)pkt, length); + EVP_DigestFinal(&ctx, digest, &len); + memmove((u_char *)pkt + length + 4, digest, len); + return (len + 4); +@@ -58,11 +58,11 @@ + */ + int + MD5authdecrypt( +- int type, /* hash algorithm */ +- u_char *key, /* key pointer */ +- u_int32 *pkt, /* packet pointer */ +- int length, /* packet length */ +- int size /* MAC size */ ++ int type, /* hash algorithm */ ++ const u_char * key, /* key pointer */ ++ u_int32 * pkt, /* packet pointer */ ++ size_t length, /* packet length */ ++ size_t size /* MAC size */ + ) + { + u_char digest[EVP_MAX_MD_SIZE]; +@@ -85,14 +85,14 @@ + EVP_DigestInit(&ctx, EVP_get_digestbynid(type)); + #endif + EVP_DigestUpdate(&ctx, key, cache_secretsize); +- EVP_DigestUpdate(&ctx, (u_char *)pkt, (u_int)length); ++ EVP_DigestUpdate(&ctx, (u_char *)pkt, length); + EVP_DigestFinal(&ctx, digest, &len); +- if ((u_int)size != len + 4) { ++ if (size != (size_t)len + 4) { + msyslog(LOG_ERR, + "MAC decrypt: MAC length error"); + return (0); + } +- return !memcmp(digest, (char *)pkt + length + 4, len); ++ return !memcmp(digest, (const char *)pkt + length + 4, len); + } + + /* +--- contrib/ntp/libntp/atolfp.c.orig ++++ contrib/ntp/libntp/atolfp.c +@@ -68,7 +68,7 @@ + + while (*cp != '\0' && (ind = strchr(digits, *cp)) != NULL) { + dec_i = (dec_i << 3) + (dec_i << 1); /* multiply by 10 */ +- dec_i += (ind - digits); ++ dec_i += (u_long)(ind - digits); + cp++; + } + +@@ -80,7 +80,7 @@ + && (ind = strchr(digits, *cp)) != NULL) { + ndec++; + dec_f = (dec_f << 3) + (dec_f << 1); /* *10 */ +- dec_f += (ind - digits); ++ dec_f += (u_long)(ind - digits); + cp++; + } + +--- contrib/ntp/libntp/authkeys.c.orig ++++ contrib/ntp/libntp/authkeys.c +@@ -63,7 +63,7 @@ + * keyid. We make this fairly big for potentially busy servers. + */ + #define DEF_AUTHHASHSIZE 64 +-//#define HASHMASK ((HASHSIZE)-1) ++/*#define HASHMASK ((HASHSIZE)-1)*/ + #define KEYHASH(keyid) ((keyid) & authhashmask) + + int authhashdisabled; +@@ -511,7 +511,17 @@ + return TRUE; + } + +- ++/* Note: There are two locations below where 'strncpy()' is used. While ++ * this function is a hazard by itself, it's essential that it is used ++ * here. Bug 1243 involved that the secret was filled with NUL bytes ++ * after the first NUL encountered, and 'strlcpy()' simply does NOT have ++ * this behaviour. So disabling the fix and reverting to the buggy ++ * behaviour due to compatibility issues MUST also fill with NUL and ++ * this needs 'strncpy'. Also, the secret is managed as a byte blob of a ++ * given size, and eventually truncating it and replacing the last byte ++ * with a NUL would be a bug. ++ * perlinger@ntp.org 2015-10-10 ++ */ + void + MD5auth_setkey( + keyid_t keyno, +@@ -546,7 +556,8 @@ + #ifndef DISABLE_BUG1243_FIX + memcpy(sk->secret, key, secretsize); + #else +- strlcpy((char *)sk->secret, (const char *)key, ++ /* >MUST< use 'strncpy()' here! See above! */ ++ strncpy((char *)sk->secret, (const char *)key, + secretsize); + #endif + if (cache_keyid == keyno) { +@@ -565,7 +576,8 @@ + #ifndef DISABLE_BUG1243_FIX + memcpy(secret, key, secretsize); + #else +- strlcpy((char *)secret, (const char *)key, secretsize); ++ /* >MUST< use 'strncpy()' here! See above! */ ++ strncpy((char *)secret, (const char *)key, secretsize); + #endif + allocsymkey(bucket, keyno, 0, (u_short)keytype, 0, + (u_short)secretsize, secret); +@@ -641,13 +653,13 @@ + * + * Returns length of authenticator field, zero if key not found. + */ +-int ++size_t + authencrypt( + keyid_t keyno, + u_int32 * pkt, +- int length ++ size_t length + ) +-{\ ++{ + /* + * A zero key identifier means the sender has not verified + * the last message was correctly authenticated. The MAC +@@ -675,8 +687,8 @@ + authdecrypt( + keyid_t keyno, + u_int32 * pkt, +- int length, +- int size ++ size_t length, ++ size_t size + ) + { + /* +--- contrib/ntp/libntp/authreadkeys.c.orig ++++ contrib/ntp/libntp/authreadkeys.c +@@ -77,14 +77,23 @@ + * data on global/static level. + */ + +-static const size_t nerr_loglimit = 5u; +-static const size_t nerr_maxlimit = 15; ++static const u_int nerr_loglimit = 5u; ++static const u_int nerr_maxlimit = 15; + +-static void log_maybe(size_t*, const char*, ...) NTP_PRINTF(2, 3); ++static void log_maybe(u_int*, const char*, ...) NTP_PRINTF(2, 3); + ++typedef struct keydata KeyDataT; ++struct keydata { ++ KeyDataT *next; /* queue/stack link */ ++ keyid_t keyid; /* stored key ID */ ++ u_short keytype; /* stored key type */ ++ u_short seclen; /* length of secret */ ++ u_char secbuf[1]; /* begin of secret (formal only)*/ ++}; ++ + static void + log_maybe( +- size_t *pnerr, ++ u_int *pnerr, + const char *fmt , + ...) + { +@@ -113,26 +122,25 @@ + u_char keystr[32]; /* Bug 2537 */ + size_t len; + size_t j; +- size_t nerr; ++ u_int nerr; ++ KeyDataT *list = NULL; ++ KeyDataT *next = NULL; + /* + * Open file. Complain and return if it can't be opened. + */ + fp = fopen(file, "r"); + if (fp == NULL) { +- msyslog(LOG_ERR, "authreadkeys: file %s: %m", ++ msyslog(LOG_ERR, "authreadkeys: file '%s': %m", + file); +- return (0); ++ goto onerror; + } + INIT_SSL(); + + /* +- * Remove all existing keys ++ * Now read lines from the file, looking for key entries. Put ++ * the data into temporary store for later propagation to avoid ++ * two-pass processing. + */ +- auth_delkeys(); +- +- /* +- * Now read lines from the file, looking for key entries +- */ + nerr = 0; + while ((line = fgets(buf, sizeof buf, fp)) != NULL) { + if (nerr > nerr_maxlimit) +@@ -216,11 +224,16 @@ + "authreadkeys: no key for key %d", keyno); + continue; + } ++ next = NULL; + len = strlen(token); + if (len <= 20) { /* Bug 2537 */ +- MD5auth_setkey(keyno, keytype, (u_char *)token, len); ++ next = emalloc(sizeof(KeyDataT) + len); ++ next->keyid = keyno; ++ next->keytype = keytype; ++ next->seclen = len; ++ memcpy(next->secbuf, token, len); + } else { +- char hex[] = "0123456789abcdef"; ++ static const char hex[] = "0123456789abcdef"; + u_char temp; + char *ptr; + size_t jlim; +@@ -242,19 +255,51 @@ + keyno); + continue; + } +- MD5auth_setkey(keyno, keytype, keystr, jlim / 2); ++ len = jlim/2; /* hmmmm.... what about odd length?!? */ ++ next = emalloc(sizeof(KeyDataT) + len); ++ next->keyid = keyno; ++ next->keytype = keytype; ++ next->seclen = len; ++ memcpy(next->secbuf, keystr, len); + } ++ INSIST(NULL != next); ++ next->next = list; ++ list = next; + } + fclose(fp); + if (nerr > nerr_maxlimit) { + msyslog(LOG_ERR, +- "authreadkeys: emergency break after %u errors", +- nerr); +- return (0); +- } else if (nerr > nerr_loglimit) { ++ "authreadkeys: rejecting file '%s' after %u errors (emergency break)", ++ file, nerr); ++ goto onerror; ++ } ++ if (nerr > 0) { + msyslog(LOG_ERR, +- "authreadkeys: found %u more error(s)", +- nerr - nerr_loglimit); ++ "authreadkeys: rejecting file '%s' after %u error(s)", ++ file, nerr); ++ goto onerror; + } ++ ++ /* first remove old file-based keys */ ++ auth_delkeys(); ++ /* insert the new key material */ ++ while (NULL != (next = list)) { ++ list = next->next; ++ MD5auth_setkey(next->keyid, next->keytype, ++ next->secbuf, next->seclen); ++ /* purge secrets from memory before free()ing it */ ++ memset(next, 0, sizeof(*next) + next->seclen); ++ free(next); ++ } + return (1); ++ ++ onerror: ++ /* Mop up temporary storage before bailing out. */ ++ while (NULL != (next = list)) { ++ list = next->next; ++ /* purge secrets from memory before free()ing it */ ++ memset(next, 0, sizeof(*next) + next->seclen); ++ free(next); ++ } ++ return (0); + } +--- contrib/ntp/libntp/authusekey.c.orig ++++ contrib/ntp/libntp/authusekey.c +@@ -23,7 +23,7 @@ + const u_char *str + ) + { +- int len; ++ size_t len; + + len = strlen((const char *)str); + if (0 == len) +--- contrib/ntp/libntp/dolfptoa.c.orig ++++ contrib/ntp/libntp/dolfptoa.c +@@ -40,7 +40,7 @@ + * including a possible rounding from the fractional part. + */ + cp = cpend = cpdec = &cbuf[10]; +- for (dec = cp - cbuf; dec > 0 && fpi != 0; dec--) { ++ for (dec = (int)(cp - cbuf); dec > 0 && fpi != 0; dec--) { + /* can add another digit */ + u_int32 digit; + +@@ -62,7 +62,7 @@ + cpdec += 3; + } + if ((size_t)dec > sizeof(cbuf) - (cpend - cbuf)) +- dec = sizeof(cbuf) - (cpend - cbuf); ++ dec = (int)(sizeof(cbuf) - (cpend - cbuf)); + + /* + * If there's a fraction to deal with, do so. +@@ -95,7 +95,7 @@ + u_char *tp = cpend; + int carry = ((fpv & 0x80000000) != 0); + +- for (dec = tp - cbuf; carry && dec > 0; dec--) { ++ for (dec = (int)(tp - cbuf); carry && dec > 0; dec--) { + *--tp += 1; + if (*tp == 10) + *tp = 0; +--- contrib/ntp/libntp/hextolfp.c.orig ++++ contrib/ntp/libntp/hextolfp.c +@@ -37,8 +37,9 @@ + while (*cp != '\0' && (cp - cpstart) < 8 && + (ind = strchr(digits, *cp)) != NULL) { + dec_i = dec_i << 4; /* multiply by 16 */ +- dec_i += ((ind - digits) > 15) ? (ind - digits) - 6 +- : (ind - digits); ++ dec_i += ((ind - digits) > 15) ++ ? (u_long)(ind - digits - 6) ++ : (u_long)(ind - digits); + cp++; + } + +@@ -51,8 +52,9 @@ + while (*cp != '\0' && (cp - cpstart) < 8 && + (ind = strchr(digits, *cp)) != NULL) { + dec_f = dec_f << 4; /* multiply by 16 */ +- dec_f += ((ind - digits) > 15) ? (ind - digits) - 6 +- : (ind - digits); ++ dec_f += ((ind - digits) > 15) ++ ? (u_long)(ind - digits - 6) ++ : (u_long)(ind - digits); + cp++; + } + +--- contrib/ntp/libntp/mstolfp.c.orig ++++ contrib/ntp/libntp/mstolfp.c +@@ -70,8 +70,7 @@ + */ + *bp++ = '.'; + if ((cpdec - cp) < 3) { +- register int i = 3 - (cpdec - cp); +- ++ size_t i = 3 - (cpdec - cp); + do { + *bp++ = '0'; + } while (--i > 0); +--- contrib/ntp/libntp/msyslog.c.orig ++++ contrib/ntp/libntp/msyslog.c +@@ -331,7 +331,7 @@ + ) + { + va_list ap; +- size_t rc; ++ int rc; + + va_start(ap, fmt); + rc = mvsnprintf(buf, bufsiz, fmt, ap); +--- contrib/ntp/libntp/ntp_crypto_rnd.c.orig ++++ contrib/ntp/libntp/ntp_crypto_rnd.c +@@ -16,6 +16,7 @@ + + #include + #include ++#include "safecast.h" + + #ifdef USE_OPENSSL_CRYPTO_RAND + #include +@@ -93,7 +94,7 @@ + #ifdef USE_OPENSSL_CRYPTO_RAND + int rc; + +- rc = RAND_bytes(buf, nbytes); ++ rc = RAND_bytes(buf, size2int_chk(nbytes)); + if (1 != rc) { + unsigned long err; + char *err_str; +--- contrib/ntp/libntp/ntp_lineedit.c.orig ++++ contrib/ntp/libntp/ntp_lineedit.c +@@ -29,6 +29,7 @@ + #include "ntp.h" + #include "ntp_stdlib.h" + #include "ntp_lineedit.h" ++#include "safecast.h" + + #define MAXEDITLINE 512 + +@@ -213,7 +214,7 @@ + + line = fgets(line_buf, sizeof(line_buf), stdin); + if (NULL != line && *line) { +- *pcount = strlen(line); ++ *pcount = (int)strlen(line); /* cannot overflow here */ + line = estrdup(line); + } else + line = NULL; +--- contrib/ntp/libntp/ntp_rfc2553.c.orig ++++ contrib/ntp/libntp/ntp_rfc2553.c +@@ -203,11 +203,12 @@ + else + ai_nxt = ai_src->ai_next; + *ai_cpy = *ai_src; +- REQUIRE(ai_src->ai_addrlen <= sizeof(sockaddr_u)); ++ DEBUG_INSIST(ai_cpy->ai_canonname == ai_src->ai_canonname); ++ INSIST(ai_src->ai_addrlen <= sizeof(sockaddr_u)); + memcpy(psau, ai_src->ai_addr, ai_src->ai_addrlen); + ai_cpy->ai_addr = &psau->sa; + ++psau; +- if (NULL != ai_cpy->ai_canonname) { ++ if (NULL != ai_src->ai_canonname) { + ai_cpy->ai_canonname = pcanon; + str_octets = 1 + strlen(ai_src->ai_canonname); + memcpy(pcanon, ai_src->ai_canonname, str_octets); +@@ -480,9 +481,9 @@ + * set elsewhere so that we can set the appropriate wildcard + */ + if (nodename == NULL) { +- ai->ai_addrlen = sizeof(struct sockaddr_storage); + if (ai->ai_family == AF_INET) + { ++ ai->ai_addrlen = sizeof(struct sockaddr_in); + sockin = (struct sockaddr_in *)ai->ai_addr; + sockin->sin_family = (short) ai->ai_family; + sockin->sin_addr.s_addr = htonl(INADDR_ANY); +@@ -489,6 +490,7 @@ + } + else + { ++ ai->ai_addrlen = sizeof(struct sockaddr_in6); + sockin6 = (struct sockaddr_in6 *)ai->ai_addr; + sockin6->sin6_family = (short) ai->ai_family; + /* +--- contrib/ntp/libntp/ntp_worker.c.orig ++++ contrib/ntp/libntp/ntp_worker.c +@@ -150,7 +150,8 @@ + prev_octets); + blocking_children_alloc = new_alloc; + +- return prev_alloc; ++ /* assume we'll never have enough workers to overflow u_int */ ++ return (u_int)prev_alloc; + } + + +--- contrib/ntp/libntp/snprintf.c.orig ++++ contrib/ntp/libntp/snprintf.c +@@ -889,19 +889,19 @@ + switch (cflags) { + case PRINT_C_CHAR: + charptr = va_arg(args, signed char *); +- *charptr = len; ++ *charptr = (signed char)len; + break; + case PRINT_C_SHORT: + shortptr = va_arg(args, short int *); +- *shortptr = len; ++ *shortptr = (short int)len; + break; + case PRINT_C_LONG: + longptr = va_arg(args, long int *); +- *longptr = len; ++ *longptr = (long int)len; + break; + case PRINT_C_LLONG: + llongptr = va_arg(args, LLONG *); +- *llongptr = len; ++ *llongptr = (LLONG)len; + break; + case PRINT_C_SIZE: + /* +@@ -912,19 +912,19 @@ + * size_t argument." (7.19.6.1, 7) + */ + sizeptr = va_arg(args, SSIZE_T *); +- *sizeptr = len; ++ *sizeptr = (SSIZE_T)len; + break; + case PRINT_C_INTMAX: + intmaxptr = va_arg(args, INTMAX_T *); +- *intmaxptr = len; ++ *intmaxptr = (INTMAX_T)len; + break; + case PRINT_C_PTRDIFF: + ptrdiffptr = va_arg(args, PTRDIFF_T *); +- *ptrdiffptr = len; ++ *ptrdiffptr = (PTRDIFF_T)len; + break; + default: + intptr = va_arg(args, int *); +- *intptr = len; ++ *intptr = (int)len; + break; + } + break; +@@ -1209,7 +1209,7 @@ + * Factor of ten with the number of digits needed for the fractional + * part. For example, if the precision is 3, the mask will be 1000. + */ +- mask = mypow10(precision); ++ mask = (UINTMAX_T)mypow10(precision); + /* + * We "cheat" by converting the fractional part to integer by + * multiplying by a factor of ten. +@@ -1461,7 +1461,7 @@ + if (value >= UINTMAX_MAX) + return UINTMAX_MAX; + +- result = value; ++ result = (UINTMAX_T)value; + /* + * At least on NetBSD/sparc64 3.0.2 and 4.99.30, casting long double to + * an integer type converts e.g. 1.9 to 2 instead of 1 (which violates +--- contrib/ntp/libntp/socktohost.c.orig ++++ contrib/ntp/libntp/socktohost.c +@@ -36,13 +36,18 @@ + sockaddr_u addr; + size_t octets; + int a_info; ++ int saved_errno; + ++ saved_errno = socket_errno(); ++ + /* reverse the address to purported DNS name */ + LIB_GETBUF(pbuf); + gni_flags = NI_DGRAM | NI_NAMEREQD; + if (getnameinfo(&sock->sa, SOCKLEN(sock), pbuf, LIB_BUFLENGTH, +- NULL, 0, gni_flags)) ++ NULL, 0, gni_flags)) { ++ errno = saved_errno; + return stoa(sock); /* use address */ ++ } + + TRACE(1, ("%s reversed to %s\n", stoa(sock), pbuf)); + +@@ -97,8 +102,10 @@ + } + freeaddrinfo(alist); + +- if (ai != NULL) ++ if (ai != NULL) { ++ errno = saved_errno; + return pbuf; /* forward check passed */ ++ } + + forward_fail: + TRACE(1, ("%s forward check lookup fail: %s\n", pbuf, +@@ -106,5 +113,6 @@ + LIB_GETBUF(pliar); + snprintf(pliar, LIB_BUFLENGTH, "%s (%s)", stoa(sock), pbuf); + ++ errno = saved_errno; + return pliar; + } +--- contrib/ntp/libntp/systime.c.orig ++++ contrib/ntp/libntp/systime.c +@@ -25,6 +25,8 @@ + # include + #endif /* HAVE_UTMPX_H */ + ++int allow_panic = FALSE; /* allow panic correction (-g) */ ++int enable_panic_check = TRUE; /* Can we check allow_panic's state? */ + + #ifndef USE_COMPILETIME_PIVOT + # define USE_COMPILETIME_PIVOT 1 +@@ -295,8 +297,13 @@ + * EVNT_NSET adjtime() can be aborted by a tiny adjtime() + * triggered by sys_residual. + */ +- if (0. == now) ++ if (0. == now) { ++ if (enable_panic_check && allow_panic) { ++ msyslog(LOG_ERR, "adj_systime: allow_panic is TRUE!"); ++ INSIST(!allow_panic); ++ } + return TRUE; ++ } + + /* + * Most Unix adjtime() implementations adjust the system clock +@@ -333,9 +340,15 @@ + if (adjtv.tv_sec != 0 || adjtv.tv_usec != 0) { + if (adjtime(&adjtv, &oadjtv) < 0) { + msyslog(LOG_ERR, "adj_systime: %m"); ++ if (enable_panic_check && allow_panic) { ++ msyslog(LOG_ERR, "adj_systime: allow_panic is TRUE!"); ++ } + return FALSE; + } + } ++ if (enable_panic_check && allow_panic) { ++ msyslog(LOG_ERR, "adj_systime: allow_panic is TRUE!"); ++ } + return TRUE; + } + #endif +@@ -419,6 +432,9 @@ + /* now set new system time */ + if (ntp_set_tod(&timetv, NULL) != 0) { + msyslog(LOG_ERR, "step-systime: %m"); ++ if (enable_panic_check && allow_panic) { ++ msyslog(LOG_ERR, "step_systime: allow_panic is TRUE!"); ++ } + return FALSE; + } + +@@ -445,7 +461,7 @@ + * long ut_time; + * }; + * and appends line="|", name="date", host="", time for the OLD +- * and appends line="{", name="date", host="", time for the NEW ++ * and appends line="{", name="date", host="", time for the NEW // } + * to _PATH_WTMP . + * + * Some OSes have utmp, some have utmpx. +@@ -564,6 +580,10 @@ + #endif /* UPDATE_WTMPX */ + + } ++ if (enable_panic_check && allow_panic) { ++ msyslog(LOG_ERR, "step_systime: allow_panic is TRUE!"); ++ INSIST(!allow_panic); ++ } + return TRUE; + } + +--- contrib/ntp/libntp/work_thread.c.orig ++++ contrib/ntp/libntp/work_thread.c +@@ -32,16 +32,20 @@ + #define THREAD_MINSTACKSIZE (64U * 1024) + #endif + +-#ifndef DEVOLATILE +-#define DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var)) +-#endif ++#ifdef SYS_WINNT + +-#ifdef SYS_WINNT + # define thread_exit(c) _endthreadex(c) +-# define tickle_sem SetEvent ++# define tickle_sem(sh) ReleaseSemaphore((sh->shnd), 1, NULL) ++u_int WINAPI blocking_thread(void *); ++static BOOL same_os_sema(const sem_ref obj, void * osobj); ++ + #else ++ + # define thread_exit(c) pthread_exit((void*)(size_t)(c)) + # define tickle_sem sem_post ++void * blocking_thread(void *); ++static void block_thread_signals(sigset_t *); ++ + #endif + + #ifdef WORK_PIPE +@@ -54,18 +58,10 @@ + static void start_blocking_thread_internal(blocking_child *); + static void prepare_child_sems(blocking_child *); + static int wait_for_sem(sem_ref, struct timespec *); +-static void ensure_workitems_empty_slot(blocking_child *); +-static void ensure_workresp_empty_slot(blocking_child *); ++static int ensure_workitems_empty_slot(blocking_child *); ++static int ensure_workresp_empty_slot(blocking_child *); + static int queue_req_pointer(blocking_child *, blocking_pipe_header *); + static void cleanup_after_child(blocking_child *); +-#ifdef SYS_WINNT +-u_int WINAPI blocking_thread(void *); +-#else +-void * blocking_thread(void *); +-#endif +-#ifndef SYS_WINNT +-static void block_thread_signals(sigset_t *); +-#endif + + + void +@@ -76,7 +72,9 @@ + thread_exit(exitcode); /* see #define thread_exit */ + } + +- ++/* -------------------------------------------------------------------- ++ * sleep for a given time or until the wakup semaphore is tickled. ++ */ + int + worker_sleep( + blocking_child * c, +@@ -98,9 +96,7 @@ + } + # endif + until.tv_sec += seconds; +- do { +- rc = wait_for_sem(c->wake_scheduled_sleep, &until); +- } while (-1 == rc && EINTR == errno); ++ rc = wait_for_sem(c->wake_scheduled_sleep, &until); + if (0 == rc) + return -1; + if (-1 == rc && ETIMEDOUT == errno) +@@ -110,6 +106,9 @@ + } + + ++/* -------------------------------------------------------------------- ++ * Wake up a worker that takes a nap. ++ */ + void + interrupt_worker_sleep(void) + { +@@ -124,65 +123,79 @@ + } + } + +- +-static void ++/* -------------------------------------------------------------------- ++ * Make sure there is an empty slot at the head of the request ++ * queue. Tell if the queue is currently empty. ++ */ ++static int + ensure_workitems_empty_slot( + blocking_child *c + ) + { +- const size_t each = sizeof(blocking_children[0]->workitems[0]); +- size_t new_alloc; +- size_t old_octets; +- size_t new_octets; +- void * nonvol_workitems; ++ /* ++ ** !!! PRECONDITION: caller holds access lock! ++ ** ++ ** This simply tries to increase the size of the buffer if it ++ ** becomes full. The resize operation does *not* maintain the ++ ** order of requests, but that should be irrelevant since the ++ ** processing is considered asynchronous anyway. ++ ** ++ ** Return if the buffer is currently empty. ++ */ ++ ++ static const size_t each = ++ sizeof(blocking_children[0]->workitems[0]); + ++ size_t new_alloc; ++ size_t slots_used; + +- if (c->workitems != NULL && +- NULL == c->workitems[c->next_workitem]) +- return; +- +- new_alloc = c->workitems_alloc + WORKITEMS_ALLOC_INC; +- old_octets = c->workitems_alloc * each; +- new_octets = new_alloc * each; +- nonvol_workitems = DEVOLATILE(void *, c->workitems); +- c->workitems = erealloc_zero(nonvol_workitems, new_octets, +- old_octets); +- if (0 == c->next_workitem) +- c->next_workitem = c->workitems_alloc; +- c->workitems_alloc = new_alloc; ++ slots_used = c->head_workitem - c->tail_workitem; ++ if (slots_used >= c->workitems_alloc) { ++ new_alloc = c->workitems_alloc + WORKITEMS_ALLOC_INC; ++ c->workitems = erealloc(c->workitems, new_alloc * each); ++ c->tail_workitem = 0; ++ c->head_workitem = c->workitems_alloc; ++ c->workitems_alloc = new_alloc; ++ } ++ return (0 == slots_used); + } + +- +-static void ++/* -------------------------------------------------------------------- ++ * Make sure there is an empty slot at the head of the response ++ * queue. Tell if the queue is currently empty. ++ */ ++static int + ensure_workresp_empty_slot( + blocking_child *c + ) + { +- const size_t each = sizeof(blocking_children[0]->responses[0]); +- size_t new_alloc; +- size_t old_octets; +- size_t new_octets; +- void * nonvol_responses; ++ /* ++ ** !!! PRECONDITION: caller holds access lock! ++ ** ++ ** Works like the companion function above. ++ */ ++ ++ static const size_t each = ++ sizeof(blocking_children[0]->responses[0]); + +- if (c->responses != NULL && +- NULL == c->responses[c->next_response]) +- return; ++ size_t new_alloc; ++ size_t slots_used; + +- new_alloc = c->responses_alloc + RESPONSES_ALLOC_INC; +- old_octets = c->responses_alloc * each; +- new_octets = new_alloc * each; +- nonvol_responses = DEVOLATILE(void *, c->responses); +- c->responses = erealloc_zero(nonvol_responses, new_octets, +- old_octets); +- if (0 == c->next_response) +- c->next_response = c->responses_alloc; +- c->responses_alloc = new_alloc; ++ slots_used = c->head_response - c->tail_response; ++ if (slots_used >= c->responses_alloc) { ++ new_alloc = c->responses_alloc + RESPONSES_ALLOC_INC; ++ c->responses = erealloc(c->responses, new_alloc * each); ++ c->tail_response = 0; ++ c->head_response = c->responses_alloc; ++ c->responses_alloc = new_alloc; ++ } ++ return (0 == slots_used); + } + + +-/* ++/* -------------------------------------------------------------------- + * queue_req_pointer() - append a work item or idle exit request to +- * blocking_workitems[]. ++ * blocking_workitems[]. Employ proper locking. + */ + static int + queue_req_pointer( +@@ -190,21 +203,28 @@ + blocking_pipe_header * hdr + ) + { +- c->workitems[c->next_workitem] = hdr; +- c->next_workitem = (1 + c->next_workitem) % c->workitems_alloc; ++ size_t qhead; ++ ++ /* >>>> ACCESS LOCKING STARTS >>>> */ ++ wait_for_sem(c->accesslock, NULL); ++ ensure_workitems_empty_slot(c); ++ qhead = c->head_workitem; ++ c->workitems[qhead % c->workitems_alloc] = hdr; ++ c->head_workitem = 1 + qhead; ++ tickle_sem(c->accesslock); ++ /* <<<< ACCESS LOCKING ENDS <<<< */ + +- /* +- * We only want to signal the wakeup event if the child is +- * blocking on it, which is indicated by setting the blocking +- * event. Wait with zero timeout to test. +- */ +- /* !!!! if (WAIT_OBJECT_0 == WaitForSingleObject(c->child_is_blocking, 0)) */ +- tickle_sem(c->blocking_req_ready); ++ /* queue consumer wake-up notification */ ++ tickle_sem(c->workitems_pending); + + return 0; + } + +- ++/* -------------------------------------------------------------------- ++ * API function to make sure a worker is running, a proper private copy ++ * of the data is made, the data eneterd into the queue and the worker ++ * is signalled. ++ */ + int + send_blocking_req_internal( + blocking_child * c, +@@ -223,12 +243,8 @@ + return 1; /* failure */ + payload_octets = hdr->octets - sizeof(*hdr); + +- ensure_workitems_empty_slot(c); +- if (NULL == c->thread_ref) { +- ensure_workresp_empty_slot(c); ++ if (NULL == c->thread_ref) + start_blocking_thread(c); +- } +- + threadcopy = emalloc(hdr->octets); + memcpy(threadcopy, hdr, sizeof(*hdr)); + memcpy((char *)threadcopy + sizeof(*hdr), data, payload_octets); +@@ -236,7 +252,10 @@ + return queue_req_pointer(c, threadcopy); + } + +- ++/* -------------------------------------------------------------------- ++ * Wait for the 'incoming queue no longer empty' signal, lock the shared ++ * structure and dequeue an item. ++ */ + blocking_pipe_header * + receive_blocking_req_internal( + blocking_child * c +@@ -243,36 +262,31 @@ + ) + { + blocking_pipe_header * req; +- int rc; ++ size_t qhead, qtail; + +- /* +- * Child blocks here when idle. SysV semaphores maintain a +- * count and release from sem_wait() only when it reaches 0. +- * Windows auto-reset events are simpler, and multiple SetEvent +- * calls before any thread waits result in a single wakeup. +- * On Windows, the child drains all workitems each wakeup, while +- * with SysV semaphores wait_sem() is used before each item. +- */ +-#ifdef SYS_WINNT +- while (NULL == c->workitems[c->next_workeritem]) { +- /* !!!! SetEvent(c->child_is_blocking); */ +- rc = wait_for_sem(c->blocking_req_ready, NULL); +- INSIST(0 == rc); +- /* !!!! ResetEvent(c->child_is_blocking); */ +- } +-#else ++ req = NULL; + do { +- rc = wait_for_sem(c->blocking_req_ready, NULL); +- } while (-1 == rc && EINTR == errno); +- INSIST(0 == rc); +-#endif ++ /* wait for tickle from the producer side */ ++ wait_for_sem(c->workitems_pending, NULL); + +- req = c->workitems[c->next_workeritem]; ++ /* >>>> ACCESS LOCKING STARTS >>>> */ ++ wait_for_sem(c->accesslock, NULL); ++ qhead = c->head_workitem; ++ do { ++ qtail = c->tail_workitem; ++ if (qhead == qtail) ++ break; ++ c->tail_workitem = qtail + 1; ++ qtail %= c->workitems_alloc; ++ req = c->workitems[qtail]; ++ c->workitems[qtail] = NULL; ++ } while (NULL == req); ++ tickle_sem(c->accesslock); ++ /* <<<< ACCESS LOCKING ENDS <<<< */ ++ ++ } while (NULL == req); ++ + INSIST(NULL != req); +- c->workitems[c->next_workeritem] = NULL; +- c->next_workeritem = (1 + c->next_workeritem) % +- c->workitems_alloc; +- + if (CHILD_EXIT_REQ == req) { /* idled out */ + send_blocking_resp_internal(c, CHILD_GONE_RESP); + req = NULL; +@@ -281,7 +295,10 @@ + return req; + } + +- ++/* -------------------------------------------------------------------- ++ * Push a response into the return queue and eventually tickle the ++ * receiver. ++ */ + int + send_blocking_resp_internal( + blocking_child * c, +@@ -288,37 +305,64 @@ + blocking_pipe_header * resp + ) + { +- ensure_workresp_empty_slot(c); ++ size_t qhead; ++ int empty; ++ ++ /* >>>> ACCESS LOCKING STARTS >>>> */ ++ wait_for_sem(c->accesslock, NULL); ++ empty = ensure_workresp_empty_slot(c); ++ qhead = c->head_response; ++ c->responses[qhead % c->responses_alloc] = resp; ++ c->head_response = 1 + qhead; ++ tickle_sem(c->accesslock); ++ /* <<<< ACCESS LOCKING ENDS <<<< */ + +- c->responses[c->next_response] = resp; +- c->next_response = (1 + c->next_response) % c->responses_alloc; +- +-#ifdef WORK_PIPE +- write(c->resp_write_pipe, "", 1); +-#else +- tickle_sem(c->blocking_response_ready); +-#endif +- ++ /* queue consumer wake-up notification */ ++ if (empty) ++ { ++# ifdef WORK_PIPE ++ write(c->resp_write_pipe, "", 1); ++# else ++ tickle_sem(c->responses_pending); ++# endif ++ } + return 0; + } + + + #ifndef WORK_PIPE ++ ++/* -------------------------------------------------------------------- ++ * Check if a (Windows-)hanndle to a semaphore is actually the same we ++ * are using inside the sema wrapper. ++ */ ++static BOOL ++same_os_sema( ++ const sem_ref obj, ++ void* osh ++ ) ++{ ++ return obj && osh && (obj->shnd == (HANDLE)osh); ++} ++ ++/* -------------------------------------------------------------------- ++ * Find the shared context that associates to an OS handle and make sure ++ * the data is dequeued and processed. ++ */ + void + handle_blocking_resp_sem( + void * context + ) + { +- HANDLE ready; + blocking_child * c; + u_int idx; + +- ready = (HANDLE)context; + c = NULL; + for (idx = 0; idx < blocking_children_alloc; idx++) { + c = blocking_children[idx]; +- if (c != NULL && c->thread_ref != NULL && +- ready == c->blocking_response_ready) ++ if (c != NULL && ++ c->thread_ref != NULL && ++ same_os_sema(c->responses_pending, context)) + break; + } + if (idx < blocking_children_alloc) +@@ -326,7 +370,10 @@ + } + #endif /* !WORK_PIPE */ + +- ++/* -------------------------------------------------------------------- ++ * Fetch the next response from the return queue. In case of signalling ++ * via pipe, make sure the pipe is flushed, too. ++ */ + blocking_pipe_header * + receive_blocking_resp_internal( + blocking_child * c +@@ -333,19 +380,31 @@ + ) + { + blocking_pipe_header * removed; ++ size_t qhead, qtail, slot; ++ + #ifdef WORK_PIPE + int rc; + char scratch[32]; + +- do { ++ do + rc = read(c->resp_read_pipe, scratch, sizeof(scratch)); +- } while (-1 == rc && EINTR == errno); ++ while (-1 == rc && EINTR == errno); + #endif +- removed = c->responses[c->next_workresp]; ++ ++ /* >>>> ACCESS LOCKING STARTS >>>> */ ++ wait_for_sem(c->accesslock, NULL); ++ qhead = c->head_response; ++ qtail = c->tail_response; ++ for (removed = NULL; !removed && (qhead != qtail); ++qtail) { ++ slot = qtail % c->responses_alloc; ++ removed = c->responses[slot]; ++ c->responses[slot] = NULL; ++ } ++ c->tail_response = qtail; ++ tickle_sem(c->accesslock); ++ /* <<<< ACCESS LOCKING ENDS <<<< */ ++ + if (NULL != removed) { +- c->responses[c->next_workresp] = NULL; +- c->next_workresp = (1 + c->next_workresp) % +- c->responses_alloc; + DEBUG_ENSURE(CHILD_GONE_RESP == removed || + BLOCKING_RESP_MAGIC == removed->magic_sig); + } +@@ -357,7 +416,9 @@ + return removed; + } + +- ++/* -------------------------------------------------------------------- ++ * Light up a new worker. ++ */ + static void + start_blocking_thread( + blocking_child * c +@@ -370,7 +431,14 @@ + start_blocking_thread_internal(c); + } + +- ++/* -------------------------------------------------------------------- ++ * Create a worker thread. There are several differences between POSIX ++ * and Windows, of course -- most notably the Windows thread is no ++ * detached thread, and we keep the handle around until we want to get ++ * rid of the thread. The notification scheme also differs: Windows ++ * makes use of semaphores in both directions, POSIX uses a pipe for ++ * integration with 'select()' or alike. ++ */ + static void + start_blocking_thread_internal( + blocking_child * c +@@ -377,12 +445,11 @@ + ) + #ifdef SYS_WINNT + { +- thr_ref blocking_child_thread; +- u_int blocking_thread_id; + BOOL resumed; + +- (*addremove_io_semaphore)(c->blocking_response_ready, FALSE); +- blocking_child_thread = ++ c->thread_ref = NULL; ++ (*addremove_io_semaphore)(c->responses_pending->shnd, FALSE); ++ c->thr_table[0].thnd = + (HANDLE)_beginthreadex( + NULL, + 0, +@@ -389,21 +456,20 @@ + &blocking_thread, + c, + CREATE_SUSPENDED, +- &blocking_thread_id); ++ NULL); + +- if (NULL == blocking_child_thread) { ++ if (NULL == c->thr_table[0].thnd) { + msyslog(LOG_ERR, "start blocking thread failed: %m"); + exit(-1); + } +- c->thread_id = blocking_thread_id; +- c->thread_ref = blocking_child_thread; + /* remember the thread priority is only within the process class */ +- if (!SetThreadPriority(blocking_child_thread, ++ if (!SetThreadPriority(c->thr_table[0].thnd, + THREAD_PRIORITY_BELOW_NORMAL)) + msyslog(LOG_ERR, "Error lowering blocking thread priority: %m"); + +- resumed = ResumeThread(blocking_child_thread); ++ resumed = ResumeThread(c->thr_table[0].thnd); + DEBUG_INSIST(resumed); ++ c->thread_ref = &c->thr_table[0]; + } + #else /* pthreads start_blocking_thread_internal() follows */ + { +@@ -419,6 +485,8 @@ + size_t stacksize; + sigset_t saved_sig_mask; + ++ c->thread_ref = NULL; ++ + # ifdef NEED_PTHREAD_INIT + /* + * from lib/isc/unix/app.c: +@@ -475,7 +543,7 @@ + #endif + c->thread_ref = emalloc_zero(sizeof(*c->thread_ref)); + block_thread_signals(&saved_sig_mask); +- rc = pthread_create(c->thread_ref, &thr_attr, ++ rc = pthread_create(&c->thr_table[0], &thr_attr, + &blocking_thread, c); + saved_errno = errno; + pthread_sigmask(SIG_SETMASK, &saved_sig_mask, NULL); +@@ -485,11 +553,11 @@ + msyslog(LOG_ERR, "pthread_create() blocking child: %m"); + exit(1); + } ++ c->thread_ref = &c->thr_table[0]; + } + #endif + +- +-/* ++/* -------------------------------------------------------------------- + * block_thread_signals() + * + * Temporarily block signals used by ntpd main thread, so that signal +@@ -538,61 +606,101 @@ + #endif /* !SYS_WINNT */ + + +-/* ++/* -------------------------------------------------------------------- ++ * Create & destroy semaphores. This is sufficiently different between ++ * POSIX and Windows to warrant wrapper functions and close enough to ++ * use the concept of synchronization via semaphore for all platforms. ++ */ ++static sem_ref ++create_sema( ++ sema_type* semptr, ++ u_int inival, ++ u_int maxval) ++{ ++#ifdef SYS_WINNT ++ ++ long svini, svmax; ++ if (NULL != semptr) { ++ svini = (inival < LONG_MAX) ++ ? (long)inival : LONG_MAX; ++ svmax = (maxval < LONG_MAX && maxval > 0) ++ ? (long)maxval : LONG_MAX; ++ semptr->shnd = CreateSemaphore(NULL, svini, svmax, NULL); ++ if (NULL == semptr->shnd) ++ semptr = NULL; ++ } ++ ++#else ++ ++ (void)maxval; ++ if (semptr && sem_init(semptr, FALSE, inival)) ++ semptr = NULL; ++ ++#endif ++ ++ return semptr; ++} ++ ++/* ------------------------------------------------------------------ */ ++static sem_ref ++delete_sema( ++ sem_ref obj) ++{ ++ ++# ifdef SYS_WINNT ++ ++ if (obj) { ++ if (obj->shnd) ++ CloseHandle(obj->shnd); ++ obj->shnd = NULL; ++ } ++ ++# else ++ ++ if (obj) ++ sem_destroy(obj); ++ ++# endif ++ ++ return NULL; ++} ++ ++/* -------------------------------------------------------------------- + * prepare_child_sems() + * +- * create sync events (semaphores) +- * child_is_blocking initially unset +- * blocking_req_ready initially unset ++ * create sync & access semaphores + * +- * Child waits for blocking_req_ready to be set after +- * setting child_is_blocking. blocking_req_ready and +- * blocking_response_ready are auto-reset, so wake one +- * waiter and become unset (unsignalled) in one operation. ++ * All semaphores are cleared, only the access semaphore has 1 unit. ++ * Childs wait on 'workitems_pending', then grabs 'sema_access' ++ * and dequeues jobs. When done, 'sema_access' is given one unit back. ++ * ++ * The producer grabs 'sema_access', manages the queue, restores ++ * 'sema_access' and puts one unit into 'workitems_pending'. ++ * ++ * The story goes the same for the response queue. + */ + static void + prepare_child_sems( + blocking_child *c + ) +-#ifdef SYS_WINNT + { +- if (NULL == c->blocking_req_ready) { +- /* manual reset using ResetEvent() */ +- /* !!!! c->child_is_blocking = CreateEvent(NULL, TRUE, FALSE, NULL); */ +- /* auto reset - one thread released from wait each set */ +- c->blocking_req_ready = CreateEvent(NULL, FALSE, FALSE, NULL); +- c->blocking_response_ready = CreateEvent(NULL, FALSE, FALSE, NULL); +- c->wake_scheduled_sleep = CreateEvent(NULL, FALSE, FALSE, NULL); +- } else { +- /* !!!! ResetEvent(c->child_is_blocking); */ +- /* ResetEvent(c->blocking_req_ready); */ +- /* ResetEvent(c->blocking_response_ready); */ +- /* ResetEvent(c->wake_scheduled_sleep); */ +- } ++ c->accesslock = create_sema(&c->sem_table[0], 1, 1); ++ c->workitems_pending = create_sema(&c->sem_table[1], 0, 0); ++ c->wake_scheduled_sleep = create_sema(&c->sem_table[2], 0, 1); ++# ifndef WORK_PIPE ++ c->responses_pending = create_sema(&c->sem_table[3], 0, 0); ++# endif + } +-#else /* pthreads prepare_child_sems() follows */ +-{ +- size_t octets; + +- if (NULL == c->blocking_req_ready) { +- octets = sizeof(*c->blocking_req_ready); +- octets += sizeof(*c->wake_scheduled_sleep); +- /* !!!! octets += sizeof(*c->child_is_blocking); */ +- c->blocking_req_ready = emalloc_zero(octets);; +- c->wake_scheduled_sleep = 1 + c->blocking_req_ready; +- /* !!!! c->child_is_blocking = 1 + c->wake_scheduled_sleep; */ +- } else { +- sem_destroy(c->blocking_req_ready); +- sem_destroy(c->wake_scheduled_sleep); +- /* !!!! sem_destroy(c->child_is_blocking); */ +- } +- sem_init(c->blocking_req_ready, FALSE, 0); +- sem_init(c->wake_scheduled_sleep, FALSE, 0); +- /* !!!! sem_init(c->child_is_blocking, FALSE, 0); */ +-} +-#endif +- +- ++/* -------------------------------------------------------------------- ++ * wait for semaphore. Where the wait can be interrupted, it will ++ * internally resume -- When this function returns, there is either no ++ * semaphore at all, a timeout occurred, or the caller could ++ * successfully take a token from the semaphore. ++ * ++ * For untimed wait, not checking the result of this function at all is ++ * definitely an option. ++ */ + static int + wait_for_sem( + sem_ref sem, +@@ -605,6 +713,11 @@ + DWORD msec; + DWORD rc; + ++ if (!(sem && sem->shnd)) { ++ errno = EINVAL; ++ return -1; ++ } ++ + if (NULL == timeout) { + msec = INFINITE; + } else { +@@ -619,7 +732,7 @@ + msec += delta.tv_nsec / (1000 * 1000); + } + } +- rc = WaitForSingleObject(sem, msec); ++ rc = WaitForSingleObject(sem->shnd, msec); + if (WAIT_OBJECT_0 == rc) + return 0; + if (WAIT_TIMEOUT == rc) { +@@ -632,24 +745,28 @@ + } + #else /* pthreads wait_for_sem() follows */ + { +- int rc; ++ int rc = -1; + +- if (NULL == timeout) +- rc = sem_wait(sem); ++ if (sem) do { ++ if (NULL == timeout) ++ rc = sem_wait(sem); ++ else ++ rc = sem_timedwait(sem, timeout); ++ } while (rc == -1 && errno == EINTR); + else +- rc = sem_timedwait(sem, timeout); +- ++ errno = EINVAL; ++ + return rc; + } + #endif + +- +-/* +- * blocking_thread - thread functions have WINAPI calling convention ++/* -------------------------------------------------------------------- ++ * blocking_thread - thread functions have WINAPI (aka 'stdcall') ++ * calling conventions under Windows and POSIX-defined signature ++ * otherwise. + */ + #ifdef SYS_WINNT +-u_int +-WINAPI ++u_int WINAPI + #else + void * + #endif +@@ -666,9 +783,16 @@ + return 0; + } + +- +-/* ++/* -------------------------------------------------------------------- + * req_child_exit() runs in the parent. ++ * ++ * This function is called from from the idle timer, too, and possibly ++ * without a thread being there any longer. Since we have folded up our ++ * tent in that case and all the semaphores are already gone, we simply ++ * ignore this request in this case. ++ * ++ * Since the existence of the semaphores is controlled exclusively by ++ * the parent, there's no risk of data race here. + */ + int + req_child_exit( +@@ -675,11 +799,12 @@ + blocking_child *c + ) + { +- return queue_req_pointer(c, CHILD_EXIT_REQ); ++ return (c->accesslock) ++ ? queue_req_pointer(c, CHILD_EXIT_REQ) ++ : 0; + } + +- +-/* ++/* -------------------------------------------------------------------- + * cleanup_after_child() runs in parent. + */ + static void +@@ -687,17 +812,27 @@ + blocking_child * c + ) + { +- u_int idx; +- + DEBUG_INSIST(!c->reusable); +-#ifdef SYS_WINNT +- INSIST(CloseHandle(c->thread_ref)); +-#else +- free(c->thread_ref); +-#endif ++ ++# ifdef SYS_WINNT ++ /* The thread was not created in detached state, so we better ++ * clean up. ++ */ ++ if (c->thread_ref && c->thread_ref->thnd) { ++ WaitForSingleObject(c->thread_ref->thnd, INFINITE); ++ INSIST(CloseHandle(c->thread_ref->thnd)); ++ c->thread_ref->thnd = NULL; ++ } ++# endif + c->thread_ref = NULL; +- c->thread_id = 0; +-#ifdef WORK_PIPE ++ ++ /* remove semaphores and (if signalling vi IO) pipes */ ++ ++ c->accesslock = delete_sema(c->accesslock); ++ c->workitems_pending = delete_sema(c->workitems_pending); ++ c->wake_scheduled_sleep = delete_sema(c->wake_scheduled_sleep); ++ ++# ifdef WORK_PIPE + DEBUG_INSIST(-1 != c->resp_read_pipe); + DEBUG_INSIST(-1 != c->resp_write_pipe); + (*addremove_io_fd)(c->resp_read_pipe, c->ispipe, TRUE); +@@ -705,18 +840,22 @@ + close(c->resp_read_pipe); + c->resp_write_pipe = -1; + c->resp_read_pipe = -1; +-#else +- DEBUG_INSIST(NULL != c->blocking_response_ready); +- (*addremove_io_semaphore)(c->blocking_response_ready, TRUE); +-#endif +- for (idx = 0; idx < c->workitems_alloc; idx++) +- c->workitems[idx] = NULL; +- c->next_workitem = 0; +- c->next_workeritem = 0; +- for (idx = 0; idx < c->responses_alloc; idx++) +- c->responses[idx] = NULL; +- c->next_response = 0; +- c->next_workresp = 0; ++# else ++ DEBUG_INSIST(NULL != c->responses_pending); ++ (*addremove_io_semaphore)(c->responses_pending->shnd, TRUE); ++ c->responses_pending = delete_sema(c->responses_pending); ++# endif ++ ++ /* Is it necessary to check if there are pending requests and ++ * responses? If so, and if there are, what to do with them? ++ */ ++ ++ /* re-init buffer index sequencers */ ++ c->head_workitem = 0; ++ c->tail_workitem = 0; ++ c->head_response = 0; ++ c->tail_response = 0; ++ + c->reusable = TRUE; + } + +--- contrib/ntp/libparse/clk_computime.c.orig ++++ contrib/ntp/libparse/clk_computime.c +@@ -157,7 +157,7 @@ + { + unsigned int rtc; + +- parseprintf(DD_PARSE, ("inp_computime(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); ++ parseprintf(DD_PARSE, ("inp_computime(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); + + switch (ch) + { +--- contrib/ntp/libparse/clk_dcf7000.c.orig ++++ contrib/ntp/libparse/clk_dcf7000.c +@@ -158,7 +158,7 @@ + { + unsigned int rtc; + +- parseprintf(DD_PARSE, ("inp_dcf7000(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); ++ parseprintf(DD_PARSE, ("inp_dcf7000(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); + + switch (ch) + { +--- contrib/ntp/libparse/clk_hopf6021.c.orig ++++ contrib/ntp/libparse/clk_hopf6021.c +@@ -227,7 +227,7 @@ + { + unsigned int rtc; + +- parseprintf(DD_PARSE, ("inp_hopf6021(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); ++ parseprintf(DD_PARSE, ("inp_hopf6021(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); + + switch (ch) + { +--- contrib/ntp/libparse/clk_meinberg.c.orig ++++ contrib/ntp/libparse/clk_meinberg.c +@@ -434,7 +434,7 @@ + { + unsigned int rtc; + +- parseprintf(DD_PARSE, ("mbg_input(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); ++ parseprintf(DD_PARSE, ("mbg_input(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); + + switch (ch) + { +@@ -602,7 +602,7 @@ + + msg_buf = (struct msg_buf *)parseio->parse_pdata; + +- parseprintf(DD_PARSE, ("gps_input(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); ++ parseprintf(DD_PARSE, ("gps_input(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); + + if (!msg_buf) + return PARSE_INP_SKIP; +--- contrib/ntp/libparse/clk_rawdcf.c.orig ++++ contrib/ntp/libparse/clk_rawdcf.c +@@ -627,7 +627,7 @@ + { + static struct timeval timeout = { 1, 500000 }; /* 1.5 secongs denote second #60 */ + +- parseprintf(DD_PARSE, ("inp_rawdcf(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); ++ parseprintf(DD_PARSE, ("inp_rawdcf(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); + + parseio->parse_dtime.parse_stime = *tstamp; /* collect timestamp */ + +--- contrib/ntp/libparse/clk_rcc8000.c.orig ++++ contrib/ntp/libparse/clk_rcc8000.c +@@ -141,7 +141,7 @@ + { + unsigned int rtc; + +- parseprintf(DD_PARSE, ("inp_rcc8000(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); ++ parseprintf(DD_PARSE, ("inp_rcc8000(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); + + switch (ch) + { +--- contrib/ntp/libparse/clk_schmid.c.orig ++++ contrib/ntp/libparse/clk_schmid.c +@@ -205,7 +205,7 @@ + { + unsigned int rtc; + +- parseprintf(DD_PARSE, ("inp_schmid(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); ++ parseprintf(DD_PARSE, ("inp_schmid(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); + + switch ((uint8_t)ch) + { +--- contrib/ntp/libparse/clk_trimtaip.c.orig ++++ contrib/ntp/libparse/clk_trimtaip.c +@@ -155,7 +155,7 @@ + { + unsigned int rtc; + +- parseprintf(DD_PARSE, ("inp_trimtaip(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); ++ parseprintf(DD_PARSE, ("inp_trimtaip(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); + + switch (ch) + { +--- contrib/ntp/libparse/clk_varitext.c.orig ++++ contrib/ntp/libparse/clk_varitext.c +@@ -58,12 +58,12 @@ + extern int printf (const char *, ...); + #endif + +-static const u_char VT_INITIALISED = 0x01; +-static const u_char VT_SYNCHRONISED = 0x02; +-static const u_char VT_ALARM_STATE = 0x04; ++/* static const u_char VT_INITIALISED = 0x01; */ ++/* static const u_char VT_SYNCHRONISED = 0x02; */ ++/* static const u_char VT_ALARM_STATE = 0x04; */ + static const u_char VT_BST = 0x08; +-static const u_char VT_SEASON_CHANGE = 0x10; +-static const u_char VT_LAST_TELEGRAM_OK = 0x20; ++/* static const u_char VT_SEASON_CHANGE = 0x10; */ ++/* static const u_char VT_LAST_TELEGRAM_OK = 0x20; */ + + /* + * The Varitext receiver sends a datagram in the following format every minute +@@ -195,7 +195,7 @@ + struct varitext *t = (struct varitext *)parseio->parse_pdata; + int rtc; + +- parseprintf(DD_PARSE, ("inp_varitext(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); ++ parseprintf(DD_PARSE, ("inp_varitext(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); + + if (!t) + return PARSE_INP_SKIP; /* local data not allocated - sigh! */ +--- contrib/ntp/libparse/clk_wharton.c.orig ++++ contrib/ntp/libparse/clk_wharton.c +@@ -137,7 +137,7 @@ + { + unsigned int rtc; + +- parseprintf(DD_PARSE, ("inp_wharton_400a(0x%lx, 0x%x, ...)\n", (long)parseio, ch)); ++ parseprintf(DD_PARSE, ("inp_wharton_400a(0x%p, 0x%x, ...)\n", (void*)parseio, ch)); + + switch (ch) + { +--- contrib/ntp/libparse/parse.c.orig ++++ contrib/ntp/libparse/parse.c +@@ -288,7 +288,7 @@ + break; + } + +- parseprintf(DD_PARSE, ("parse_ioread(0x%lx, char=0x%x, ..., ...)\n", (unsigned long)parseio, ch & 0xFF)); ++ parseprintf(DD_PARSE, ("parse_ioread(0x%p, char=0x%x, ..., ...)\n", (void*)parseio, ch & 0xFF)); + + if (!clockformats[parseio->parse_lformat]->convert) + { +--- contrib/ntp/ntpd/invoke-ntp.conf.texi.orig ++++ contrib/ntp/ntpd/invoke-ntp.conf.texi +@@ -6,7 +6,7 @@ + # + # EDIT THIS FILE WITH CAUTION (invoke-ntp.conf.texi) + # +-# It has been AutoGen-ed October 21, 2015 at 12:38:16 PM by AutoGen 5.18.5 ++# It has been AutoGen-ed January 7, 2016 at 11:30:49 PM by AutoGen 5.18.5 + # From the definitions ntp.conf.def + # and the template file agtexi-file.tpl + @end ignore +--- contrib/ntp/ntpd/invoke-ntp.keys.texi.orig ++++ contrib/ntp/ntpd/invoke-ntp.keys.texi +@@ -6,7 +6,7 @@ + # + # EDIT THIS FILE WITH CAUTION (invoke-ntp.keys.texi) + # +-# It has been AutoGen-ed October 21, 2015 at 12:38:19 PM by AutoGen 5.18.5 ++# It has been AutoGen-ed January 7, 2016 at 11:30:52 PM by AutoGen 5.18.5 + # From the definitions ntp.keys.def + # and the template file agtexi-file.tpl + @end ignore +--- contrib/ntp/ntpd/invoke-ntpd.texi.orig ++++ contrib/ntp/ntpd/invoke-ntpd.texi +@@ -6,7 +6,7 @@ + # + # EDIT THIS FILE WITH CAUTION (invoke-ntpd.texi) + # +-# It has been AutoGen-ed October 21, 2015 at 12:38:21 PM by AutoGen 5.18.5 ++# It has been AutoGen-ed January 7, 2016 at 11:30:54 PM by AutoGen 5.18.5 + # From the definitions ntpd-opts.def + # and the template file agtexi-cmd.tpl + @end ignore +@@ -142,7 +142,7 @@ + + @exampleindent 0 + @example +-ntpd - NTP daemon program - Ver. 4.2.8p4 ++ntpd - NTP daemon program - Ver. 4.2.8p5 + Usage: ntpd [ - [] | --[@{=| @}] ]... \ + [ ... ] + Flg Arg Option-Name Description +--- contrib/ntp/ntpd/ntp.conf.5man.orig ++++ contrib/ntp/ntpd/ntp.conf.5man +@@ -10,11 +10,11 @@ + .ds B-Font B + .ds I-Font I + .ds R-Font R +-.TH ntp.conf 5man "21 Oct 2015" "4.2.8p4" "File Formats" ++.TH ntp.conf 5man "07 Jan 2016" "4.2.8p5" "File Formats" + .\" +-.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-9oaqYI/ag-OpaiXI) ++.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-8qayqp/ag-Vraqpp) + .\" +-.\" It has been AutoGen-ed October 21, 2015 at 12:38:01 PM by AutoGen 5.18.5 ++.\" It has been AutoGen-ed January 7, 2016 at 11:30:35 PM by AutoGen 5.18.5 + .\" From the definitions ntp.conf.def + .\" and the template file agman-cmd.tpl + .SH NAME +--- contrib/ntp/ntpd/ntp.conf.5mdoc.orig ++++ contrib/ntp/ntpd/ntp.conf.5mdoc +@@ -1,9 +1,9 @@ +-.Dd October 21 2015 ++.Dd January 7 2016 + .Dt NTP_CONF 5mdoc File Formats + .Os + .\" EDIT THIS FILE WITH CAUTION (ntp.mdoc) + .\" +-.\" It has been AutoGen-ed October 21, 2015 at 12:38:24 PM by AutoGen 5.18.5 ++.\" It has been AutoGen-ed January 7, 2016 at 11:30:57 PM by AutoGen 5.18.5 + .\" From the definitions ntp.conf.def + .\" and the template file agmdoc-cmd.tpl + .Sh NAME +--- contrib/ntp/ntpd/ntp.conf.html.orig ++++ contrib/ntp/ntpd/ntp.conf.html +@@ -33,7 +33,7 @@ +

This document describes the configuration file for the NTP Project's + ntpd program. + +-

This document applies to version 4.2.8p4 of ntp.conf. ++

This document applies to version 4.2.8p5 of ntp.conf. + +

+

Short Contents

+--- contrib/ntp/ntpd/ntp.conf.man.in.orig ++++ contrib/ntp/ntpd/ntp.conf.man.in +@@ -10,11 +10,11 @@ + .ds B-Font B + .ds I-Font I + .ds R-Font R +-.TH ntp.conf 5 "21 Oct 2015" "4.2.8p4" "File Formats" ++.TH ntp.conf 5 "07 Jan 2016" "4.2.8p5" "File Formats" + .\" +-.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-9oaqYI/ag-OpaiXI) ++.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-8qayqp/ag-Vraqpp) + .\" +-.\" It has been AutoGen-ed October 21, 2015 at 12:38:01 PM by AutoGen 5.18.5 ++.\" It has been AutoGen-ed January 7, 2016 at 11:30:35 PM by AutoGen 5.18.5 + .\" From the definitions ntp.conf.def + .\" and the template file agman-cmd.tpl + .SH NAME +--- contrib/ntp/ntpd/ntp.conf.mdoc.in.orig ++++ contrib/ntp/ntpd/ntp.conf.mdoc.in +@@ -1,9 +1,9 @@ +-.Dd October 21 2015 ++.Dd January 7 2016 + .Dt NTP_CONF 5 File Formats + .Os + .\" EDIT THIS FILE WITH CAUTION (ntp.mdoc) + .\" +-.\" It has been AutoGen-ed October 21, 2015 at 12:38:24 PM by AutoGen 5.18.5 ++.\" It has been AutoGen-ed January 7, 2016 at 11:30:57 PM by AutoGen 5.18.5 + .\" From the definitions ntp.conf.def + .\" and the template file agmdoc-cmd.tpl + .Sh NAME +--- contrib/ntp/ntpd/ntp.keys.5man.orig ++++ contrib/ntp/ntpd/ntp.keys.5man +@@ -1,8 +1,8 @@ +-.TH ntp.keys 5man "21 Oct 2015" "4.2.8p4" "File Formats" ++.TH ntp.keys 5man "07 Jan 2016" "4.2.8p5" "File Formats" + .\" + .\" EDIT THIS FILE WITH CAUTION (ntp.man) + .\" +-.\" It has been AutoGen-ed October 21, 2015 at 12:38:08 PM by AutoGen 5.18.5 ++.\" It has been AutoGen-ed January 7, 2016 at 11:30:41 PM by AutoGen 5.18.5 + .\" From the definitions ntp.keys.def + .\" and the template file agman-file.tpl + .Sh NAME +--- contrib/ntp/ntpd/ntp.keys.5mdoc.orig ++++ contrib/ntp/ntpd/ntp.keys.5mdoc +@@ -1,9 +1,9 @@ +-.Dd October 21 2015 ++.Dd January 7 2016 + .Dt NTP_KEYS 5mdoc File Formats + .Os SunOS 5.10 + .\" EDIT THIS FILE WITH CAUTION (ntp.mdoc) + .\" +-.\" It has been AutoGen-ed October 21, 2015 at 12:38:28 PM by AutoGen 5.18.5 ++.\" It has been AutoGen-ed January 7, 2016 at 11:31:00 PM by AutoGen 5.18.5 + .\" From the definitions ntp.keys.def + .\" and the template file agmdoc-file.tpl + .Sh NAME +--- contrib/ntp/ntpd/ntp.keys.html.orig ++++ contrib/ntp/ntpd/ntp.keys.html +@@ -33,7 +33,7 @@ +

This document describes the symmetric key file for the NTP Project's + ntpd program. + +-

This document applies to version 4.2.8p4 of ntp.keys. ++

This document applies to version 4.2.8p5 of ntp.keys. + +

+

Short Contents

+--- contrib/ntp/ntpd/ntp.keys.man.in.orig ++++ contrib/ntp/ntpd/ntp.keys.man.in +@@ -1,8 +1,8 @@ +-.TH ntp.keys 5 "21 Oct 2015" "4.2.8p4" "File Formats" ++.TH ntp.keys 5 "07 Jan 2016" "4.2.8p5" "File Formats" + .\" + .\" EDIT THIS FILE WITH CAUTION (ntp.man) + .\" +-.\" It has been AutoGen-ed October 21, 2015 at 12:38:08 PM by AutoGen 5.18.5 ++.\" It has been AutoGen-ed January 7, 2016 at 11:30:41 PM by AutoGen 5.18.5 + .\" From the definitions ntp.keys.def + .\" and the template file agman-file.tpl + .Sh NAME +--- contrib/ntp/ntpd/ntp.keys.mdoc.in.orig ++++ contrib/ntp/ntpd/ntp.keys.mdoc.in +@@ -1,9 +1,9 @@ +-.Dd October 21 2015 ++.Dd January 7 2016 + .Dt NTP_KEYS 5 File Formats + .Os SunOS 5.10 + .\" EDIT THIS FILE WITH CAUTION (ntp.mdoc) + .\" +-.\" It has been AutoGen-ed October 21, 2015 at 12:38:28 PM by AutoGen 5.18.5 ++.\" It has been AutoGen-ed January 7, 2016 at 11:31:00 PM by AutoGen 5.18.5 + .\" From the definitions ntp.keys.def + .\" and the template file agmdoc-file.tpl + .Sh NAME +--- contrib/ntp/ntpd/ntp_control.c.orig ++++ contrib/ntp/ntpd/ntp_control.c +@@ -846,7 +846,7 @@ + u_char errcode + ) + { +- int maclen; ++ size_t maclen; + + numctlerrors++; + DPRINTF(3, ("sending control error %u\n", errcode)); +@@ -1248,10 +1248,10 @@ + ) + { + size_t i; +- int dlen; +- int sendlen; +- int maclen; +- int totlen; ++ size_t dlen; ++ size_t sendlen; ++ size_t maclen; ++ size_t totlen; + keyid_t keyid; + + dlen = datapt - rpkt.u.data; +--- contrib/ntp/ntpd/ntp_crypto.c.orig ++++ contrib/ntp/ntpd/ntp_crypto.c +@@ -473,9 +473,9 @@ + } + + /* Check if the declared size fits into the remaining +- * buffer. ++ * buffer. We *know* 'macbytes' > 0 here! + */ +- if (len > macbytes) { ++ if (len > (u_int)macbytes) { + DPRINTF(1, ("crypto_recv: possible attack detected, associd %d\n", + associd)); + return XEVNT_LEN; +--- contrib/ntp/ntpd/ntp_io.c.orig ++++ contrib/ntp/ntpd/ntp_io.c +@@ -41,6 +41,7 @@ + #include "timevalops.h" + #include "timespecops.h" + #include "ntpd-opts.h" ++#include "safecast.h" + + /* Don't include ISC's version of IPv6 variables and structures */ + #define ISC_IPV6_H 1 +@@ -772,7 +773,7 @@ + hints.ai_flags |= AI_NUMERICHOST; + if (getaddrinfo(tmpbuf, NULL, &hints, &result) == 0) { + AF(addr) = AF_INET6; +- resaddr6 = (struct sockaddr_in6 *)result->ai_addr; ++ resaddr6 = UA_PTR(struct sockaddr_in6, result->ai_addr); + SET_ADDR6N(addr, resaddr6->sin6_addr); + SET_SCOPE(addr, resaddr6->sin6_scope_id); + +@@ -3365,7 +3366,7 @@ + #endif /* HAVE_BINTIME */ + #ifdef HAVE_TIMESTAMPNS + case SCM_TIMESTAMPNS: +- tsp = (struct timespec *)CMSG_DATA(cmsghdr); ++ tsp = UA_PTR(struct timespec, CMSG_DATA(cmsghdr)); + if (sys_tick > measured_tick && + sys_tick > 1e-9) { + ticks = (unsigned long)((tsp->tv_nsec * 1e-9) / +@@ -3666,8 +3667,7 @@ + fds = activefds; + tvzero.tv_sec = tvzero.tv_usec = 0; + +- n = select(maxactivefd + 1, &fds, (fd_set *)0, (fd_set *)0, +- &tvzero); ++ n = select(maxactivefd + 1, &fds, NULL, NULL, &tvzero); + + /* + * If there are no packets waiting just return +@@ -4447,7 +4447,7 @@ + break; + + case FD_TYPE_FILE: +- closeserial(lsock->fd); ++ closeserial((int)lsock->fd); + break; + + default: +@@ -4643,7 +4643,7 @@ + * process routing message + */ + #ifdef HAVE_RTNETLINK +- for (nh = (struct nlmsghdr *)buffer; ++ for (nh = UA_PTR(struct nlmsghdr, buffer); + NLMSG_OK(nh, cnt); + nh = NLMSG_NEXT(nh, cnt)) { + msg_type = nh->nlmsg_type; +--- contrib/ntp/ntpd/ntp_loopfilter.c.orig ++++ contrib/ntp/ntpd/ntp_loopfilter.c +@@ -154,7 +154,6 @@ + int ext_enable; /* external clock enabled */ + int pps_stratum; /* pps stratum */ + int kernel_status; /* from ntp_adjtime */ +-int allow_panic = FALSE; /* allow panic correction (-g) */ + int force_step_once = FALSE; /* always step time once at startup (-G) */ + int mode_ntpdate = FALSE; /* exit on first clock set (-q) */ + int freq_cnt; /* initial frequency clamp */ +@@ -459,16 +458,16 @@ + double dtemp, etemp; /* double temps */ + char tbuf[80]; /* report buffer */ + ++ (void)ntp_adj_ret; /* not always used below... */ + /* + * If the loop is opened or the NIST LOCKCLOCK is in use, + * monitor and record the offsets anyway in order to determine + * the open-loop response and then go home. + */ +-#ifdef LOCKCLOCK ++#ifndef LOCKCLOCK ++ if (!ntp_enable) ++#endif /* not LOCKCLOCK */ + { +-#else +- if (!ntp_enable) { +-#endif /* LOCKCLOCK */ + record_loop_stats(fp_offset, drift_comp, clock_jitter, + clock_stability, sys_poll); + return (0); +@@ -493,6 +492,8 @@ + return (-1); + } + ++ allow_panic = FALSE; ++ + /* + * This section simulates ntpdate. If the offset exceeds the + * step threshold (128 ms), step the clock to that time and +@@ -538,12 +539,8 @@ + else + dtemp = (peer->delay - sys_mindly) / 2; + fp_offset += dtemp; +-#ifdef DEBUG +- if (debug) +- printf( +- "local_clock: size %d mindly %.6f huffpuff %.6f\n", +- sys_hufflen, sys_mindly, dtemp); +-#endif ++ DPRINTF(1, ("local_clock: size %d mindly %.6f huffpuff %.6f\n", ++ sys_hufflen, sys_mindly, dtemp)); + } + + /* +@@ -694,7 +691,6 @@ + * startup until the initial transient has subsided. + */ + default: +- allow_panic = FALSE; + if (freq_cnt == 0) { + + /* +@@ -921,15 +917,11 @@ + */ + record_loop_stats(clock_offset, drift_comp, clock_jitter, + clock_stability, sys_poll); +-#ifdef DEBUG +- if (debug) +- printf( +- "local_clock: offset %.9f jit %.9f freq %.3f stab %.3f poll %d\n", ++ DPRINTF(1, ("local_clock: offset %.9f jit %.9f freq %.3f stab %.3f poll %d\n", + clock_offset, clock_jitter, drift_comp * 1e6, +- clock_stability * 1e6, sys_poll); +-#endif /* DEBUG */ ++ clock_stability * 1e6, sys_poll)); + return (rval); +-#endif /* LOCKCLOCK */ ++#endif /* not LOCKCLOCK */ + } + + +@@ -1005,7 +997,10 @@ + * but does not automatically stop slewing when an offset + * has decayed to zero. + */ ++ DEBUG_INSIST(enable_panic_check == TRUE); ++ enable_panic_check = FALSE; + adj_systime(offset_adj + freq_adj); ++ enable_panic_check = TRUE; + #endif /* LOCKCLOCK */ + } + +@@ -1019,12 +1014,9 @@ + double offset /* new offset */ + ) + { +-#ifdef DEBUG +- if (debug > 1) +- printf("local_clock: mu %lu state %d poll %d count %d\n", ++ DPRINTF(2, ("rstclock: mu %lu state %d poll %d count %d\n", + current_time - clock_epoch, trans, sys_poll, +- tc_counter); +-#endif ++ tc_counter)); + if (trans != state && trans != EVNT_FSET) + report_event(trans, NULL, NULL); + state = trans; +@@ -1075,6 +1067,7 @@ + const char * loop_desc; + int ntp_adj_ret; + ++ (void)ntp_adj_ret; /* not always used below... */ + drift_comp = freq; + loop_desc = "ntpd"; + #ifdef KERNEL_PLL +@@ -1236,10 +1229,7 @@ + int i; + double ftemp; + +-#ifdef DEBUG +- if (debug > 1) +- printf("loop_config: item %d freq %f\n", item, freq); +-#endif ++ DPRINTF(2, ("loop_config: item %d freq %f\n", item, freq)); + switch (item) { + + /* +--- contrib/ntp/ntpd/ntp_parser.c.orig ++++ contrib/ntp/ntpd/ntp_parser.c +@@ -889,21 +889,21 @@ + 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, + 882, 886, 891, 899, 904, 905, 906, 910, 915, 923, + 928, 929, 930, 931, 932, 933, 934, 935, 943, 953, +- 958, 966, 968, 970, 972, 974, 979, 980, 984, 985, +- 986, 987, 995, 1000, 1005, 1013, 1018, 1019, 1020, 1029, +- 1031, 1036, 1041, 1049, 1051, 1068, 1069, 1070, 1071, 1072, +- 1073, 1077, 1078, 1086, 1091, 1096, 1104, 1109, 1110, 1111, +- 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1127, 1128, 1129, +- 1136, 1143, 1150, 1166, 1185, 1187, 1189, 1191, 1193, 1195, +- 1202, 1207, 1208, 1209, 1213, 1217, 1226, 1227, 1231, 1232, +- 1233, 1237, 1248, 1262, 1274, 1279, 1281, 1286, 1287, 1295, +- 1297, 1305, 1310, 1318, 1343, 1350, 1360, 1361, 1365, 1366, +- 1367, 1368, 1372, 1373, 1374, 1378, 1383, 1388, 1396, 1397, +- 1398, 1399, 1400, 1401, 1402, 1412, 1417, 1425, 1430, 1438, +- 1440, 1444, 1449, 1454, 1462, 1467, 1475, 1484, 1485, 1489, +- 1490, 1499, 1517, 1521, 1526, 1534, 1539, 1540, 1544, 1549, +- 1557, 1562, 1567, 1572, 1577, 1585, 1590, 1595, 1603, 1608, +- 1609, 1610, 1611, 1612 ++ 958, 966, 968, 970, 979, 981, 986, 987, 991, 992, ++ 993, 994, 1002, 1007, 1012, 1020, 1025, 1026, 1027, 1036, ++ 1038, 1043, 1048, 1056, 1058, 1075, 1076, 1077, 1078, 1079, ++ 1080, 1084, 1085, 1093, 1098, 1103, 1111, 1116, 1117, 1118, ++ 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1134, 1135, 1136, ++ 1143, 1150, 1157, 1173, 1192, 1194, 1196, 1198, 1200, 1202, ++ 1209, 1214, 1215, 1216, 1220, 1224, 1233, 1234, 1238, 1239, ++ 1240, 1244, 1255, 1269, 1281, 1286, 1288, 1293, 1294, 1302, ++ 1304, 1312, 1317, 1325, 1350, 1357, 1367, 1368, 1372, 1373, ++ 1374, 1375, 1379, 1380, 1381, 1385, 1390, 1395, 1403, 1404, ++ 1405, 1406, 1407, 1408, 1409, 1419, 1424, 1432, 1437, 1445, ++ 1447, 1451, 1456, 1461, 1469, 1474, 1482, 1491, 1492, 1496, ++ 1497, 1506, 1524, 1528, 1533, 1541, 1546, 1547, 1551, 1556, ++ 1564, 1569, 1574, 1579, 1584, 1592, 1597, 1602, 1610, 1615, ++ 1616, 1617, 1618, 1619 + }; + #endif + +@@ -2684,90 +2684,97 @@ + + case 173: + #line 971 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ +- { (yyval.Attr_val) = create_attr_ival((yyvsp[-1].Integer), (yyvsp[0].Integer)); } +-#line 2689 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++ { ++ if ((yyvsp[0].Integer) >= 0 && (yyvsp[0].Integer) <= 16) { ++ (yyval.Attr_val) = create_attr_ival((yyvsp[-1].Integer), (yyvsp[0].Integer)); ++ } else { ++ (yyval.Attr_val) = NULL; ++ yyerror("fudge factor: stratum value not in [0..16], ignored"); ++ } ++ } ++#line 2696 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 174: +-#line 973 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 980 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Attr_val) = create_attr_sval((yyvsp[-1].Integer), (yyvsp[0].String)); } +-#line 2695 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2702 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 175: +-#line 975 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 982 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Attr_val) = create_attr_sval((yyvsp[-1].Integer), (yyvsp[0].String)); } +-#line 2701 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2708 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 182: +-#line 996 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1003 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { CONCAT_G_FIFOS(cfgt.rlimit, (yyvsp[0].Attr_val_fifo)); } +-#line 2707 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2714 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 183: +-#line 1001 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1008 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); + } +-#line 2716 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2723 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 184: +-#line 1006 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1013 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = NULL; + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); + } +-#line 2725 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2732 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 185: +-#line 1014 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1021 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Attr_val) = create_attr_ival((yyvsp[-1].Integer), (yyvsp[0].Integer)); } +-#line 2731 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2738 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 189: +-#line 1030 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1037 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { CONCAT_G_FIFOS(cfgt.enable_opts, (yyvsp[0].Attr_val_fifo)); } +-#line 2737 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2744 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 190: +-#line 1032 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1039 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { CONCAT_G_FIFOS(cfgt.disable_opts, (yyvsp[0].Attr_val_fifo)); } +-#line 2743 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2750 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 191: +-#line 1037 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1044 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); + } +-#line 2752 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2759 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 192: +-#line 1042 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1049 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = NULL; + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); + } +-#line 2761 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2768 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 193: +-#line 1050 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1057 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Attr_val) = create_attr_ival(T_Flag, (yyvsp[0].Integer)); } +-#line 2767 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2774 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 194: +-#line 1052 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1059 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + if (lex_from_file()) { + (yyval.Attr_val) = create_attr_ival(T_Flag, (yyvsp[0].Integer)); +@@ -2781,41 +2788,41 @@ + yyerror(err_str); + } + } +-#line 2785 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2792 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 203: +-#line 1087 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1094 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { CONCAT_G_FIFOS(cfgt.tinker, (yyvsp[0].Attr_val_fifo)); } +-#line 2791 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2798 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 204: +-#line 1092 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1099 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); + } +-#line 2800 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2807 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 205: +-#line 1097 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1104 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = NULL; + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); + } +-#line 2809 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2816 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 206: +-#line 1105 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1112 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Attr_val) = create_attr_dval((yyvsp[-1].Integer), (yyvsp[0].Double)); } +-#line 2815 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2822 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 219: +-#line 1130 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1137 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + attr_val *av; + +@@ -2822,11 +2829,11 @@ + av = create_attr_dval((yyvsp[-1].Integer), (yyvsp[0].Double)); + APPEND_G_FIFO(cfgt.vars, av); + } +-#line 2826 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2833 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 220: +-#line 1137 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1144 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + attr_val *av; + +@@ -2833,11 +2840,11 @@ + av = create_attr_ival((yyvsp[-1].Integer), (yyvsp[0].Integer)); + APPEND_G_FIFO(cfgt.vars, av); + } +-#line 2837 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2844 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 221: +-#line 1144 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1151 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + attr_val *av; + +@@ -2844,11 +2851,11 @@ + av = create_attr_sval((yyvsp[-1].Integer), (yyvsp[0].String)); + APPEND_G_FIFO(cfgt.vars, av); + } +-#line 2848 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2855 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 222: +-#line 1151 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1158 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + char error_text[64]; + attr_val *av; +@@ -2864,11 +2871,11 @@ + yyerror(error_text); + } + } +-#line 2868 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2875 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 223: +-#line 1167 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1174 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + if (!lex_from_file()) { + YYFREE((yyvsp[-1].String)); /* avoid leak */ +@@ -2887,41 +2894,41 @@ + } + YYFREE((yyvsp[-1].String)); /* avoid leak */ + } +-#line 2891 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2898 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 224: +-#line 1186 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1193 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { lex_flush_stack(); } +-#line 2897 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2904 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 225: +-#line 1188 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1195 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { /* see drift_parm below for actions */ } +-#line 2903 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2910 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 226: +-#line 1190 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1197 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { CONCAT_G_FIFOS(cfgt.logconfig, (yyvsp[0].Attr_val_fifo)); } +-#line 2909 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2916 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 227: +-#line 1192 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1199 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { CONCAT_G_FIFOS(cfgt.phone, (yyvsp[0].String_fifo)); } +-#line 2915 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2922 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 228: +-#line 1194 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1201 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { APPEND_G_FIFO(cfgt.setvar, (yyvsp[0].Set_var)); } +-#line 2921 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2928 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 229: +-#line 1196 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1203 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + addr_opts_node *aon; + +@@ -2928,27 +2935,27 @@ + aon = create_addr_opts_node((yyvsp[-1].Address_node), (yyvsp[0].Attr_val_fifo)); + APPEND_G_FIFO(cfgt.trap, aon); + } +-#line 2932 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2939 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 230: +-#line 1203 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1210 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { CONCAT_G_FIFOS(cfgt.ttl, (yyvsp[0].Attr_val_fifo)); } +-#line 2938 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2945 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 235: +-#line 1218 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1225 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + #ifndef LEAP_SMEAR + yyerror("Built without LEAP_SMEAR support."); + #endif + } +-#line 2948 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2955 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 241: +-#line 1238 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1245 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + if (lex_from_file()) { + attr_val *av; +@@ -2959,11 +2966,11 @@ + yyerror("driftfile remote configuration ignored"); + } + } +-#line 2963 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2970 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 242: +-#line 1249 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1256 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + if (lex_from_file()) { + attr_val *av; +@@ -2976,11 +2983,11 @@ + yyerror("driftfile remote configuration ignored"); + } + } +-#line 2980 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 2987 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 243: +-#line 1262 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1269 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + if (lex_from_file()) { + attr_val *av; +@@ -2990,71 +2997,71 @@ + yyerror("driftfile remote configuration ignored"); + } + } +-#line 2994 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3001 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 244: +-#line 1275 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1282 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Set_var) = create_setvar_node((yyvsp[-3].String), (yyvsp[-1].String), (yyvsp[0].Integer)); } +-#line 3000 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3007 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 246: +-#line 1281 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1288 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Integer) = 0; } +-#line 3006 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3013 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 247: +-#line 1286 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1293 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Attr_val_fifo) = NULL; } +-#line 3012 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3019 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 248: +-#line 1288 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1295 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); + } +-#line 3021 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3028 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 249: +-#line 1296 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1303 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Attr_val) = create_attr_ival((yyvsp[-1].Integer), (yyvsp[0].Integer)); } +-#line 3027 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3034 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 250: +-#line 1298 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1305 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val) = create_attr_sval((yyvsp[-1].Integer), estrdup((yyvsp[0].Address_node)->address)); + destroy_address_node((yyvsp[0].Address_node)); + } +-#line 3036 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3043 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 251: +-#line 1306 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1313 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); + } +-#line 3045 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3052 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 252: +-#line 1311 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1318 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = NULL; + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); + } +-#line 3054 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3061 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 253: +-#line 1319 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1326 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + char prefix; + char * type; +@@ -3076,11 +3083,11 @@ + (yyval.Attr_val) = create_attr_sval(prefix, estrdup(type)); + YYFREE((yyvsp[0].String)); + } +-#line 3080 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3087 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 254: +-#line 1344 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1351 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + nic_rule_node *nrn; + +@@ -3087,11 +3094,11 @@ + nrn = create_nic_rule_node((yyvsp[0].Integer), NULL, (yyvsp[-1].Integer)); + APPEND_G_FIFO(cfgt.nic_rules, nrn); + } +-#line 3091 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3098 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 255: +-#line 1351 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1358 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + nic_rule_node *nrn; + +@@ -3098,119 +3105,119 @@ + nrn = create_nic_rule_node(0, (yyvsp[0].String), (yyvsp[-1].Integer)); + APPEND_G_FIFO(cfgt.nic_rules, nrn); + } +-#line 3102 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3109 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 265: +-#line 1379 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1386 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { CONCAT_G_FIFOS(cfgt.reset_counters, (yyvsp[0].Int_fifo)); } +-#line 3108 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3115 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 266: +-#line 1384 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1391 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Int_fifo) = (yyvsp[-1].Int_fifo); + APPEND_G_FIFO((yyval.Int_fifo), create_int_node((yyvsp[0].Integer))); + } +-#line 3117 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3124 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 267: +-#line 1389 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1396 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Int_fifo) = NULL; + APPEND_G_FIFO((yyval.Int_fifo), create_int_node((yyvsp[0].Integer))); + } +-#line 3126 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3133 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 275: +-#line 1413 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1420 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); + APPEND_G_FIFO((yyval.Attr_val_fifo), create_int_node((yyvsp[0].Integer))); + } +-#line 3135 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3142 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 276: +-#line 1418 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1425 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = NULL; + APPEND_G_FIFO((yyval.Attr_val_fifo), create_int_node((yyvsp[0].Integer))); + } +-#line 3144 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3151 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 277: +-#line 1426 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1433 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = (yyvsp[-1].Attr_val_fifo); + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); + } +-#line 3153 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3160 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 278: +-#line 1431 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1438 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = NULL; + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[0].Attr_val)); + } +-#line 3162 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3169 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 279: +-#line 1439 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1446 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Attr_val) = create_attr_ival('i', (yyvsp[0].Integer)); } +-#line 3168 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3175 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 281: +-#line 1445 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1452 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Attr_val) = create_attr_rangeval('-', (yyvsp[-3].Integer), (yyvsp[-1].Integer)); } +-#line 3174 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3181 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 282: +-#line 1450 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1457 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.String_fifo) = (yyvsp[-1].String_fifo); + APPEND_G_FIFO((yyval.String_fifo), create_string_node((yyvsp[0].String))); + } +-#line 3183 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3190 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 283: +-#line 1455 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1462 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.String_fifo) = NULL; + APPEND_G_FIFO((yyval.String_fifo), create_string_node((yyvsp[0].String))); + } +-#line 3192 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3199 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 284: +-#line 1463 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1470 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Address_fifo) = (yyvsp[-1].Address_fifo); + APPEND_G_FIFO((yyval.Address_fifo), (yyvsp[0].Address_node)); + } +-#line 3201 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3208 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 285: +-#line 1468 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1475 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Address_fifo) = NULL; + APPEND_G_FIFO((yyval.Address_fifo), (yyvsp[0].Address_node)); + } +-#line 3210 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3217 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 286: +-#line 1476 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1483 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + if ((yyvsp[0].Integer) != 0 && (yyvsp[0].Integer) != 1) { + yyerror("Integer value is not boolean (0 or 1). Assuming 1"); +@@ -3219,29 +3226,29 @@ + (yyval.Integer) = (yyvsp[0].Integer); + } + } +-#line 3223 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3230 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 287: +-#line 1484 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1491 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Integer) = 1; } +-#line 3229 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3236 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 288: +-#line 1485 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1492 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Integer) = 0; } +-#line 3235 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3242 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 289: +-#line 1489 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1496 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Double) = (double)(yyvsp[0].Integer); } +-#line 3241 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3248 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 291: +-#line 1500 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1507 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + sim_node *sn; + +@@ -3251,125 +3258,125 @@ + /* Revert from ; to \n for end-of-command */ + old_config_style = 1; + } +-#line 3255 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3262 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 292: +-#line 1517 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1524 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { old_config_style = 0; } +-#line 3261 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3268 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 293: +-#line 1522 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1529 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = (yyvsp[-2].Attr_val_fifo); + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[-1].Attr_val)); + } +-#line 3270 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3277 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 294: +-#line 1527 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1534 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = NULL; + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[-1].Attr_val)); + } +-#line 3279 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3286 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 295: +-#line 1535 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1542 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Attr_val) = create_attr_dval((yyvsp[-2].Integer), (yyvsp[0].Double)); } +-#line 3285 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3292 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 298: +-#line 1545 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1552 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Sim_server_fifo) = (yyvsp[-1].Sim_server_fifo); + APPEND_G_FIFO((yyval.Sim_server_fifo), (yyvsp[0].Sim_server)); + } +-#line 3294 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3301 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 299: +-#line 1550 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1557 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Sim_server_fifo) = NULL; + APPEND_G_FIFO((yyval.Sim_server_fifo), (yyvsp[0].Sim_server)); + } +-#line 3303 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3310 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 300: +-#line 1558 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1565 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Sim_server) = ONLY_SIM(create_sim_server((yyvsp[-4].Address_node), (yyvsp[-2].Double), (yyvsp[-1].Sim_script_fifo))); } +-#line 3309 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3316 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 301: +-#line 1563 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1570 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Double) = (yyvsp[-1].Double); } +-#line 3315 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3322 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 302: +-#line 1568 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1575 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Address_node) = (yyvsp[0].Address_node); } +-#line 3321 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3328 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 303: +-#line 1573 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1580 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Sim_script_fifo) = (yyvsp[-1].Sim_script_fifo); + APPEND_G_FIFO((yyval.Sim_script_fifo), (yyvsp[0].Sim_script)); + } +-#line 3330 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3337 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 304: +-#line 1578 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1585 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Sim_script_fifo) = NULL; + APPEND_G_FIFO((yyval.Sim_script_fifo), (yyvsp[0].Sim_script)); + } +-#line 3339 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3346 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 305: +-#line 1586 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1593 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Sim_script) = ONLY_SIM(create_sim_script_info((yyvsp[-3].Double), (yyvsp[-1].Attr_val_fifo))); } +-#line 3345 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3352 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 306: +-#line 1591 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1598 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = (yyvsp[-2].Attr_val_fifo); + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[-1].Attr_val)); + } +-#line 3354 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3361 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 307: +-#line 1596 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1603 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { + (yyval.Attr_val_fifo) = NULL; + APPEND_G_FIFO((yyval.Attr_val_fifo), (yyvsp[-1].Attr_val)); + } +-#line 3363 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3370 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + case 308: +-#line 1604 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ ++#line 1611 "../../ntpd/ntp_parser.y" /* yacc.c:1646 */ + { (yyval.Attr_val) = create_attr_dval((yyvsp[-2].Integer), (yyvsp[0].Double)); } +-#line 3369 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3376 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + break; + + +-#line 3373 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ ++#line 3380 "../../ntpd/ntp_parser.c" /* yacc.c:1646 */ + default: break; + } + /* User semantic actions sometimes alter yychar, and that requires +@@ -3597,7 +3604,7 @@ + #endif + return yyresult; + } +-#line 1615 "../../ntpd/ntp_parser.y" /* yacc.c:1906 */ ++#line 1622 "../../ntpd/ntp_parser.y" /* yacc.c:1906 */ + + + void +--- contrib/ntp/ntpd/ntp_proto.c.orig ++++ contrib/ntp/ntpd/ntp_proto.c +@@ -15,6 +15,7 @@ + #include "ntp_string.h" + #include "ntp_leapsec.h" + #include "refidsmear.h" ++#include "lib_strbuf.h" + + #include + #ifdef HAVE_LIBSCF_H +@@ -172,8 +173,14 @@ + const struct addrinfo *); + #endif /* WORKER */ + ++const char * amtoa (int am); ++ ++ + void +-set_sys_leap(u_char new_sys_leap) { ++set_sys_leap( ++ u_char new_sys_leap ++ ) ++{ + sys_leap = new_sys_leap; + xmt_leap = sys_leap; + +@@ -189,8 +196,9 @@ + #ifdef LEAP_SMEAR + else { + /* +- * If leap smear is enabled in general we must never send a leap second warning +- * to clients, so make sure we only send "in sync". ++ * If leap smear is enabled in general we must ++ * never send a leap second warning to clients, ++ * so make sure we only send "in sync". + */ + if (leap_smear.enabled) + xmt_leap = LEAP_NOWARNING; +@@ -199,34 +207,39 @@ + } + } + ++ + /* + * Kiss Code check + */ +-int kiss_code_check(u_char hisleap, u_char hisstratum, u_char hismode, u_int32 refid) { ++int ++kiss_code_check( ++ u_char hisleap, ++ u_char hisstratum, ++ u_char hismode, ++ u_int32 refid ++ ) ++{ + +- if ( hismode == MODE_SERVER +- && hisleap == LEAP_NOTINSYNC +- && hisstratum == STRATUM_UNSPEC) { +- if(memcmp(&refid,"RATE", 4) == 0) { +- return (RATEKISS); +- } +- else if(memcmp(&refid,"DENY", 4) == 0) { +- return (DENYKISS); +- } +- else if(memcmp(&refid,"RSTR", 4) == 0) { +- return (RSTRKISS); +- } +- else if(memcmp(&refid,"X", 1) == 0) { +- return (XKISS); +- } +- else { +- return (UNKNOWNKISS); +- } ++ if ( hismode == MODE_SERVER ++ && hisleap == LEAP_NOTINSYNC ++ && hisstratum == STRATUM_UNSPEC) { ++ if(memcmp(&refid,"RATE", 4) == 0) { ++ return (RATEKISS); ++ } else if(memcmp(&refid,"DENY", 4) == 0) { ++ return (DENYKISS); ++ } else if(memcmp(&refid,"RSTR", 4) == 0) { ++ return (RSTRKISS); ++ } else if(memcmp(&refid,"X", 1) == 0) { ++ return (XKISS); ++ } else { ++ return (UNKNOWNKISS); + } +- else { +- return (NOKISS); +- } ++ } else { ++ return (NOKISS); ++ } + } ++ ++ + /* + * transmit - transmit procedure called by poll timeout + */ +@@ -303,7 +316,7 @@ + peer->outdate = current_time; + if ( (peer_associations <= 2 * sys_maxclock) + && ( peer_associations < sys_maxclock +- || sys_survivors < sys_minclock)) ++ || sys_survivors < sys_minclock)) + pool_xmit(peer); + poll_update(peer, hpoll); + return; +@@ -416,9 +429,36 @@ + if (peer->hmode != MODE_BCLIENT) + peer_xmit(peer); + poll_update(peer, hpoll); ++ ++ return; + } + + ++const char * ++amtoa( ++ int am ++ ) ++{ ++ char *bp; ++ ++ switch(am) { ++ case AM_ERR: return "AM_ERR"; ++ case AM_NOMATCH: return "AM_NOMATCH"; ++ case AM_PROCPKT: return "AM_PROCPKT"; ++ case AM_BCST: return "AM_BCST"; ++ case AM_FXMIT: return "AM_FXMIT"; ++ case AM_MANYCAST: return "AM_MANYCAST"; ++ case AM_NEWPASS: return "AM_NEWPASS"; ++ case AM_NEWBCL: return "AM_NEWBCL"; ++ case AM_POSSBCL: return "AM_POSSBCL"; ++ default: ++ LIB_GETBUF(bp); ++ snprintf(bp, LIB_BUFLENGTH, "AM_#%d", am); ++ return bp; ++ } ++} ++ ++ + /* + * receive - receive procedure called for each packet received + */ +@@ -434,7 +474,9 @@ + u_char hismode; /* packet mode */ + u_char hisstratum; /* packet stratum */ + u_short restrict_mask; /* restrict bits */ +- int kissCode = NOKISS; /* Kiss Code */ ++ const char *hm_str; /* hismode string */ ++ const char *am_str; /* association match string */ ++ int kissCode = NOKISS; /* Kiss Code */ + int has_mac; /* length of MAC field */ + int authlen; /* offset of MAC field */ + int is_authentic = 0; /* cryptosum ok */ +@@ -441,9 +483,9 @@ + int retcode = AM_NOMATCH; /* match code */ + keyid_t skeyid = 0; /* key IDs */ + u_int32 opcode = 0; /* extension field opcode */ +- sockaddr_u *dstadr_sin; /* active runway */ ++ sockaddr_u *dstadr_sin; /* active runway */ + struct peer *peer2; /* aux peer structure pointer */ +- endpt * match_ep; /* newpeer() local address */ ++ endpt *match_ep; /* newpeer() local address */ + l_fp p_org; /* origin timestamp */ + l_fp p_rec; /* receive timestamp */ + l_fp p_xmt; /* transmit timestamp */ +@@ -474,11 +516,12 @@ + return; /* bogus port */ + } + restrict_mask = restrictions(&rbufp->recv_srcadr); +- DPRINTF(2, ("receive: at %ld %s<-%s flags %x restrict %03x\n", ++ pkt = &rbufp->recv_pkt; ++ DPRINTF(2, ("receive: at %ld %s<-%s flags %x restrict %03x org %#010x.%08x xmt %#010x.%08x\n", + current_time, stoa(&rbufp->dstadr->sin), +- stoa(&rbufp->recv_srcadr), +- rbufp->dstadr->flags, restrict_mask)); +- pkt = &rbufp->recv_pkt; ++ stoa(&rbufp->recv_srcadr), rbufp->dstadr->flags, ++ restrict_mask, ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), ++ ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); + hisversion = PKT_VERSION(pkt->li_vn_mode); + hisleap = PKT_LEAP(pkt->li_vn_mode); + hismode = (int)PKT_MODE(pkt->li_vn_mode); +@@ -685,6 +728,8 @@ + NTOHL_FP(&pkt->org, &p_org); + NTOHL_FP(&pkt->rec, &p_rec); + NTOHL_FP(&pkt->xmt, &p_xmt); ++ hm_str = modetoa(hismode); ++ am_str = amtoa(retcode); + + /* + * Authentication is conditioned by three switches: +@@ -713,25 +758,21 @@ + if (has_mac == 0) { + restrict_mask &= ~RES_MSSNTP; + is_authentic = AUTH_NONE; /* not required */ +-#ifdef DEBUG +- if (debug) +- printf( +- "receive: at %ld %s<-%s mode %d len %d\n", ++ DPRINTF(2, ("receive: at %ld %s<-%s mode %d/%s:%s len %d org %#010x.%08x xmt %#010x.%08x NOMAC\n", + current_time, stoa(dstadr_sin), +- stoa(&rbufp->recv_srcadr), hismode, +- authlen); +-#endif ++ stoa(&rbufp->recv_srcadr), hismode, hm_str, am_str, ++ authlen, ++ ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), ++ ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); + } else if (has_mac == 4) { + restrict_mask &= ~RES_MSSNTP; + is_authentic = AUTH_CRYPTO; /* crypto-NAK */ +-#ifdef DEBUG +- if (debug) +- printf( +- "receive: at %ld %s<-%s mode %d keyid %08x len %d auth %d\n", ++ DPRINTF(2, ("receive: at %ld %s<-%s mode %d/%s:%s keyid %08x len %d auth %d org %#010x.%08x xmt %#010x.%08x MAC4\n", + current_time, stoa(dstadr_sin), +- stoa(&rbufp->recv_srcadr), hismode, skeyid, +- authlen + has_mac, is_authentic); +-#endif ++ stoa(&rbufp->recv_srcadr), hismode, hm_str, am_str, ++ skeyid, authlen + has_mac, is_authentic, ++ ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), ++ ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); + + #ifdef HAVE_NTP_SIGND + /* +@@ -747,7 +788,7 @@ + && (restrict_mask & RES_MSSNTP) + && (retcode == AM_FXMIT || retcode == AM_NEWPASS) + && (memcmp(zero_key, (char *)pkt + authlen + 4, +- MAX_MD5_LEN - 4) == 0)) { ++ MAX_MD5_LEN - 4) == 0)) { + is_authentic = AUTH_NONE; + #endif /* HAVE_NTP_SIGND */ + +@@ -856,14 +897,12 @@ + if (crypto_flags && skeyid > NTP_MAXKEY) + authtrust(skeyid, 0); + #endif /* AUTOKEY */ +-#ifdef DEBUG +- if (debug) +- printf( +- "receive: at %ld %s<-%s mode %d keyid %08x len %d auth %d\n", ++ DPRINTF(2, ("receive: at %ld %s<-%s mode %d/%s:%s keyid %08x len %d auth %d org %#010x.%08x xmt %#010x.%08x\n", + current_time, stoa(dstadr_sin), +- stoa(&rbufp->recv_srcadr), hismode, skeyid, +- authlen + has_mac, is_authentic); +-#endif ++ stoa(&rbufp->recv_srcadr), hismode, hm_str, am_str, ++ skeyid, authlen + has_mac, is_authentic, ++ ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), ++ ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf))); + } + + /* +@@ -1194,11 +1233,11 @@ + * debug-printed and not logged to avoid log + * flooding. + */ +- DPRINTF(1, ("receive: at %ld refusing to mobilize passive association" +- " with unknown peer %s mode %d keyid %08x len %d auth %d\n", ++ DPRINTF(2, ("receive: at %ld refusing to mobilize passive association" ++ " with unknown peer %s mode %d/%s:%s keyid %08x len %d auth %d\n", + current_time, stoa(&rbufp->recv_srcadr), +- hismode, skeyid, (authlen + has_mac), +- is_authentic)); ++ hismode, hm_str, am_str, skeyid, ++ (authlen + has_mac), is_authentic)); + sys_declined++; + return; + } +@@ -1321,26 +1360,36 @@ + } + + /* +- * Check for bogus packet in basic mode. If found, switch to +- * interleaved mode and resynchronize, but only after confirming +- * the packet is not bogus in symmetric interleaved mode. ++ * Basic mode checks: + * ++ * If there is no origin timestamp, it's an initial packet. ++ * ++ * Otherwise, check for bogus packet in basic mode. ++ * If it is bogus, switch to interleaved mode and resynchronize, ++ * but only after confirming the packet is not bogus in ++ * symmetric interleaved mode. ++ * + * This could also mean somebody is forging packets claiming to + * be from us, attempting to cause our server to KoD us. + */ + } else if (peer->flip == 0) { +- if (!L_ISEQU(&p_org, &peer->aorg)) { ++ if (0 < hisstratum && L_ISZERO(&p_org)) { ++ L_CLR(&peer->aorg); ++ } else if (!L_ISEQU(&p_org, &peer->aorg)) { + peer->bogusorg++; + peer->flash |= TEST2; /* bogus */ + msyslog(LOG_INFO, +- "receive: Unexpected origin timestamp from %s", +- ntoa(&peer->srcadr)); ++ "receive: Unexpected origin timestamp %#010x.%08x from %s xmt %#010x.%08x", ++ ntohl(pkt->org.l_ui), ntohl(pkt->org.l_uf), ++ ntoa(&peer->srcadr), ++ ntohl(pkt->xmt.l_ui), ntohl(pkt->xmt.l_uf)); + if ( !L_ISZERO(&peer->dst) + && L_ISEQU(&p_org, &peer->dst)) { ++ /* Might be the start of an interleave */ + peer->flip = 1; + report_event(PEVNT_XLEAVE, peer, NULL); + } +- return; /* Bogus packet, we are done */ ++ return; /* Bogus or possible interleave packet */ + } else { + L_CLR(&peer->aorg); + } +@@ -1694,11 +1743,8 @@ + */ + if (peer->flash & PKT_TEST_MASK) { + peer->seldisptoolarge++; +-#ifdef DEBUG +- if (debug) +- printf("packet: flash header %04x\n", +- peer->flash); +-#endif ++ DPRINTF(1, ("packet: flash header %04x\n", ++ peer->flash)); + return; + } + +@@ -1871,15 +1917,12 @@ + * the roundtrip delay. Then it calculates the correction as a + * fraction of d. + */ +- peer->t21 = t21; ++ peer->t21 = t21; + peer->t21_last = peer->t21_bytes; + peer->t34 = -t34; + peer->t34_bytes = len; +-#ifdef DEBUG +- if (debug > 1) +- printf("packet: t21 %.9lf %d t34 %.9lf %d\n", peer->t21, +- peer->t21_bytes, peer->t34, peer->t34_bytes); +-#endif ++ DPRINTF(2, ("packet: t21 %.9lf %d t34 %.9lf %d\n", peer->t21, ++ peer->t21_bytes, peer->t34, peer->t34_bytes)); + if (peer->r21 > 0 && peer->r34 > 0 && p_del > 0) { + if (peer->pmode != MODE_BROADCAST) + td = (peer->r34 / (peer->r21 + peer->r34) - +@@ -1888,7 +1931,7 @@ + td = 0; + + /* +- * Unfortunately, in many cases the errors are ++ * Unfortunately, in many cases the errors are + * unacceptable, so for the present the rates are not + * used. In future, we might find conditions where the + * calculations are useful, so this should be considered +@@ -1896,12 +1939,9 @@ + */ + t21 -= td; + t34 -= td; +-#ifdef DEBUG +- if (debug > 1) +- printf("packet: del %.6lf r21 %.1lf r34 %.1lf %.6lf\n", ++ DPRINTF(2, ("packet: del %.6lf r21 %.1lf r34 %.1lf %.6lf\n", + p_del, peer->r21 / 1e3, peer->r34 / 1e3, +- td); +-#endif ++ td)); + } + #endif /* ASSYM */ + +@@ -1994,12 +2034,8 @@ + sys_rootdelay = peer->delay + peer->rootdelay; + sys_reftime = peer->dst; + +-#ifdef DEBUG +- if (debug) +- printf( +- "clock_update: at %lu sample %lu associd %d\n", +- current_time, peer->epoch, peer->associd); +-#endif ++ DPRINTF(1, ("clock_update: at %lu sample %lu associd %d\n", ++ current_time, peer->epoch, peer->associd)); + + /* + * Comes now the moment of truth. Crank the clock discipline and +@@ -2308,13 +2344,9 @@ + #ifdef AUTOKEY + peer->refresh = current_time + (1 << NTP_REFRESH); + #endif /* AUTOKEY */ +-#ifdef DEBUG +- if (debug) +- printf( +- "peer_clear: at %ld next %ld associd %d refid %s\n", ++ DPRINTF(1, ("peer_clear: at %ld next %ld associd %d refid %s\n", + current_time, peer->nextdate, peer->associd, +- ident); +-#endif ++ ident)); + } + + +@@ -2478,11 +2510,8 @@ + * packets. + */ + if (peer->filter_epoch[k] <= peer->epoch) { +-#if DEBUG +- if (debug > 1) +- printf("clock_filter: old sample %lu\n", current_time - +- peer->filter_epoch[k]); +-#endif ++ DPRINTF(2, ("clock_filter: old sample %lu\n", current_time - ++ peer->filter_epoch[k])); + return; + } + peer->epoch = peer->filter_epoch[k]; +@@ -2494,13 +2523,9 @@ + */ + record_peer_stats(&peer->srcadr, ctlpeerstatus(peer), + peer->offset, peer->delay, peer->disp, peer->jitter); +-#ifdef DEBUG +- if (debug) +- printf( +- "clock_filter: n %d off %.6f del %.6f dsp %.6f jit %.6f\n", ++ DPRINTF(1, ("clock_filter: n %d off %.6f del %.6f dsp %.6f jit %.6f\n", + m, peer->offset, peer->delay, peer->disp, +- peer->jitter); +-#endif ++ peer->jitter)); + if (peer->burst == 0 || sys_leap == LEAP_NOTINSYNC) + clock_select(); + } +@@ -3004,7 +3029,7 @@ + typesystem = typepps; + sys_clockhop = 0; + typesystem->new_status = CTL_PST_SEL_PPS; +- sys_offset = typesystem->offset; ++ sys_offset = typesystem->offset; + sys_jitter = typesystem->jitter; + DPRINTF(1, ("select: pps offset %.9f jitter %.9f\n", + sys_offset, sys_jitter)); +@@ -3157,11 +3182,11 @@ + * might not be usable. + */ + sendlen = LEN_PKT_NOMAC; ++ if ( + #ifdef AUTOKEY +- if (!(peer->flags & FLAG_SKEY) && peer->keyid == 0) { +-#else /* !AUTOKEY follows */ +- if (peer->keyid == 0) { ++ !(peer->flags & FLAG_SKEY) && + #endif /* !AUTOKEY */ ++ peer->keyid == 0) { + + /* + * Transmit a-priori timestamps +@@ -3207,13 +3232,11 @@ + } + L_SUB(&xmt_ty, &xmt_tx); + LFPTOD(&xmt_ty, peer->xleave); +-#ifdef DEBUG +- if (debug) +- printf("transmit: at %ld %s->%s mode %d len %zu\n", +- current_time, peer->dstadr ? +- stoa(&peer->dstadr->sin) : "-", +- stoa(&peer->srcadr), peer->hmode, sendlen); +-#endif ++ DPRINTF(1, ("peer_xmit: at %ld %s->%s mode %d len %zu xmt %#010x.%08x\n", ++ current_time, ++ peer->dstadr ? stoa(&peer->dstadr->sin) : "-", ++ stoa(&peer->srcadr), peer->hmode, sendlen, ++ xmt_tx.l_ui, xmt_tx.l_uf)); + return; + } + +@@ -3498,7 +3521,7 @@ + authtrust(xkeyid, 0); + #endif /* AUTOKEY */ + if (sendlen > sizeof(xpkt)) { +- msyslog(LOG_ERR, "proto: buffer overflow %zu", sendlen); ++ msyslog(LOG_ERR, "peer_xmit: buffer overflow %zu", sendlen); + exit (-1); + } + peer->t21_bytes = sendlen; +@@ -3521,22 +3544,18 @@ + L_SUB(&xmt_ty, &xmt_tx); + LFPTOD(&xmt_ty, peer->xleave); + #ifdef AUTOKEY +-#ifdef DEBUG +- if (debug) +- printf("transmit: at %ld %s->%s mode %d keyid %08x len %zu index %d\n", ++ DPRINTF(1, ("peer_xmit: at %ld %s->%s mode %d keyid %08x len %zu index %d\n", + current_time, latoa(peer->dstadr), + ntoa(&peer->srcadr), peer->hmode, xkeyid, sendlen, +- peer->keynumber); +-#endif ++ peer->keynumber)); + #else /* !AUTOKEY follows */ +-#ifdef DEBUG +- if (debug) +- printf("transmit: at %ld %s->%s mode %d keyid %08x len %d\n", ++ DPRINTF(1, ("peer_xmit: at %ld %s->%s mode %d keyid %08x len %d\n", + current_time, peer->dstadr ? + ntoa(&peer->dstadr->sin) : "-", +- ntoa(&peer->srcadr), peer->hmode, xkeyid, sendlen); +-#endif ++ ntoa(&peer->srcadr), peer->hmode, xkeyid, sendlen)); + #endif /* !AUTOKEY */ ++ ++ return; + } + + +@@ -3543,8 +3562,15 @@ + #ifdef LEAP_SMEAR + + static void +-leap_smear_add_offs(l_fp *t, l_fp *t_recv) { ++leap_smear_add_offs( ++ l_fp *t, ++ l_fp *t_recv ++ ) ++{ ++ + L_ADD(t, &leap_smear.offset); ++ ++ return; + } + + #endif /* LEAP_SMEAR */ +@@ -3565,7 +3591,7 @@ + struct pkt xpkt; /* transmit packet structure */ + struct pkt *rpkt; /* receive packet structure */ + l_fp xmt_tx, xmt_ty; +- int sendlen; ++ size_t sendlen; + #ifdef AUTOKEY + u_int32 temp32; + #endif +@@ -3684,13 +3710,10 @@ + if (rbufp->recv_length == sendlen) { + sendpkt(&rbufp->recv_srcadr, rbufp->dstadr, 0, &xpkt, + sendlen); +-#ifdef DEBUG +- if (debug) +- printf( +- "transmit: at %ld %s->%s mode %d len %d\n", ++ DPRINTF(1, ("fast_xmit: at %ld %s->%s mode %d len %lu\n", + current_time, stoa(&rbufp->dstadr->sin), +- stoa(&rbufp->recv_srcadr), xmode, sendlen); +-#endif ++ stoa(&rbufp->recv_srcadr), xmode, ++ (u_long)sendlen)); + return; + } + +@@ -3717,7 +3740,7 @@ + */ + cookie = session_key(&rbufp->recv_srcadr, + &rbufp->dstadr->sin, 0, sys_private, 0); +- if (rbufp->recv_length > sendlen + (int)MAX_MAC_LEN) { ++ if ((size_t)rbufp->recv_length > sendlen + MAX_MAC_LEN) { + session_key(&rbufp->dstadr->sin, + &rbufp->recv_srcadr, xkeyid, 0, 2); + temp32 = CRYPTO_RESP; +@@ -3741,13 +3764,10 @@ + get_systime(&xmt_ty); + L_SUB(&xmt_ty, &xmt_tx); + sys_authdelay = xmt_ty; +-#ifdef DEBUG +- if (debug) +- printf( +- "transmit: at %ld %s->%s mode %d keyid %08x len %d\n", ++ DPRINTF(1, ("fast_xmit: at %ld %s->%s mode %d keyid %08x len %lu\n", + current_time, ntoa(&rbufp->dstadr->sin), +- ntoa(&rbufp->recv_srcadr), xmode, xkeyid, sendlen); +-#endif ++ ntoa(&rbufp->recv_srcadr), xmode, xkeyid, ++ (u_long)sendlen)); + } + + +@@ -3827,11 +3847,8 @@ + LEN_PKT_NOMAC); + pool->sent++; + pool->throttle += (1 << pool->minpoll) - 2; +-#ifdef DEBUG +- if (debug) +- printf("transmit: at %ld %s->%s pool\n", +- current_time, latoa(lcladr), stoa(rmtadr)); +-#endif ++ DPRINTF(1, ("pool_xmit: at %ld %s->%s pool\n", ++ current_time, latoa(lcladr), stoa(rmtadr))); + msyslog(LOG_INFO, "Soliciting pool server %s", stoa(rmtadr)); + #endif /* WORKER */ + } +@@ -3849,7 +3866,8 @@ + * group different 1 ignore + * * ignore if notrust + */ +-int group_test( ++int ++group_test( + char *grp, + char *ident + ) +@@ -3929,11 +3947,8 @@ + value_free(&peer->sndval); + peer->keynumber = 0; + peer->flags &= ~FLAG_ASSOC; +-#ifdef DEBUG +- if (debug) +- printf("key_expire: at %lu associd %d\n", current_time, +- peer->associd); +-#endif ++ DPRINTF(1, ("key_expire: at %lu associd %d\n", current_time, ++ peer->associd)); + } + #endif /* AUTOKEY */ + +--- contrib/ntp/ntpd/ntp_refclock.c.orig ++++ contrib/ntp/ntpd/ntp_refclock.c +@@ -732,9 +732,9 @@ + */ + int + refclock_open( +- char *dev, /* device name pointer */ +- u_int speed, /* serial port speed (code) */ +- u_int lflags /* line discipline flags */ ++ const char *dev, /* device name pointer */ ++ u_int speed, /* serial port speed (code) */ ++ u_int lflags /* line discipline flags */ + ) + { + int fd; +--- contrib/ntp/ntpd/ntp_request.c.orig ++++ contrib/ntp/ntpd/ntp_request.c +@@ -2006,11 +2006,11 @@ + u_long trust + ) + { +- register u_long *kp; ++ register uint32_t *kp; + register int items; + + items = INFO_NITEMS(inpkt->err_nitems); +- kp = (u_long *)&inpkt->u; ++ kp = (uint32_t*)&inpkt->u; + while (items-- > 0) { + authtrust(*kp, trust); + kp++; +--- contrib/ntp/ntpd/ntp_restrict.c.orig ++++ contrib/ntp/ntpd/ntp_restrict.c +@@ -160,7 +160,7 @@ + const size_t count = INC_RESLIST4; + restrict_u * rl; + restrict_u * res; +- int i; ++ size_t i; + + UNLINK_HEAD_SLIST(res, resfree4, link); + if (res != NULL) +@@ -186,7 +186,7 @@ + const size_t count = INC_RESLIST6; + restrict_u * rl; + restrict_u * res; +- int i; ++ size_t i; + + UNLINK_HEAD_SLIST(res, resfree6, link); + if (res != NULL) +--- contrib/ntp/ntpd/ntp_signd.c.orig ++++ contrib/ntp/ntpd/ntp_signd.c +@@ -66,7 +66,7 @@ + while (len) { + int n = write(fd, buf, len); + if (n <= 0) return total; +- buf = n + (char *)buf; ++ buf = n + (const char *)buf; + len -= n; + total += n; + } +@@ -110,9 +110,10 @@ + { + if (read_all(fd, len, sizeof(*len)) != sizeof(*len)) return -1; + *len = ntohl(*len); +- (*buf) = emalloc(*len); ++ *buf = emalloc(*len); + if (read_all(fd, *buf, *len) != *len) { + free(*buf); ++ *buf = NULL; + return -1; + } + return 0; +--- contrib/ntp/ntpd/ntp_timer.c.orig ++++ contrib/ntp/ntpd/ntp_timer.c +@@ -626,18 +626,19 @@ + * announce the leap event has happened. + */ + const char *leapmsg = NULL; +- if (lsdata.warped < 0) { ++ double lswarp = lsdata.warped; ++ if (lswarp < 0.0) { + if (clock_max_back > 0.0 && +- clock_max_back < fabs(lsdata.warped)) { +- step_systime(lsdata.warped); ++ clock_max_back < -lswarp) { ++ step_systime(lswarp); + leapmsg = leapmsg_p_step; + } else { + leapmsg = leapmsg_p_slew; + } +- } else if (lsdata.warped > 0) { ++ } else if (lswarp > 0.0) { + if (clock_max_fwd > 0.0 && +- clock_max_fwd < fabs(lsdata.warped)) { +- step_systime(lsdata.warped); ++ clock_max_fwd < lswarp) { ++ step_systime(lswarp); + leapmsg = leapmsg_n_step; + } else { + leapmsg = leapmsg_n_slew; +--- contrib/ntp/ntpd/ntp_util.c.orig ++++ contrib/ntp/ntpd/ntp_util.c +@@ -334,7 +334,7 @@ + { + FILE *fp; + const char *value; +- int len; ++ size_t len; + double old_drift; + l_fp now; + time_t ttnow; +@@ -437,7 +437,7 @@ + (int)sizeof(statsdir) - 2); + } else { + int add_dir_sep; +- int value_l; ++ size_t value_l; + + /* Add a DIR_SEP unless we already have one. */ + value_l = strlen(value); +@@ -933,7 +933,7 @@ + const char *keyfile + ) + { +- int len; ++ size_t len; + + len = strlen(keyfile); + if (!len) +--- contrib/ntp/ntpd/ntpd-opts.c.orig ++++ contrib/ntp/ntpd/ntpd-opts.c +@@ -1,7 +1,7 @@ + /* + * EDIT THIS FILE WITH CAUTION (ntpd-opts.c) + * +- * It has been AutoGen-ed October 21, 2015 at 12:36:00 PM by AutoGen 5.18.5 ++ * It has been AutoGen-ed January 7, 2016 at 11:28:29 PM by AutoGen 5.18.5 + * From the definitions ntpd-opts.def + * and the template file options + * +@@ -75,7 +75,7 @@ + * static const strings for ntpd options + */ + static char const ntpd_opt_strs[3129] = +-/* 0 */ "ntpd 4.2.8p4\n" ++/* 0 */ "ntpd 4.2.8p5\n" + "Copyright (C) 1992-2015 The University of Delaware and Network Time Foundation, all rights reserved.\n" + "This is free software. It is licensed for use, modification and\n" + "redistribution under the terms of the NTP License, copies of which\n" +@@ -205,12 +205,12 @@ + /* 2900 */ "output version information and exit\0" + /* 2936 */ "version\0" + /* 2944 */ "NTPD\0" +-/* 2949 */ "ntpd - NTP daemon program - Ver. 4.2.8p4\n" ++/* 2949 */ "ntpd - NTP daemon program - Ver. 4.2.8p5\n" + "Usage: %s [ - [] | --[{=| }] ]... \\\n" + "\t\t[ ... ]\n\0" + /* 3080 */ "http://bugs.ntp.org, bugs@ntp.org\0" + /* 3114 */ "\n\0" +-/* 3116 */ "ntpd 4.2.8p4"; ++/* 3116 */ "ntpd 4.2.8p5"; + + /** + * ipv4 option description with +@@ -1529,7 +1529,7 @@ + translate option names. + */ + /* referenced via ntpdOptions.pzCopyright */ +- puts(_("ntpd 4.2.8p4\n\ ++ puts(_("ntpd 4.2.8p5\n\ + Copyright (C) 1992-2015 The University of Delaware and Network Time Foundation, all rights reserved.\n\ + This is free software. It is licensed for use, modification and\n\ + redistribution under the terms of the NTP License, copies of which\n\ +@@ -1670,7 +1670,7 @@ + puts(_("output version information and exit")); + + /* referenced via ntpdOptions.pzUsageTitle */ +- puts(_("ntpd - NTP daemon program - Ver. 4.2.8p4\n\ ++ puts(_("ntpd - NTP daemon program - Ver. 4.2.8p5\n\ + Usage: %s [ - [] | --[{=| }] ]... \\\n\ + \t\t[ ... ]\n")); + +@@ -1678,7 +1678,7 @@ + puts(_("\n")); + + /* referenced via ntpdOptions.pzFullVersion */ +- puts(_("ntpd 4.2.8p4")); ++ puts(_("ntpd 4.2.8p5")); + + /* referenced via ntpdOptions.pzFullUsage */ + puts(_("<<>>")); +--- contrib/ntp/ntpd/ntpd-opts.h.orig ++++ contrib/ntp/ntpd/ntpd-opts.h +@@ -1,7 +1,7 @@ + /* + * EDIT THIS FILE WITH CAUTION (ntpd-opts.h) + * +- * It has been AutoGen-ed October 21, 2015 at 12:35:59 PM by AutoGen 5.18.5 ++ * It has been AutoGen-ed January 7, 2016 at 11:28:28 PM by AutoGen 5.18.5 + * From the definitions ntpd-opts.def + * and the template file options + * +@@ -106,9 +106,9 @@ + /** count of all options for ntpd */ + #define OPTION_CT 38 + /** ntpd version */ +-#define NTPD_VERSION "4.2.8p4" ++#define NTPD_VERSION "4.2.8p5" + /** Full ntpd version text */ +-#define NTPD_FULL_VERSION "ntpd 4.2.8p4" ++#define NTPD_FULL_VERSION "ntpd 4.2.8p5" + + /** + * Interface defines for all options. Replace "n" with the UPPER_CASED +--- contrib/ntp/ntpd/ntpd.1ntpdman.orig ++++ contrib/ntp/ntpd/ntpd.1ntpdman +@@ -10,11 +10,11 @@ + .ds B-Font B + .ds I-Font I + .ds R-Font R +-.TH ntpd 1ntpdman "21 Oct 2015" "4.2.8p4" "User Commands" ++.TH ntpd 1ntpdman "07 Jan 2016" "4.2.8p5" "User Commands" + .\" +-.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-dUaOfK/ag-qUaGeK) ++.\" EDIT THIS FILE WITH CAUTION (/tmp/.ag-KDaWJq/ag-WDaOIq) + .\" +-.\" It has been AutoGen-ed October 21, 2015 at 12:38:11 PM by AutoGen 5.18.5 ++.\" It has been AutoGen-ed January 7, 2016 at 11:30:44 PM by AutoGen 5.18.5 + .\" From the definitions ntpd-opts.def + .\" and the template file agman-cmd.tpl + .SH NAME +--- contrib/ntp/ntpd/ntpd.1ntpdmdoc.orig ++++ contrib/ntp/ntpd/ntpd.1ntpdmdoc +@@ -1,9 +1,9 @@ +-.Dd October 21 2015 ++.Dd January 7 2016 + .Dt NTPD 1ntpdmdoc User Commands + .Os + .\" EDIT THIS FILE WITH CAUTION (ntpd-opts.mdoc) + .\" +-.\" It has been AutoGen-ed October 21, 2015 at 12:38:30 PM by AutoGen 5.18.5 ++.\" It has been AutoGen-ed January 7, 2016 at 11:31:02 PM by AutoGen 5.18.5 + .\" From the definitions ntpd-opts.def + .\" and the template file agmdoc-cmd.tpl + .Sh NAME +--- contrib/ntp/ntpd/ntpd.c.orig ++++ contrib/ntp/ntpd/ntpd.c +@@ -27,12 +27,16 @@ + #include "ntp_libopts.h" + #include "ntpd-opts.h" + +-/* there's a short treatise below what the thread stuff is for */ ++/* there's a short treatise below what the thread stuff is for. ++ * [Bug 2954] enable the threading warm-up only for Linux. ++ */ + #if defined(HAVE_PTHREADS) && HAVE_PTHREADS && !defined(NO_THREADS) + # ifdef HAVE_PTHREAD_H + # include + # endif +-# define NEED_PTHREAD_WARMUP ++# if defined(linux) ++# define NEED_PTHREAD_WARMUP ++# endif + #endif + + #ifdef HAVE_UNISTD_H +@@ -269,6 +273,9 @@ + * This uses only the standard pthread API and should work with all + * implementations of pthreads. It is not necessary everywhere, but it's + * cheap enough to go on nearly unnoticed. ++ * ++ * Addendum: Bug 2954 showed that the assumption that this should work ++ * with all OS is wrong -- at least FreeBSD bombs heavily. + */ + #ifdef NEED_PTHREAD_WARMUP + +@@ -646,6 +653,9 @@ + # endif + + # ifdef HAVE_WORKING_FORK ++ /* make sure the FDs are initialised */ ++ pipe_fds[0] = -1; ++ pipe_fds[1] = -1; + do { /* 'loop' once */ + if (!HAVE_OPT( WAIT_SYNC )) + break; +--- contrib/ntp/ntpd/ntpd.html.orig ++++ contrib/ntp/ntpd/ntpd.html +@@ -39,7 +39,7 @@ + symmetric and broadcast modes, and with both symmetric-key and public-key + cryptography. + +-

This document applies to version 4.2.8p4 of ntpd. ++

This document applies to version 4.2.8p5 of ntpd. + +