From nobody Mon Jan 5 20:02:57 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 4dlQFt1Zwdz6MyXv for ; Mon, 05 Jan 2026 20:02:58 +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 4dlQFs6sjrz3K7C for ; Mon, 05 Jan 2026 20:02:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767643378; 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=/xWOkilxiOpSHs6UC8PwHAuPcvzSxs3YIv0XsqCUpPE=; b=B9Xuf+kbWjCV3O/jYEpdCCY0i1OeiZ71YSEzponjGr+XfKXYu6K5sFRASLvHx4Da/eGMHy vJV+EJaK3x89pddHo1VXdX+ffyunamsyT2S3u5iNhjtmpePrGJ1PJKTQDNyaMjoXiD6pj6 x1tva9WM4bEDOs6cnnK7AItkT6RC6RlRUhgBTSAOvLAlNHGk2nICjWcAlH3dTxnVnhFKGO 3rYLI8aGaYLFe+N3+x/sUHhyrg1DsTxzw0NksSzO0GNuOmNOYOex4phAicxCE5rvH4KJkF 3QGzEisYJspfqaG7ml8TyaBiysQDTKBWALIx1f3W9DPKSl3dQfBYjHrDCUojSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1767643378; 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=/xWOkilxiOpSHs6UC8PwHAuPcvzSxs3YIv0XsqCUpPE=; b=JAM2bOaVemZkFbJ1Sc5WV6jOscSgNEommfdFJ2n7Fb2s/lupAPiIFUFXXnmRMxK6Yd8rnw aZzO/uRpd6WIzZboUSKNrG52emRO3PsPVW0yXp5Qclf8BqTdXvM1UhRmaYL7rNFLtqzZDa QQvV9Ax0eco29fDlvKFdr2CrtQDtL+/6jCLE7UZ5g7Qj/vTk99MsRk29A7PyNr3BEo5XG7 VQv/ddjGP02KWGsN2TrIcpW+I3u9MM9r5qTDNSZyX5LP3Oy0hNm+EGpjZXXtc1MSqRU0aL ziG/40efhiwXI/yF7VwtqpZBXu/L4vJNAXKX/gKTOKDVhHO/qVIWDEZTp8NmMg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1767643378; a=rsa-sha256; cv=none; b=hJAmutgnsBqrEIm4q03QjeeHNI4uygrBKKOVXtzy/IZvW3q9QyZcgLw8fe9iOs1NQZAhWN lx0vH15GIK9CcqBPWCYaVJG9gw66fdiQXDJOIIr1UunaBpMudjE0K4MYRir2SDPsK9xhz4 uTSZGZqOJpAovwYfMw63rMer37SBupSZsGexD2+JCRWFIWKFHMeZTUUUFdrIuSQ/qAo/4E 7eTrDkv7zwM9M6oMzuC2oSCRlxoQLPjDD0EeCaIUEzCawAHm+oD9Dy0TJRhMuw1SDf4xfa qAfFke0TLrl8FJbURlmIGJvT2+uAza1fzEsBL/ApLU9VfdHUg2yeYcsuceXBWQ== 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 4dlQFs6HKYzbbx for ; Mon, 05 Jan 2026 20:02:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 8309 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 05 Jan 2026 20:02:57 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Cy Schubert Subject: git: e3b9f73e126e - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: e3b9f73e126e5b75142c1efbd825da3f0944b49f Auto-Submitted: auto-generated Date: Mon, 05 Jan 2026 20:02:57 +0000 Message-Id: <695c18f1.8309.220dd91a@gitrepo.freebsd.org> The branch stable/13 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=e3b9f73e126e5b75142c1efbd825da3f0944b49f commit e3b9f73e126e5b75142c1efbd825da3f0944b49f Author: Cy Schubert AuthorDate: 2025-10-29 18:29:39 +0000 Commit: Cy Schubert CommitDate: 2026-01-05 03:40:11 +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 5619b24200d7..89f1e7f9ec3c 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 545ef657217d..786efca38232 100644 --- a/sys/netpfil/ipfilter/netinet/fil.c +++ b/sys/netpfil/ipfilter/netinet/fil.c @@ -9102,6 +9102,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 821d63664859..4bbb19c889bd 100644 --- a/sys/netpfil/ipfilter/netinet/ip_fil.h +++ b/sys/netpfil/ipfilter/netinet/ip_fil.h @@ -1552,6 +1552,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 89e5be506be2..a5f634247a1a 100644 --- a/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c +++ b/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c @@ -92,6 +92,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 @@ -278,6 +279,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 0edaf666ecd8..b11dea53029b 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