From nobody Mon Feb 27 18:47:25 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PQTy60bgrz3vTH4; Mon, 27 Feb 2023 18:47:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PQTy575Cmz446k; Mon, 27 Feb 2023 18:47:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677523646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x8Sp9xx85vjUacFp0x74CliDhX9IxpMUfCF+H+rwE30=; b=EunJ8RXBH7hf7eM0yelTsa3ugEh0YVpd22SYAihxmsR/llt0awpBtI/LJ0QFM/yw7LyuLz 2oyhUx+X/lGqjWN274qomQMYVyGswykIgOzinq+OOeOHQQi0xkemUmSP+iKf8sP2s82j8H DA6t5mylYhTEm0h7Gu4vCCl7MjeOZBcYJK3tKZb20zpFuV3+Y9a3U0uXcF0jqtte0IZadz MbfkEJ+cPZgg5Tv1TYmDmUCPZQyfLTlIpIo4OBKbMnUKFDK7DtpT1tOJkLRQPw8DCHf5ih oA+7Wt4CHFcEOykwwBbGLDU8S8t57ukmoNqPMx2vKbFwUGlTk4g889sECsOepg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677523646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x8Sp9xx85vjUacFp0x74CliDhX9IxpMUfCF+H+rwE30=; b=Ibsf5KX6cbPJ78jfurbG7Fjp78HfM9zhrcUMrZSgcogDjJ/OgQvTTvXngasf5TStE6cxmI dEeFQvd3CNOgdnodTSgL/q7ttSsHT7DWUuL+CpToLqUZd99cwIr6s+u5mheedDDYx9UYif 9/UEyhhbcepYVASxL3etzjENchw5H4c54IIENF0f6Oy1q20BnaL44VkqufCbzx88SVVMNk Pfvt3mTQOv15iEXflbKuGKVVNFYjJZ6P8US6mulDGSZs+VelJh7UC17ozi6UL+yWtc5Evn Qei3bBE13HeeYaxx9haMGFC3jXTDsQ4GsnBeybTM/VQkcOafs4PHvYcHdeI/Sg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677523646; a=rsa-sha256; cv=none; b=ilBCe/hd4kBVNH0r2LtakxCsde8IWEVFWTIbsyT3AtmYAafzxUSI1AgvNe/pN2jldwTNGe yHuw5x5HALqWAfq6jTZQ5QAOom+SldsgKnGQStQWEQVFW2J93wdlLnzMVK16PX++l7dPvd n6Kb6aatKIWk7vgVrEnIo+9DZSpSx0wGL8TkyiQOyOKmTy6uuXVLGwUBM/O0YqH+muwf3D zwuAxAefXaAeiL4POIabQLaWKTP3AxEWGlI9RvISYNgd/2YJFgNCwhtr+/DskeogSXPzD9 fUJBNJVmFyGIRSROVMPkoJt9t+v5rit3H88OqZtxOmNuj3QboUx8r8wh5U9HVw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PQTy5697tzcVT; Mon, 27 Feb 2023 18:47:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31RIlPUo084507; Mon, 27 Feb 2023 18:47:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31RIlPTH084506; Mon, 27 Feb 2023 18:47:25 GMT (envelope-from git) Date: Mon, 27 Feb 2023 18:47:25 GMT Message-Id: <202302271847.31RIlPTH084506@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Cy Schubert Subject: git: ed4f9a251868 - releng/13.2 - ping: Fix unsigned integer underflow resuling in a ping -R segfault List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cy X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.2 X-Git-Reftype: branch X-Git-Commit: ed4f9a251868149dd738640568b2fc48338b39e1 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.2 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=ed4f9a251868149dd738640568b2fc48338b39e1 commit ed4f9a251868149dd738640568b2fc48338b39e1 Author: Cy Schubert AuthorDate: 2023-02-23 05:43:17 +0000 Commit: Cy Schubert CommitDate: 2023-02-27 18:46:42 +0000 ping: Fix unsigned integer underflow resuling in a ping -R segfault ping -R (F_RROUTE) will loop at ping.c:1381 until it segfaults or the unsigned int hlen happens to be less than the size of an IP header: slippy$ ping -R 192.168.0.101 PING 192.168.0.101 (192.168.0.101): 56 data bytes 64 bytes from 192.168.0.101: icmp_seq=0 ttl=63 time=1.081 ms RR: 192.168.0.1 192.168.0.101 192.168.0.101 10.1.1.254 10.1.1.91 unknown option bb unknown option 32 unknown option 6 ... unknown option 96 unknown option 2d Segmentation fault The reason for this is while looping through loose source routing (LSRR) and strict source routing (SSRR), hlen will become smaller than the IP header. It may even become negative. This should terminate the loop. However, when hlen is unsigned, an integer underflow occurs becoming a large number causing the loop to continue virtually forever until hlen is either by chance smaller than the lenghth of an IP header or it segfaults. Approved by: re (cperciva) Reviewed by: asomers Fixes: 46d7b45a267b Differential Revision: https://reviews.freebsd.org/D38744 (cherry picked from commit 70960bb86a3ba5b6f5c4652e613e6313a7ed1ac1) (cherry picked from commit 18936d3526f3090e4164b8155762bf5bd54038a8) --- sbin/ping/ping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index 6956b9a68ad2..2fc876e50776 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1150,7 +1150,7 @@ pr_pack(char *buf, ssize_t cc, struct sockaddr_in *from, struct timespec *tv) ssize_t icmp_data_raw_len; double triptime; int dupflag, i, j, recv_len; - uint8_t hlen; + int8_t hlen; uint16_t seq; static int old_rrlen; static char old_rr[MAX_IPOPTLEN]; @@ -1171,7 +1171,7 @@ pr_pack(char *buf, ssize_t cc, struct sockaddr_in *from, struct timespec *tv) hlen = (l & 0x0f) << 2; /* Reject IP packets with a short header */ - if (hlen < sizeof(struct ip)) { + if (hlen < (int8_t) sizeof(struct ip)) { if (options & F_VERBOSE) warn("IHL too short (%d bytes) from %s", hlen, inet_ntoa(from->sin_addr));