From nobody Fri Nov 14 04:11:34 2025 X-Original-To: dev-commits-src-branches@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 4d73c727xlz6Grdb; Fri, 14 Nov 2025 04:11:35 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4d73c70gwSz3G26; Fri, 14 Nov 2025 04:11:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763093495; 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=Nq7rXjfO+9FjGKnv3F5dg2U0RcbHhyUHRlQix7eYx0Y=; b=mcxFkH8JtLNtaWQOgB52PIxa3w70idlP+YkMm9tw5OnHjtk80Zu35VrJwF6rjNMy5D9RCD 5JhAFd+iez942U3w/mGv1u2B5eJwwm+L+0wM12+sMDXOX67HdBiihwapDyxyDiw5UhWeWz gQ9xuE86LC+qXc+kWNLnBSsyf/65IH/J/VVdzGFNMKZ4GhaecfhC4PUk9blrZLEV+bXxL5 /SjmZ8R00ur7gvqrMxbt3rPf6WSMxIMO9mLi2xZp2ImkQiTwq/c7ZbDXfhTK1M+WNC9DOD DhF1bHh2MdONqeYAeg/QlI0auKArhwIJHVLJjE8W91Mx9hcUolgMh2LyWbJNag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763093495; 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=Nq7rXjfO+9FjGKnv3F5dg2U0RcbHhyUHRlQix7eYx0Y=; b=lgebbr9nRdnCxJXm4IS9q7ej68ZaA652mOwp9xyBSdf/5mvX3TYxX1WxaAiob0Dm8KsIAC b28V3pNM7pRhS6mpbQ3+A/0uyLtI4+HAsiytwVGBywN6ToQZo3MY9pXGZI4V1CqCCVUOrg 8tMlU0hmYONlyxygyN4nl15W3EYNboyPkuRnjX5FpbF4J73s7IZJ2reu6bmRFVVecyFmRZ Q74mWhAlhZT0M8fiJsoDTAxWZdWO7l9TbDCcDsT3B3Kmm65rc8qFW7NBhg5XVT3gU5e9Mw 5BESWEOUUj86E2H+sy08Mfo2mJitVS0r/H1Q6Yk9C0OGKpb8+LQVt8UyBHXNmw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763093495; a=rsa-sha256; cv=none; b=vetEeudW9J4xD7xLItb5Aups2syz+S7UPMTePDU0a+SDLPKfJLhbmgqq8wA7aERJh524DS 4q4KpnAraS7pZuJeVKJ13bhzlLVsmIByZCisgkAPuKU2QciL8V05fCH4VmQ48DQ/4nbiek 7vAX2+pjACBb2GvpcF5Ile0l397BLuNMzlNPIKESDGDaHE3pTP7UiQU6Wm9PA5Fvb1Nn/t 8auH+cM+T1R3ALcu0dT+Ii0KrIMomnbwZNVL9LV2jxDIlZP2ssWUaY0cXugovUONs8uiPL VCeYXA2bUkbEV17oYJyRYuu4GyS5QElZL89zLj3NfBcxxwWBQYRmXLY7NxVV1g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4d73c66rVlzrXS; Fri, 14 Nov 2025 04:11:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5AE4BY5Q083715; Fri, 14 Nov 2025 04:11:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5AE4BYXQ083712; Fri, 14 Nov 2025 04:11:34 GMT (envelope-from git) Date: Fri, 14 Nov 2025 04:11:34 GMT Message-Id: <202511140411.5AE4BYXQ083712@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: 794a904b454b - stable/14 - ipfilter: Don't trust userland supplied iph_size List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 794a904b454b22c27cea04d209a5fc74972b0fa6 Auto-Submitted: auto-generated The branch stable/14 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=794a904b454b22c27cea04d209a5fc74972b0fa6 commit 794a904b454b22c27cea04d209a5fc74972b0fa6 Author: Cy Schubert AuthorDate: 2025-10-22 23:19:54 +0000 Commit: Cy Schubert CommitDate: 2025-11-14 04:11:16 +0000 ipfilter: Don't trust userland supplied iph_size ipf_htable_create() trusts a user-supplied iph_size from iphtable_t and computes the allocation size as iph->iph_size * sizeof(*iph->iph_table) without checking for integer overflow. A sufficiently large iph_size causes the multiplication to wrap, resulting in an under-sized allocation for the table pointer array. Subsequent code (e.g., in ipf_htent_insert()) can then write past the end of the allocated buffer, corrupting kernel memory and causing DoS or potential privilege escalation. This is not typically a problem when using the ipfilter provided userland tools as calculate the correct lengths. This mitigates a rogue actor calling ipfilter ioctls directly. Reported by: Ilja Van Sprundel Reviewed by: markj Differential revision: https://reviews.freebsd.org/D53286 (cherry picked from commit df381bec2d2b73697a3d163177df042dd272022d) --- sbin/ipf/libipf/interror.c | 2 ++ sys/netpfil/ipfilter/netinet/ip_htable.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/sbin/ipf/libipf/interror.c b/sbin/ipf/libipf/interror.c index 04fc53c863fe..5b3836f36d60 100644 --- a/sbin/ipf/libipf/interror.c +++ b/sbin/ipf/libipf/interror.c @@ -228,6 +228,8 @@ static ipf_error_entry_t ipf_errors[] = { { 30024, "object size incorrect for hash table" }, { 30025, "hash table size must be at least 1"}, { 30026, "cannot allocate memory for hash table context" }, + { 30027, "hash table larger than maximum allowed" }, + { 30028, "hash table multiplication overflow" }, /* -------------------------------------------------------------------------- */ { 40001, "invalid minor device number for log read" }, { 40002, "read size too small" }, diff --git a/sys/netpfil/ipfilter/netinet/ip_htable.c b/sys/netpfil/ipfilter/netinet/ip_htable.c index 94741d589601..ca9e96698245 100644 --- a/sys/netpfil/ipfilter/netinet/ip_htable.c +++ b/sys/netpfil/ipfilter/netinet/ip_htable.c @@ -364,6 +364,15 @@ ipf_htable_create(ipf_main_softc_t *softc, void *arg, iplookupop_t *op) iph->iph_name[sizeof(iph->iph_name) - 1] = '\0'; } + if ((iph->iph_size == 0) || + (iph->iph_size > softh->ipf_htable_size_max)) { + IPFERROR(30027); + return (EINVAL); + } + if (iph->iph_size > ( SIZE_MAX / sizeof(*iph->iph_table))) { + IPFERROR(30028); + return (EINVAL); + } KMALLOCS(iph->iph_table, iphtent_t **, iph->iph_size * sizeof(*iph->iph_table)); if (iph->iph_table == NULL) {