From nobody Wed Nov 05 15:34:02 2025 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 4d1q9k5F2Fz6GTtP; Wed, 05 Nov 2025 15:34:02 +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 4d1q9k3CqNz3Fkm; Wed, 05 Nov 2025 15:34:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1762356842; 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=Sx642bChyuM73m2/Z3ksJNP1DJFVsIN/pW/kIHK1KkM=; b=a8TMNEcF7s4rvPlJsK6CaEDXubRzvAbiKCyysov2f4roY4RK1KYyajmwgwBV5yKyHoxrss 3sKKBxVucpk/F13UBsfBkfZ9E2VitCmdW97MuA4uFShPUbpYUS8TCXxINSyYOwJghBqc8R JLKqgeUfzcF3zq5GE5gY/+07v7H77M845UxjAks6zYPFd+kF3DNpFyQDk48sf5ATT1Rqyv e9gKys+u3eZeO6o+o2rjQoj27FXxrk9LRgpDSo0U3QJVrUy47zgmmlDcq+DydX42DYijBI 7PxoFU3zXYp38fQrAcvSTWaYXR6EUMzvRqr4iVbz8IxlTi7edz71AQ1eCc/K0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1762356842; 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=Sx642bChyuM73m2/Z3ksJNP1DJFVsIN/pW/kIHK1KkM=; b=IZHErpMJS8OohpBKRop+PcJ+Y7IgQjLLw+qOAY9kjn+e5MJLIVI4co0C0hcg09/LPZ8XwH ha/BLaX82XZbJKUc61jWuqA1hOwmViu8TTLVIiFFV9flrtQSmMtyqYST2id5YClPSBBclJ 9xoVx0I9sucyEsxart7P0REwTAO6NEXSBnLI/FWhDCGx1AvE80Kg38AuGCwCMOOZoaDc8B W+8VSc2Ud7YpLTPxqcIOSSUK2u5oVtuZzYY9ke9Pj5DtT2G7lhqxi76XxqMeRpkozMAoRF 8yN/SKZEoU8kd2C7ZvmL525W67cXEBDT90Gjhu41oxsDAZqlQaFRc86E4ASoxg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1762356842; a=rsa-sha256; cv=none; b=G+JGXyzoKA4H4yzWbB5u36R30S9EED6jRjAArGkT/M3m2uZcs6WXGXOpda4CWUmJoEJ9gt sWUASqg+Q4ByWuu0XQybg2TocapOcXYthAbphq5aUtauP8Yr4w/8WlB+Ac3MYUrch11zm0 nfO9BhJ3rWkC3RarOWb3SdVB8KrkjD8wdzrABTJIPJKjFwwL72dq4vmNsVh2wfxAMURIVD j8w1kztjp6wNhSySczs5JEUcpLCL6ZEUks6MewSG3YedU2snLZvRR2M3HoLgBmX6tsqvaN 8PtrnmX86D17wd3AC5QRvGT1YNUJnXpllmYFLqUr1KObFnt5dxh9mhgjK6oW6w== 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 4d1q9k2l74zptH; Wed, 05 Nov 2025 15:34:02 +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 5A5FY2a1033328; Wed, 5 Nov 2025 15:34:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5A5FY26A033325; Wed, 5 Nov 2025 15:34:02 GMT (envelope-from git) Date: Wed, 5 Nov 2025 15:34:02 GMT Message-Id: <202511051534.5A5FY26A033325@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Cy Schubert Subject: git: df381bec2d2b - main - ipfilter: Don't trust userland supplied iph_size 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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/main X-Git-Reftype: branch X-Git-Commit: df381bec2d2b73697a3d163177df042dd272022d Auto-Submitted: auto-generated The branch main has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=df381bec2d2b73697a3d163177df042dd272022d commit df381bec2d2b73697a3d163177df042dd272022d Author: Cy Schubert AuthorDate: 2025-10-22 23:19:54 +0000 Commit: Cy Schubert CommitDate: 2025-11-05 15:32:17 +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 MFC after: 1 week Differential revision: https://reviews.freebsd.org/D53286 --- 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) {