From nobody Fri Dec 19 18:06:00 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 4dXwSp13nGz6M9Fb for ; Fri, 19 Dec 2025 18:06: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 4dXwSm6rYsz44K6 for ; Fri, 19 Dec 2025 18:06:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1766167561; 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=NZ1L2CMjsTk7Z4NHDniTeibTP8c9lo78HBwPEGfN/bs=; b=YOFZ+w4ubQvuNvdIUN66MZEgBfO/Qv13A7wcQrEh33eb7V6CEJVYX5WEYl0i3zeumItvDJ 7f2ToPOaD7232K4hpM6oODgGxRFILRbWjf+LVc/FW4d77nz4nk779fYkREuCP1MpTedipo FTVKqBPgskweozb1MJwfmROwFTrfVgsOOdWHD1NTfguz8Fkzxni3rVEA5T3IwV9B2VpV5U NUvyUrp9DZqtpHOphkcJa0+OWHW1LOoM3dttOtYz3g/OmCyRLcMWJl0/22kmaNuXbqXg+m UA8DsPI39/IqISdFNATPpKepXpXLRcFR+8uIKsI5Rsdcrp8+eN0NG6UPeZ+NBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1766167561; 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=NZ1L2CMjsTk7Z4NHDniTeibTP8c9lo78HBwPEGfN/bs=; b=WIPaxDUzRkvkLRe+gpCagTwARESGsETB5cWgIcT1vwhbKg/UmU4foxEMBmCXgrhTpMgzyQ i98BqBugJ/+LmqREQP4/uESU8Dk36a4Kdk6W5WYoyEHlvNNnbCpP/4ubBrS+LuVP/mDufO TInthqeEmHFMT1gx7xiBud4Z1Js2udxgtGuPHOtwL1+raBsNNUNotFoEBOtKyJufsi+dHU QfFsOVvI5cDZKBTD4B9eBgFFQ0xHut9yRDqYYNS+vyq141kadbf+y6DG5F02baKnQ++SGq 7ofYlSr08Mn02yaAkYeZJWP34Eb0D8oMR2TIZBtO+WEPIIG+Fa2zjUI3Rg6gSg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1766167561; a=rsa-sha256; cv=none; b=PVO+94v0zQVcg/76BhZBv+u+P5nDIUomjQS9N996dPL1QeyB9gEfMIkQpIbQvRQK3atbUW EnFGpHia+Z+ZncrK7iIjIEtLT+nEWNsoQObhR0F2NhU8byDR+wyxpkR2x2fZviJMUl+Inq wYydRHGfxSkLdHQcWpyBHTnIoTugiXbAmlI6rP/6wh7a0ICphQFdjrIBYGuKIQ0VpeJ1LM A6b0Kn++cEZacdxDc6/GcqPmOcL69VP15cuCyX982HQUycv0zD0usDYaQ7nC9gPP3SxFlS i74+6xWXxAJtMmA6HP19u0ahAf8ChQC6U3LjJ66b1Vv/KKniOKfOw5sojOGaQg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dXwSm0qv4z4D1 for ; Fri, 19 Dec 2025 18:06:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 23b3a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 19 Dec 2025 18:06:00 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: 594ed1aab6f5 - stable/15 - ipfilter: Prevent stack buffer overflow 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: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 594ed1aab6f5666cd891151737489f448c039849 Auto-Submitted: auto-generated Date: Fri, 19 Dec 2025 18:06:00 +0000 Message-Id: <69459408.23b3a.3073b68c@gitrepo.freebsd.org> The branch stable/15 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=594ed1aab6f5666cd891151737489f448c039849 commit 594ed1aab6f5666cd891151737489f448c039849 Author: Dag-Erling Smørgrav AuthorDate: 2025-12-16 16:11:24 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-12-19 18:05:44 +0000 ipfilter: Prevent stack buffer overflow When copying ipfs data from user space, don't just check that the payload length is nonzero, but also that it does not exceed the size of the stack buffer we're copying it into. While we're at it, use a union to create a buffer of the exact size we need instead of guessing that 2048 will be enough (and not too much). Finally, check the size of the payload once it gets to where it's used. MFC after: 3 days Reported by: Ilja Van Sprundel Reviewed by: cy Differential Revision: https://reviews.freebsd.org/D54194 (cherry picked from commit a34c50fbd2a52bb63acde82e5aec4cb57880e39b) --- sbin/ipf/libipf/interror.c | 5 ++++ sys/netpfil/ipfilter/netinet/ip_sync.c | 51 ++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/sbin/ipf/libipf/interror.c b/sbin/ipf/libipf/interror.c index a8dc3be2d5d1..29923163212f 100644 --- a/sbin/ipf/libipf/interror.c +++ b/sbin/ipf/libipf/interror.c @@ -472,6 +472,11 @@ log" }, { 110019, "sync update could not find NAT entry" }, { 110020, "unrecognised sync NAT command" }, { 110021, "ioctls are not handled with sync" }, + /* missing entries 110022-110024 */ + { 110025, "invalid payload length (sync create state)" }, + { 110026, "invalid payload length (sync update state)" }, + { 110027, "invalid payload length (sync create NAT)" }, + { 110028, "invalid payload length (sync update NAT)" }, /* -------------------------------------------------------------------------- */ { 120001, "null data pointer for iterator" }, { 120002, "unit outside of acceptable range" }, diff --git a/sys/netpfil/ipfilter/netinet/ip_sync.c b/sys/netpfil/ipfilter/netinet/ip_sync.c index f6bc7e7fbe2a..b0be68148a18 100644 --- a/sys/netpfil/ipfilter/netinet/ip_sync.c +++ b/sys/netpfil/ipfilter/netinet/ip_sync.c @@ -409,13 +409,16 @@ ipf_sync_write(ipf_main_softc_t *softc, struct uio *uio) { ipf_sync_softc_t *softs = softc->ipf_sync_soft; synchdr_t sh; - - /* - * THIS MUST BE SUFFICIENT LARGE TO STORE - * ANY POSSIBLE DATA TYPE - */ - char data[2048]; - + union ipf_sync_data { + union ipf_sync_state_data { + ipstate_t create; + synctcp_update_t update; + } state; + union ipf_sync_nat_data { + nat_t create; + syncupdent_t update; + } nat; + } data; int err = 0; # if defined(__NetBSD__) || defined(__FreeBSD__) @@ -494,18 +497,18 @@ ipf_sync_write(ipf_main_softc_t *softc, struct uio *uio) * needed for the request */ - /* not supported */ - if (sh.sm_len == 0) { + /* too short or too long */ + if (sh.sm_len == 0 || sh.sm_len > sizeof(data)) { if (softs->ipf_sync_debug > 2) - printf("uiomove(data zero length %s\n", - "not supported"); + printf("uiomove(data) invalid length %d\n", + sh.sm_len); IPFERROR(110006); return (EINVAL); } if (uio->uio_resid >= sh.sm_len) { - err = UIOMOVE(data, sh.sm_len, UIO_WRITE, uio); + err = UIOMOVE(&data, sh.sm_len, UIO_WRITE, uio); if (err) { if (softs->ipf_sync_debug > 2) @@ -519,9 +522,9 @@ ipf_sync_write(ipf_main_softc_t *softc, struct uio *uio) sh.sm_len); if (sh.sm_table == SMC_STATE) - err = ipf_sync_state(softc, &sh, data); + err = ipf_sync_state(softc, &sh, &data); else if (sh.sm_table == SMC_NAT) - err = ipf_sync_nat(softc, &sh, data); + err = ipf_sync_nat(softc, &sh, &data); if (softs->ipf_sync_debug > 7) printf("[%d] Finished with error %d\n", sh.sm_num, err); @@ -651,6 +654,11 @@ ipf_sync_state(ipf_main_softc_t *softc, synchdr_t *sp, void *data) { case SMC_CREATE : + if (sp->sm_len != sizeof(sn)) { + IPFERROR(110025); + err = EINVAL; + break; + } bcopy(data, &sn, sizeof(sn)); KMALLOC(is, ipstate_t *); if (is == NULL) { @@ -717,6 +725,11 @@ ipf_sync_state(ipf_main_softc_t *softc, synchdr_t *sp, void *data) break; case SMC_UPDATE : + if (sp->sm_len != sizeof(su)) { + IPFERROR(110026); + err = EINVAL; + break; + } bcopy(data, &su, sizeof(su)); if (softs->ipf_sync_debug > 4) @@ -892,6 +905,11 @@ ipf_sync_nat(ipf_main_softc_t *softc, synchdr_t *sp, void *data) break; } + if (sp->sm_len != sizeof(*nat)) { + IPFERROR(110027); + err = EINVAL; + break; + } nat = (nat_t *)data; bzero((char *)n, offsetof(nat_t, nat_age)); bcopy((char *)&nat->nat_age, (char *)&n->nat_age, @@ -915,6 +933,11 @@ ipf_sync_nat(ipf_main_softc_t *softc, synchdr_t *sp, void *data) break; case SMC_UPDATE : + if (sp->sm_len != sizeof(su)) { + IPFERROR(110028); + err = EINVAL; + break; + } bcopy(data, &su, sizeof(su)); for (sl = softs->syncnattab[hv]; (sl != NULL);