From 45ecb858242ee5875e0c732aeaaf2b9f35b08fcb Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Sun, 5 Jun 2022 21:49:09 +0300 Subject: [PATCH] fdescfs: allow chown/utime etc on fdescfs fd for underlying files opened with O_PATH (cherry picked from commit 156745b42d9e6dfa3d9c6dc480db7836683850cf) --- sys/fs/fdescfs/fdesc_vnops.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/fs/fdescfs/fdesc_vnops.c b/sys/fs/fdescfs/fdesc_vnops.c index c5a7b86f1de..087f9b2551d 100644 --- a/sys/fs/fdescfs/fdesc_vnops.c +++ b/sys/fs/fdescfs/fdesc_vnops.c @@ -504,9 +504,15 @@ fdesc_setattr(struct vop_setattr_args *ap) /* * Allow setattr where there is an underlying vnode. + * For O_PATH descriptors, disallow truncate. */ - error = getvnode(td, fd, - cap_rights_init_one(&rights, CAP_EXTATTR_SET), &fp); + if (vap->va_size != VNOVAL) { + error = getvnode(td, fd, + cap_rights_init_one(&rights, CAP_EXTATTR_SET), &fp); + } else { + error = getvnode_path(td, fd, + cap_rights_init_one(&rights, CAP_EXTATTR_SET), &fp); + } if (error) { /* * getvnode() returns EINVAL if the file descriptor is not -- 2.45.2