Skip to content

Commit 6fa205a

Browse files
committed
nullfs: add nounixbypass mount option
The option, when set, disables bypassing the unix socket vnode down to the lower mp, effectively preventing connection to nullfs unix socket from being acceptable from the lower mp (and vice versa). This is done by providing a vop vector that stops bypass for unp-related VOPs. I believe that VFS_VOP_VECTOR_REGISTER() does the right thing there regardless of the order of initialization. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D52983
1 parent 8e6f6a5 commit 6fa205a

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

sys/fs/nullfs/null.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <vm/uma.h>
4040

4141
#define NULLM_CACHE 0x0001
42+
#define NULLM_NOUNPBYPASS 0x0002
4243

4344
struct null_mount {
4445
struct mount *nullm_vfs;
@@ -90,7 +91,7 @@ null_is_nullfs_vnode(struct vnode *vp)
9091
const struct vop_vector *op;
9192

9293
op = vp->v_op;
93-
return (op == &null_vnodeops);
94+
return (op == &null_vnodeops || op == &null_vnodeops_no_unp_bypass);
9495
}
9596

9697
extern uma_zone_t null_node_zone;

sys/fs/nullfs/null_subr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ null_nodeget(struct mount *mp, struct vnode *lowervp, struct vnode **vpp)
240240
*/
241241
xp = uma_zalloc_smr(null_node_zone, M_WAITOK);
242242

243-
error = getnewvnode("nullfs", mp, &null_vnodeops, &vp);
243+
error = getnewvnode("nullfs", mp, (MOUNTTONULLMOUNT(mp)->nullm_flags &
244+
NULLM_NOUNPBYPASS) != 0 ? &null_vnodeops_no_unp_bypass :
245+
&null_vnodeops, &vp);
244246
if (error) {
245247
vput(lowervp);
246248
uma_zfree_smr(null_node_zone, xp);

sys/fs/nullfs/null_vfsops.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ nullfs_mount(struct mount *mp)
8787
bool isvnunlocked;
8888
static const char cache_opt_name[] = "cache";
8989
static const char nocache_opt_name[] = "nocache";
90+
static const char unixbypass_opt_name[] = "unixbypass";
91+
static const char nounixbypass_opt_name[] = "nounixbypass";
9092

9193
NULLFSDEBUG("nullfs_mount(mp = %p)\n", (void *)mp);
9294

@@ -222,6 +224,13 @@ nullfs_mount(struct mount *mp)
222224
&xmp->notify_node);
223225
}
224226

227+
if (vfs_getopt(mp->mnt_optnew, unixbypass_opt_name, NULL, NULL) == 0) {
228+
;
229+
} else if (vfs_getopt(mp->mnt_optnew, nounixbypass_opt_name, NULL,
230+
NULL) == 0) {
231+
xmp->nullm_flags |= NULLM_NOUNPBYPASS;
232+
}
233+
225234
if (lowerrootvp == mp->mnt_vnodecovered) {
226235
vn_lock(lowerrootvp, LK_EXCLUSIVE | LK_RETRY | LK_CANRECURSE);
227236
lowerrootvp->v_vflag |= VV_CROSSLOCK;

sys/fs/nullfs/null_vnops.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,3 +1256,11 @@ struct vop_vector null_vnodeops = {
12561256
.vop_copy_file_range = VOP_PANIC,
12571257
};
12581258
VFS_VOP_VECTOR_REGISTER(null_vnodeops);
1259+
1260+
struct vop_vector null_vnodeops_no_unp_bypass = {
1261+
.vop_default = &null_vnodeops,
1262+
.vop_unp_bind = vop_stdunp_bind,
1263+
.vop_unp_connect = vop_stdunp_connect,
1264+
.vop_unp_detach = vop_stdunp_detach,
1265+
};
1266+
VFS_VOP_VECTOR_REGISTER(null_vnodeops_no_unp_bypass);

0 commit comments

Comments
 (0)