From nobody Mon Jan 5 20:00:35 2026 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 4dlQC73B3Kz6MyTC for ; Mon, 05 Jan 2026 20:00: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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dlQC71wHdz3Cdh for ; Mon, 05 Jan 2026 20:00:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767643235; 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=XpwUycS9s0Z/OeXL6PR5gUVVLX7hQG1qVnhtwtNd6hc=; b=SjcbMHTs0Egs/eB1oJPYLMS0McJnbfclF4BD+p1Ph+IkjTuMtwENi1XcVaM03pQlERw6RS YOepv6+FphHU3Tf/ljQZ0hch36whZBU5vHzbaAeC8Qel9tUunY5wOPh4QiR/coYYraoAAp gJVhcxSs6cdXXNxkfWpmnVffyzTbWePVwJPyvPXS70yvJ91KcVbrL1X8tV9cEdLkDEJIMm nU+Jl3j0cFFVSmBUG6m0OwKMJVOKCTcZPir0CFiuPrrnzKy4nR9UdEejK8J8ZW60dFWRrG vuJxzQF6DGSoHDjKdwoxnf7SnQJCQjEF4IE3KpjgR68Fpgd956C+GMMdwTOQSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767643235; 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=XpwUycS9s0Z/OeXL6PR5gUVVLX7hQG1qVnhtwtNd6hc=; b=lN+Wvt5hszF9FUwF5cBtS5dI0aX4u12+EaJrrGnpPjAE2RjEjpGByinO8MVV52KgA52dxR jOX9EyNecSsa9udFN+ynxW+pE5kBczcwa58JNgPNitKecgQM0ZbMkS1Z/Wy/JHjVFIk3yS BmEUhMzGXHUNyFpikYmsANHkLgWLLncCi0XSM4NKkAUVVyj7Unaf58k1+SNxVDXYx5s4Q3 a34l8hgXGUXooqzkTVNwHVCIL4jXXNiaLGnBy/iahPSqL8Hwc3NG3qqZqbN6QxpHxeBWZK jCt1+x8h6vXuR1Ne3DSETDKmSReR+TxQ2NUdVI5Bpl1U2X19xgs1kJrrvT5z1g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1767643235; a=rsa-sha256; cv=none; b=k4V3Ccyv19mEat0l6Z8mkDYdEM+OhuhI3X7Kcf8H9lF1Vlt0mz2kNfXhP80Si5GwMNBmJk DWn1lSg2Y1pVr+Y9HRZ32ju8jM0L5Z9XlB+Hcm0GJlPA0M6OuRK0P94+PVaWUavehowpct cOWfgRLozK1h1O6a4T7ZPI8SV9cHvEuKhylxJZZfAWjAJl8p9dqJGFsk8Xw7UbiifvrYh2 RKwUKJ5zB8urxAz3pnZTF9ZNvoeHIg6qsXhGzdcOBXVZR7jNgHaJFkdHC9qh3yx6jcHzs9 w/epow5fR1GQvdadVlZB03H+Hh5prlADjF6BX82wYZkE/HuNy5MWo0hrR/SlMA== 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 4dlQC71WmNzb58 for ; Mon, 05 Jan 2026 20:00:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 865c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 05 Jan 2026 20:00:35 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Cy Schubert Subject: git: 65bc0a1ade72 - stable/15 - ipfilter: Restrict ipfilter within a jail 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/stable/15 X-Git-Reftype: branch X-Git-Commit: 65bc0a1ade72af8941f2d0c8ae00fdb11c1d6e9b Auto-Submitted: auto-generated Date: Mon, 05 Jan 2026 20:00:35 +0000 Message-Id: <695c1863.865c.363fd3ac@gitrepo.freebsd.org> The branch stable/15 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=65bc0a1ade72af8941f2d0c8ae00fdb11c1d6e9b commit 65bc0a1ade72af8941f2d0c8ae00fdb11c1d6e9b Author: Cy Schubert AuthorDate: 2025-10-29 18:29:39 +0000 Commit: Cy Schubert CommitDate: 2026-01-05 20:00:00 +0000 ipfilter: Restrict ipfilter within a jail Add a sysctl/tunable (net.inet.ipf.jail_allowed) to control whether a jail can manage its own ipfilter rules, pools, and settings. A jail's control over its own ipfilter rules and settings may not be desireable. The default is jail access to ipfilter is denied. The host system can stil manage a jail's rules by attaching the rules, using the on keyword, limiting the rule to the jail's interface. Or the sysctl/tunable can be enabled to allow a jail control over its own ipfilter rules and settings. Implementation note: Rather than store the jail_allowed variable, referenced by sysctl(9), in a global area, storing the variable in the ipfilter softc is consistent with ipfilter's use of its softc. Discussed with: emaste, jrm MFC after: 1 week Differential revision: https://reviews.freebsd.org/D53623 (cherry picked from commit d9788eabffa4b67fc534685fc3d9b8e3334af196) --- sbin/ipf/libipf/interror.c | 1 + sys/netpfil/ipfilter/netinet/fil.c | 1 + sys/netpfil/ipfilter/netinet/ip_fil.h | 1 + sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c | 15 +++++++++++++++ sys/netpfil/ipfilter/netinet/mlfk_ipl.c | 1 + 5 files changed, 19 insertions(+) diff --git a/sbin/ipf/libipf/interror.c b/sbin/ipf/libipf/interror.c index 7634753967e6..a7e6f4a5e431 100644 --- a/sbin/ipf/libipf/interror.c +++ b/sbin/ipf/libipf/interror.c @@ -536,6 +536,7 @@ log" }, { 130016, "finding pfil head failed" }, { 130017, "ipfilter is already initialised and running" }, { 130018, "ioctl denied in jail without VNET" }, + { 130019, "ioctl denied in jail" }, }; diff --git a/sys/netpfil/ipfilter/netinet/fil.c b/sys/netpfil/ipfilter/netinet/fil.c index 0de5378322df..54b8aea7f1c8 100644 --- a/sys/netpfil/ipfilter/netinet/fil.c +++ b/sys/netpfil/ipfilter/netinet/fil.c @@ -9098,6 +9098,7 @@ ipf_main_soft_create(void *arg) softc->ipf_icmpminfragmtu = 68; softc->ipf_max_namelen = 128; softc->ipf_flags = IPF_LOGGING; + softc->ipf_jail_allowed = 0; #ifdef LARGE_NAT softc->ipf_large_nat = 1; diff --git a/sys/netpfil/ipfilter/netinet/ip_fil.h b/sys/netpfil/ipfilter/netinet/ip_fil.h index 7b070f0d6867..24d4f9695322 100644 --- a/sys/netpfil/ipfilter/netinet/ip_fil.h +++ b/sys/netpfil/ipfilter/netinet/ip_fil.h @@ -1550,6 +1550,7 @@ typedef struct ipf_main_softc_s { u_int ipf_icmpacktimeout; u_int ipf_iptimeout; u_int ipf_large_nat; + u_int ipf_jail_allowed; u_long ipf_ticks; u_long ipf_userifqs; u_long ipf_rb_no_mem; diff --git a/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c b/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c index 6eb6cf2a7a47..43b590cc0204 100644 --- a/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c +++ b/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c @@ -88,6 +88,7 @@ VNET_DEFINE(ipf_main_softc_t, ipfmain) = { .ipf_running = -2, }; #define V_ipfmain VNET(ipfmain) +#define V0_ipfmain VNET_VNET(vnet0,ipfmain) #include #include @@ -254,6 +255,20 @@ ipfioctl(struct cdev *dev, ioctlcmd_t cmd, caddr_t data, return (EPERM); } + /* + * Remember, the host system (with its vnet0) controls + * whether a jail is allowed to use ipfilter or not. + * The default is ipfilter cannot be used by a jail + * unless the sysctl allows it. + */ + if (V0_ipfmain.ipf_jail_allowed == 0) { + if (jailed(p->p_cred)) { + V_ipfmain.ipf_interror = 130019; + CURVNET_RESTORE(); + return (EOPNOTSUPP); + } + } + if (jailed_without_vnet(p->p_cred)) { V_ipfmain.ipf_interror = 130018; CURVNET_RESTORE(); diff --git a/sys/netpfil/ipfilter/netinet/mlfk_ipl.c b/sys/netpfil/ipfilter/netinet/mlfk_ipl.c index d558b2d24b2c..139fe1f766d3 100644 --- a/sys/netpfil/ipfilter/netinet/mlfk_ipl.c +++ b/sys/netpfil/ipfilter/netinet/mlfk_ipl.c @@ -136,6 +136,7 @@ SYSCTL_IPF(_net_inet_ipf, OID_AUTO, fr_chksrc, CTLFLAG_RW, &VNET_NAME(ipfmain.ip SYSCTL_IPF(_net_inet_ipf, OID_AUTO, fr_minttl, CTLFLAG_RW, &VNET_NAME(ipfmain.ipf_minttl), 0, ""); SYSCTL_IPF(_net_inet_ipf, OID_AUTO, large_nat, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &VNET_NAME(ipfmain.ipf_large_nat), 0, "large_nat"); SYSCTL_IPF(_net_inet_ipf, OID_AUTO, fr_max_namelen, CTLFLAG_RWTUN, &VNET_NAME(ipfmain.ipf_max_namelen), 0, "max_namelen"); +SYSCTL_IPF(_net_inet_ipf, OID_AUTO, jail_allowed, CTLFLAG_RWTUN, &VNET_NAME(ipfmain.ipf_jail_allowed), 0, "jail_allowed"); #define CDEV_MAJOR 79 #include