Skip to content

Commit d9788ea

Browse files
committed
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
1 parent 0f0662c commit d9788ea

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

sbin/ipf/libipf/interror.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ log" },
531531
{ 130016, "finding pfil head failed" },
532532
{ 130017, "ipfilter is already initialised and running" },
533533
{ 130018, "ioctl denied in jail without VNET" },
534+
{ 130019, "ioctl denied in jail" },
534535
};
535536

536537

sys/netpfil/ipfilter/netinet/fil.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9096,6 +9096,7 @@ ipf_main_soft_create(void *arg)
90969096
softc->ipf_icmpminfragmtu = 68;
90979097
softc->ipf_max_namelen = 128;
90989098
softc->ipf_flags = IPF_LOGGING;
9099+
softc->ipf_jail_allowed = 0;
90999100

91009101
#ifdef LARGE_NAT
91019102
softc->ipf_large_nat = 1;

sys/netpfil/ipfilter/netinet/ip_fil.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,7 @@ typedef struct ipf_main_softc_s {
15501550
u_int ipf_icmpacktimeout;
15511551
u_int ipf_iptimeout;
15521552
u_int ipf_large_nat;
1553+
u_int ipf_jail_allowed;
15531554
u_long ipf_ticks;
15541555
u_long ipf_userifqs;
15551556
u_long ipf_rb_no_mem;

sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ VNET_DEFINE(ipf_main_softc_t, ipfmain) = {
8888
.ipf_running = -2,
8989
};
9090
#define V_ipfmain VNET(ipfmain)
91+
#define V0_ipfmain VNET_VNET(vnet0,ipfmain)
9192

9293
#include <sys/conf.h>
9394
#include <net/pfil.h>
@@ -254,6 +255,20 @@ ipfioctl(struct cdev *dev, ioctlcmd_t cmd, caddr_t data,
254255
return (EPERM);
255256
}
256257

258+
/*
259+
* Remember, the host system (with its vnet0) controls
260+
* whether a jail is allowed to use ipfilter or not.
261+
* The default is ipfilter cannot be used by a jail
262+
* unless the sysctl allows it.
263+
*/
264+
if (V0_ipfmain.ipf_jail_allowed == 0) {
265+
if (jailed(p->p_cred)) {
266+
V_ipfmain.ipf_interror = 130019;
267+
CURVNET_RESTORE();
268+
return (EOPNOTSUPP);
269+
}
270+
}
271+
257272
if (jailed_without_vnet(p->p_cred)) {
258273
V_ipfmain.ipf_interror = 130018;
259274
CURVNET_RESTORE();

sys/netpfil/ipfilter/netinet/mlfk_ipl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ SYSCTL_IPF(_net_inet_ipf, OID_AUTO, fr_chksrc, CTLFLAG_RW, &VNET_NAME(ipfmain.ip
136136
SYSCTL_IPF(_net_inet_ipf, OID_AUTO, fr_minttl, CTLFLAG_RW, &VNET_NAME(ipfmain.ipf_minttl), 0, "");
137137
SYSCTL_IPF(_net_inet_ipf, OID_AUTO, large_nat, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &VNET_NAME(ipfmain.ipf_large_nat), 0, "large_nat");
138138
SYSCTL_IPF(_net_inet_ipf, OID_AUTO, fr_max_namelen, CTLFLAG_RWTUN, &VNET_NAME(ipfmain.ipf_max_namelen), 0, "max_namelen");
139+
SYSCTL_IPF(_net_inet_ipf, OID_AUTO, jail_allowed, CTLFLAG_RWTUN, &VNET_NAME(ipfmain.ipf_jail_allowed), 0, "jail_allowed");
139140

140141
#define CDEV_MAJOR 79
141142
#include <sys/poll.h>

0 commit comments

Comments
 (0)