From nobody Fri Nov 14 04:10:35 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 4d73Zz4hxRz6Gr5K; Fri, 14 Nov 2025 04:10: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 4d73Zz3jR9z3DYt; Fri, 14 Nov 2025 04:10:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763093435; 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=ucn1Iq9cexHvIBq+txE8aIzOKjsk1TIRQGIVP1Mxz6o=; b=gylW2RF23rupDsMrLbKleRo4dA+UXKFyfL1Kyzgf2SHl+zTQIP6YaQdsQbGmzJzFdH3XO+ 1OsBjJ/9VmRAl06ikoACrGBwx1QaWLk9qKfoN4uosqCKBoFQ2P8gnKWq8giS6z+mzClzMK 5gHUgPW+FimPXmifqQXh6BdiqjvyTaC0sKoIBzBZhiDt3qXfwlN+iwVBIEoxGMBOOH6mgg sQZ6/o1iLYAnPu+pixPGOrp7/6PA0iuWovzExwq3kN6XxfF+SL+dsmcs9r9O+WT4HYHD+L vsIsiXMZ5burK9/SSbSLEpy6ca2wg7nj+97uLUT3sn2npPRO6Bk3gAI7/fKHDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763093435; 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=ucn1Iq9cexHvIBq+txE8aIzOKjsk1TIRQGIVP1Mxz6o=; b=pAr6ai2YO+2+Y7TfDt8axKwhY8d7IYNCkRL5ahXs9SFTAuJfYXRkBPiddAslEZVtADX7H7 hEonoBQzOaD6xpEh0fr+DwS3+I3s/SYPrf9c8p41BushYiJd1Lb9R9NIyld1hQcgYqZNXo TKqPMNL9ap37MqBMksSXuxIqyJ8ydk8V6NXI0iVdNVZuRYsHFWHGVDR83FZxJQVE6p9pwa WRWXWYxIIIWfEPGEqNLejIldgzKT3ZLpQ6Go2XIZl2x3jz3Tk54M/8R0QhjP9BhuIgz4kb JfB47pVUBhTbhABR+XvLrKGNM7PbHJ110wIhyGQcwRTCSKs6pk+ZKoyEX5Bt9Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763093435; a=rsa-sha256; cv=none; b=xhmS3d3UDs019iP7M2aXyav7vcF/ZPRaDjExv5++CiwVkNy4X7/WAO1AToqsSE2gVc8k03 zlzJVswV8WKY/8+8kobs1gEJB66vWyQKYpKbEduEGTM0lmmvMALVZTus/uIa6YwBmuBh4e qtA4A0FNV05qP83GUESHBapdgLNQJqDtrp+zLtHwYkelwcRViXKcSClA0kgPHgwrGttri7 WzX0uUdngWhneIOBZZdEmVsj2yIa3TO5a2KMKeYulQGamNwgBN1KbfYKqnL1SSUXsDCPlc 7teAxx4n1F3jjR0JoHLOGHSdgJfJL66xBej+rxFZCJ8C9in0TylbVEnKZpYBFQ== 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 4d73Zz2yHbzr0m; Fri, 14 Nov 2025 04:10:35 +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 5AE4AZbE082128; Fri, 14 Nov 2025 04:10:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5AE4AZdD082125; Fri, 14 Nov 2025 04:10:35 GMT (envelope-from git) Date: Fri, 14 Nov 2025 04:10:35 GMT Message-Id: <202511140410.5AE4AZdD082125@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: 4fa6c0b831ba - stable/15 - 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/15 X-Git-Reftype: branch X-Git-Commit: 4fa6c0b831ba80a2f32eca273ca1116095ed4190 Auto-Submitted: auto-generated The branch stable/15 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=4fa6c0b831ba80a2f32eca273ca1116095ed4190 commit 4fa6c0b831ba80a2f32eca273ca1116095ed4190 Author: Cy Schubert AuthorDate: 2025-10-22 23:19:54 +0000 Commit: Cy Schubert CommitDate: 2025-11-14 04:10:22 +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 cbfb210c85d3..a8dc3be2d5d1 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 39777508731f..5f5c04732d69 100644 --- a/sys/netpfil/ipfilter/netinet/ip_htable.c +++ b/sys/netpfil/ipfilter/netinet/ip_htable.c @@ -361,6 +361,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) {