Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Jun 2026 11:15:12 +0100
From:      Doug Rabson <dfr@rabson.org>
To:        Kristof Provost <kp@freebsd.org>
Cc:        freebsd-jail@freebsd.org
Subject:   Re: Running pfctl inside a jail
Message-ID:  <CACA0VUh5qz_5yG3kq9ov%2B=%2BSEcvN7KJiRgagrUatRPN964WbNg@mail.gmail.com>
In-Reply-To: <745947DE-75CC-4B1B-A0E4-0FAC7FF8E221@FreeBSD.org>
References:  <CACA0VUhJ78ES4AGMtLvZOVRJLoK=w=Vot%2BKSbx3Q=ikdC8UkFQ@mail.gmail.com> <96E80293-2013-452F-859C-B725EA7963CF@FreeBSD.org> <CACA0VUhigsCrqxrBySxptLCfh_K6%2BCb%2BT%2BDSJZgHnSMr0i9WOQ@mail.gmail.com> <7C23D3B8-1A14-41B7-839A-580DB61E0403@FreeBSD.org> <CACA0VUhPCX9AzJzaNYF=25PRgU4TeUMPn36CZhBrb8wPDdFX9w@mail.gmail.com> <745947DE-75CC-4B1B-A0E4-0FAC7FF8E221@FreeBSD.org>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
On Mon, 8 Jun 2026 at 10:42, Kristof Provost <kp@freebsd.org> wrote:

> On 8 Jun 2026, at 11:29, Doug Rabson wrote:
> > On Mon, 8 Jun 2026 at 09:37, Kristof Provost <kp@freebsd.org> wrote:
> >
> >> On 8 Jun 2026, at 10:00, Doug Rabson wrote:
> >>> In my smallest test-case, the host and jail use the same root
> filesystem
> >>> and the host is running 15.0-RELEASE-p8. I haven't tested with
> stable/15
> >>> yet.  This reproduces the problem for me:
> >>>
> >>> $ sudo pfctl -s nat
> >>> nat on bridge42 inet from <cni-nat> to any -> (bridge42) round-robin
> >>> nat on bridge42 inet6 from <cni-nat> to ! ff00::/8 -> (bridge42)
> >> round-robin
> >>> nat-anchor "cni-rdr/*" all
> >>> rdr-anchor "cni-rdr/*" all
> >>> $ cat jail-pfctl-15
> >>> #! /bin/sh
> >>> j=$(jail -ic name=pfctl-in-jail15 ip4=inherit ip6=inherit path=/
> persist)
> >>> jexec $j pfctl -s nat
> >>> jail -r $j
> >>> $ sudo ./jail-pfctl-15
> >>> pfctl: DIOCGETRULES: Operation not permitted
> >>> $ freebsd-version -k
> >>> 15.0-RELEASE-p8
> >>>
> >>>
> >>> Do the pf unit tests cover the case where the jail shares the host
> vnet?
> >>>
> >> Oh. No, no they do not. That’s just plain not supposed to work.
> >>
> >
> > Historically, though, it has always worked, at least as far back as
> > FreeBSD-13 so this is a regression.
> >
> >
> >> You only ever get to manage your own pf instance, never the one of a
> >> parent jail.
> >>
> >
> > It seems reasonable (to me at least) that if a jail inherits a vnet from
> > its parent, it should be able to manage that vnet. I see some evidence in
> > the history that at least parts of netlink are intended to work for jails
> > which don't have their own vnet (e.g.
> >
> https://cgit.freebsd.org/src/commit/sys/netlink?id=04f75b980293d517558990a7fda6900445edcac6
> ).
>
> That’s explicitly only for a handful of GET calls, not full management.
> For full management we’d need some way for users to specify that this is
> allowed, which we currently don’t have.
>
> I suspect the check you’re running into is
> https://cgit.freebsd.org/src/tree/sys/netlink/netlink_generic.c#n146
>
> I actually raised the question of how to delegate these privs to regular
> users (so not child jails, but that’s probably going to require the same
> mechanism) last year:
> https://lists.freebsd.org/archives/freebsd-arch/2025-September/001042.html
> That didn’t get any response and I didn’t chase it further at the time.
>

I like the idea of adding PRIV_NETINET_PF_RO and presumably adding jail
allow flag(s) to responsibly grant these privileges to a jail. I am not
entirely sure how that would work for users, though. I guess the MAC
framework sits in the right place but I don't understand MAC at all.

Doug.

[-- Attachment #2 --]
<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, 8 Jun 2026 at 10:42, Kristof Provost &lt;<a href="mailto:kp@freebsd.org">kp@freebsd.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 8 Jun 2026, at 11:29, Doug Rabson wrote:<br>
&gt; On Mon, 8 Jun 2026 at 09:37, Kristof Provost &lt;<a href="mailto:kp@freebsd.org" target="_blank">kp@freebsd.org</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; On 8 Jun 2026, at 10:00, Doug Rabson wrote:<br>
&gt;&gt;&gt; In my smallest test-case, the host and jail use the same root filesystem<br>
&gt;&gt;&gt; and the host is running 15.0-RELEASE-p8. I haven&#39;t tested with stable/15<br>
&gt;&gt;&gt; yet.  This reproduces the problem for me:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; $ sudo pfctl -s nat<br>
&gt;&gt;&gt; nat on bridge42 inet from &lt;cni-nat&gt; to any -&gt; (bridge42) round-robin<br>
&gt;&gt;&gt; nat on bridge42 inet6 from &lt;cni-nat&gt; to ! ff00::/8 -&gt; (bridge42)<br>
&gt;&gt; round-robin<br>
&gt;&gt;&gt; nat-anchor &quot;cni-rdr/*&quot; all<br>
&gt;&gt;&gt; rdr-anchor &quot;cni-rdr/*&quot; all<br>
&gt;&gt;&gt; $ cat jail-pfctl-15<br>
&gt;&gt;&gt; #! /bin/sh<br>
&gt;&gt;&gt; j=$(jail -ic name=pfctl-in-jail15 ip4=inherit ip6=inherit path=/ persist)<br>
&gt;&gt;&gt; jexec $j pfctl -s nat<br>
&gt;&gt;&gt; jail -r $j<br>
&gt;&gt;&gt; $ sudo ./jail-pfctl-15<br>
&gt;&gt;&gt; pfctl: DIOCGETRULES: Operation not permitted<br>
&gt;&gt;&gt; $ freebsd-version -k<br>
&gt;&gt;&gt; 15.0-RELEASE-p8<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Do the pf unit tests cover the case where the jail shares the host vnet?<br>
&gt;&gt;&gt;<br>
&gt;&gt; Oh. No, no they do not. That’s just plain not supposed to work.<br>
&gt;&gt;<br>
&gt;<br>
&gt; Historically, though, it has always worked, at least as far back as<br>
&gt; FreeBSD-13 so this is a regression.<br>
&gt;<br>
&gt;<br>
&gt;&gt; You only ever get to manage your own pf instance, never the one of a<br>
&gt;&gt; parent jail.<br>
&gt;&gt;<br>
&gt;<br>
&gt; It seems reasonable (to me at least) that if a jail inherits a vnet from<br>
&gt; its parent, it should be able to manage that vnet. I see some evidence in<br>
&gt; the history that at least parts of netlink are intended to work for jails<br>
&gt; which don&#39;t have their own vnet (e.g.<br>
&gt; <a href="https://cgit.freebsd.org/src/commit/sys/netlink?id=04f75b980293d517558990a7fda6900445edcac6" rel="noreferrer" target="_blank">https://cgit.freebsd.org/src/commit/sys/netlink?id=04f75b980293d517558990a7fda6900445edcac6</a>).<br>;
<br>
That’s explicitly only for a handful of GET calls, not full management. For full management we’d need some way for users to specify that this is allowed, which we currently don’t have.<br>
<br>
I suspect the check you’re running into is <a href="https://cgit.freebsd.org/src/tree/sys/netlink/netlink_generic.c#n146" rel="noreferrer" target="_blank">https://cgit.freebsd.org/src/tree/sys/netlink/netlink_generic.c#n146</a><br>;
<br>
I actually raised the question of how to delegate these privs to regular users (so not child jails, but that’s probably going to require the same mechanism) last year: <a href="https://lists.freebsd.org/archives/freebsd-arch/2025-September/001042.html" rel="noreferrer" target="_blank">https://lists.freebsd.org/archives/freebsd-arch/2025-September/001042.html</a><br>;
That didn’t get any response and I didn’t chase it further at the time.<br></blockquote><div><br></div><div>I like the idea of adding PRIV_NETINET_PF_RO and presumably adding jail allow flag(s) to responsibly grant these privileges to a jail. I am not entirely sure how that would work for users, though. I guess the MAC framework sits in the right place but I don&#39;t understand MAC at all.</div><div> <br>
</div><div>Doug.</div></div></div>
home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CACA0VUh5qz_5yG3kq9ov%2B=%2BSEcvN7KJiRgagrUatRPN964WbNg>