From nobody Mon Dec 8 16:15:25 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 4dQ6XG0GC8z6K2Wv for ; Mon, 08 Dec 2025 16:15:26 +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 4dQ6XF6PPKz3GP8 for ; Mon, 08 Dec 2025 16:15:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765210525; 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=D1kr5G5cnhnTZpcWPqEzu1rQ7H5AhFg6nr0iJo0gZIs=; b=uhsc4FYraoKJ44UXNCYzbu1CJCMX/3BlU5n8bMaYq/neeI50h9lHZ7aECzRt2qL2u1Pvfz 5BJ/pW1zxXge62t6iEcM83Q/+f14yURj3ffXUcyYXuaiJnPZcRXQ3V+CVRM0EqrWUgcTFr vndtaLSHMbW/3t7ZQ0mDbPsLYYWAMM+xpns/F/d1suZIfyudv5dVl346K9U5QoVQaXMb9b KQhqxYvx7qahoaSqrXLTedw3vbJOa4LAeqRYqDFTdHS9QE3S3RVZiN4wTCCIX6UUXQfCRN gMGeTX1rQh7ijpFDCpAFoMTelL5nSrYrEizA7W0BljUBO+dYTQB20+rJovoURg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765210525; 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=D1kr5G5cnhnTZpcWPqEzu1rQ7H5AhFg6nr0iJo0gZIs=; b=oI4MypQDilQryzSxunBzN9yn22FyKJ+ZIfyYqhh2bWGY0+V0vzTEpOPYkBrF05LLMRq299 YSDkJQ6kYnjLuxymiuIsVAdXKUexio4zJqYI9kUr4tk1gBDM/IGZ+NGbt+miWRzZFh4V9t fayh37NBPbFEa88KEVr1BzySoe4KBxGn77vEANcalfTeSBBjFWa425jji9zmleT+qGR2SC +o8JcQJn+4QriWnzgYdMVsP3DvE8MFfz8238E5d85KjM1mIJxS79a2BHSNshISFVnJQs3t dOS0a4PYML38x2B9xuS1t4D/iwUgat57ALYgxsv4GURf8KWUpGitnIXjZrbuZA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765210525; a=rsa-sha256; cv=none; b=SKQocWOpbNbc0g/XLXsC/z4Uhp0hlyKCv3Mm6pKLtttbwpZsB5LaX1VehfphMYbOvLmTG+ i/oNaj8XU37Hiuvv2abTw/2sGR0pHU7+I1Qa0Fltt6Cl/BMCkZiU32pkM2zYXTmjIQj8qA 1j9KNaALvCc2sHp9yE1uNdzK6QLMF4T+GMfLVpJg8y0n2a7E4cgUNZ3VAwSTfE2tJSUbmA GRMy0gvq+t4WzJJfL+RWltV/Dpjltqk76CjyFdYj3kcSHn/kdjYDYFeeOQbMarfHG9N6j8 p/CRWDGKDU5w6cQ8uDBMI2Rr6OfFwZIxYH76k5NQgPmhSFkubtwvdW3/F80lEQ== 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 4dQ6XF5kY1z4VW for ; Mon, 08 Dec 2025 16:15:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3ab3f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 08 Dec 2025 16:15:25 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Cy Schubert Subject: git: d9788eabffa4 - main - 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/main X-Git-Reftype: branch X-Git-Commit: d9788eabffa4b67fc534685fc3d9b8e3334af196 Auto-Submitted: auto-generated Date: Mon, 08 Dec 2025 16:15:25 +0000 Message-Id: <6936f99d.3ab3f.185d9547@gitrepo.freebsd.org> The branch main has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=d9788eabffa4b67fc534685fc3d9b8e3334af196 commit d9788eabffa4b67fc534685fc3d9b8e3334af196 Author: Cy Schubert AuthorDate: 2025-10-29 18:29:39 +0000 Commit: Cy Schubert CommitDate: 2025-12-08 16:15:18 +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 --- 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 6d5391f58ba2..2bbecaa154e6 100644 --- a/sbin/ipf/libipf/interror.c +++ b/sbin/ipf/libipf/interror.c @@ -531,6 +531,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 0c5e22517dc4..242affeff000 100644 --- a/sys/netpfil/ipfilter/netinet/fil.c +++ b/sys/netpfil/ipfilter/netinet/fil.c @@ -9096,6 +9096,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