From nobody Fri Nov 14 04:12:16 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 4d73cw2rxNz6GrKJ; Fri, 14 Nov 2025 04:12:16 +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 4d73cw1nSXz3HJD; Fri, 14 Nov 2025 04:12:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763093536; 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=6zEAZb3jErawdcyU2s2xY5LGj7+twuDb2GnW4gDOka0=; b=fW49XyoWwHlg9oPWh/LQnapWdoUm7G359LdZG21t87qXylaoSPB3pwc89IECmkP/q1JS9T 0IDEHIiOXJmcDPetZBs8y7a6UxYr5YPq6jjVoMCHmC8XG/Bp7p/X9XT7dyjSetqm1KmOKg zVDY5n+rxelUPNvTMYFo9aP7E4ezLnPl6a/RQsFQDLmx31LC1gYkjgaDVMyHMmswkDN0oo 4Cbum4HbVsZRjdEQxSPgkF/hjrxOO8MVV1APklVhHkUJQrcZCcdYNnJgnm+l8RXDei9Gh5 4iXoN4Aal4473Q1o5fAeqMeQfSyYq1SQXg7k4BglrOUey4+qWwMuZncxm58HuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763093536; 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=6zEAZb3jErawdcyU2s2xY5LGj7+twuDb2GnW4gDOka0=; b=WUgZxqQY+mL4HliHWPzlu4CXMkTAcr6MRBs4fjp0ABY+WKYOsxdzh2d+XF/4yrPpoHEY5z /IO7tEf+M9lYGa940W93R/Io1aqCVJzLV9zdpiKh+slZLWrgT9kk400xTMQI98ZcKtWzT1 pOHlp2JO4W9bbxjGc5PzrsEYW0m+AlIQmqG7gaP2Au0aUJtcsqR4qjh1RsDV/Nlv2p/SHt IZg5ZhzdqCttebOttSb04fEW9C95IjDY92/AYBUX0flrVS+xraTA8ZLFReinFe6efmj0hd Hdr/vgF8KmHKvbGb8cDuqeqsTkWEzdMOneAzMjyg2EOO3bRdZZ0xwlzMNYlwoA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763093536; a=rsa-sha256; cv=none; b=SDb9TrZyWooGYSjl4o9iLtEykaaOu1K1DzcT7PkYS6xYe29sKYDAAKf6xdg9OyuFREG8oi VmTp/e1rXZvraSNkkhe2SO/uIk5uaVhFGGQd9YSw/eUX6jgKTZYzMuj5rgn8ht9BRzGl1f HqhhAkbdLyHS8mmU5c8TlcDbKABVx28LIBNf556AtlWUwjZg/5S771knuhLdWAtvWNu3dU 9IcW/WpsuIBvywRFVMLociQT/OCEY8bq6Jpp419EHtDYgd4T6aovDUO9TxEhhBncpMAV4X BQAkyj+GbhYDbXz5cd6E12WEB6kBrmrA5nwlol8NDz71NYU9mF8nyAZv4AXvew== 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 4d73cw1LSVzrJr; Fri, 14 Nov 2025 04:12:16 +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 5AE4CGmm087277; Fri, 14 Nov 2025 04:12:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5AE4CGZ1087274; Fri, 14 Nov 2025 04:12:16 GMT (envelope-from git) Date: Fri, 14 Nov 2025 04:12:16 GMT Message-Id: <202511140412.5AE4CGZ1087274@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: dbe0b2c986cb - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: dbe0b2c986cbd4c01d5ba5a3b367aba9740c137b Auto-Submitted: auto-generated The branch stable/13 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=dbe0b2c986cbd4c01d5ba5a3b367aba9740c137b commit dbe0b2c986cbd4c01d5ba5a3b367aba9740c137b Author: Cy Schubert AuthorDate: 2025-10-22 23:19:54 +0000 Commit: Cy Schubert CommitDate: 2025-11-12 04:02:31 +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 c2a0fa269149..6d8c313ceb8b 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 numebr 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 28b3e7e82cec..fc0044651c70 100644 --- a/sys/netpfil/ipfilter/netinet/ip_htable.c +++ b/sys/netpfil/ipfilter/netinet/ip_htable.c @@ -366,6 +366,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) {