From d7d19bb35fedcd0749e7fba4b29bb7db4f8e8385 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Fri, 29 Nov 2024 10:53:31 -0800 Subject: [PATCH] FreeBSD: handle `UF_NOUNLINK` chflags fflag The `UF_NOUNLINK` chflags fflag is analogous to `SF_NOUNLINK`, but instead of requiring superuser privileges when setting `SF_NOUNLINK`, unprivileged users (in addition to root) can set `UF_NOUNLINK` on compatible paths. This makes commands like `chflags uunlink ` work on FreeBSD. This closes #16809. Signed-off-by: Enji Cooper --- module/os/freebsd/zfs/zfs_vnops_os.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/module/os/freebsd/zfs/zfs_vnops_os.c b/module/os/freebsd/zfs/zfs_vnops_os.c index d5547c0a9392..21c5050a1d06 100644 --- a/module/os/freebsd/zfs/zfs_vnops_os.c +++ b/module/os/freebsd/zfs/zfs_vnops_os.c @@ -4750,6 +4750,8 @@ zfs_freebsd_getattr(struct vop_getattr_args *ap) xvap.xva_xoptattrs.xoa_archive); FLAG_CHECK(UF_NODUMP, XAT_NODUMP, xvap.xva_xoptattrs.xoa_nodump); + FLAG_CHECK(UF_NOUNLINK, XAT_NOUNLINK, + xvap.xva_xoptattrs.xoa_nounlink); FLAG_CHECK(UF_READONLY, XAT_READONLY, xvap.xva_xoptattrs.xoa_readonly); FLAG_CHECK(UF_SYSTEM, XAT_SYSTEM, @@ -4812,7 +4814,7 @@ zfs_freebsd_setattr(struct vop_setattr_args *ap) */ if ((fflags & ~(SF_IMMUTABLE|SF_APPEND|SF_NOUNLINK|UF_ARCHIVE| UF_NODUMP|UF_SYSTEM|UF_HIDDEN|UF_READONLY|UF_REPARSE| - UF_OFFLINE|UF_SPARSE)) != 0) + UF_OFFLINE|UF_SPARSE|UF_NOUNLINK)) != 0) return (EOPNOTSUPP); /* * Unprivileged processes are not permitted to unset system @@ -4869,6 +4871,8 @@ zfs_freebsd_setattr(struct vop_setattr_args *ap) xvap.xva_xoptattrs.xoa_archive); FLAG_CHANGE(UF_NODUMP, ZFS_NODUMP, XAT_NODUMP, xvap.xva_xoptattrs.xoa_nodump); + FLAG_CHANGE(UF_NOUNLINK, ZFS_NOUNLINK, XAT_NOUNLINK, + xvap.xva_xoptattrs.xoa_nounlink); FLAG_CHANGE(UF_READONLY, ZFS_READONLY, XAT_READONLY, xvap.xva_xoptattrs.xoa_readonly); FLAG_CHANGE(UF_SYSTEM, ZFS_SYSTEM, XAT_SYSTEM,