git: 3e29cd164ccc - stable/14 - fdescfs: check the target file for FWRITE access when truncating
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 17 Nov 2026 17:03:03 UTC
The branch stable/14 has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=3e29cd164ccc857a3473f73a2910bf411445cb7e
commit 3e29cd164ccc857a3473f73a2910bf411445cb7e
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-12 19:29:20 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-17 13:24:11 +0000
fdescfs: check the target file for FWRITE access when truncating
Truncation is done by calling fdesc_setattr(), and fdesc_setattr() looks
up fd N again, so a concurrent dup2() can swap the file between the
access check and the truncate.
Correct the rights checked for the setattr().
Unlock the fdescfs vnode around fdrop() of the underlying file.
Approved by: so
Security: FreeBSD-SA-26:91.fdescfs
Sponsored by: The FreeBSD Foundation
---
sys/fs/fdescfs/fdesc_vnops.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/sys/fs/fdescfs/fdesc_vnops.c b/sys/fs/fdescfs/fdesc_vnops.c
index f1e204d9b2d0..0f4cdb4f790f 100644
--- a/sys/fs/fdescfs/fdesc_vnops.c
+++ b/sys/fs/fdescfs/fdesc_vnops.c
@@ -527,19 +527,24 @@ fdesc_setattr(struct vop_setattr_args *ap)
return (EACCES);
fd = VTOFDESC(ap->a_vp)->fd_fd;
+ cap_rights_init(&rights, CAP_FUTIMES, CAP_FCHMOD, CAP_FCHOWN,
+ CAP_FCHFLAGS);
/*
* Allow setattr where there is an underlying vnode.
* For O_PATH descriptors, disallow truncate.
*/
if (vap->va_size != VNOVAL) {
- error = getvnode(td, fd,
- cap_rights_init_one(&rights, CAP_EXTATTR_SET), &fp);
+ cap_rights_set(&rights, CAP_FTRUNCATE);
+ error = getvnode(td, fd, &rights, &fp);
+ if (error == 0 && (fp->f_flag & FWRITE) == 0) {
+ error = EACCES;
+ goto out;
+ }
} else {
- error = getvnode_path(td, fd,
- cap_rights_init_one(&rights, CAP_EXTATTR_SET), NULL, &fp);
+ error = getvnode_path(td, fd, &rights, NULL, &fp);
}
- if (error) {
+ if (error != 0) {
/*
* getvnode() returns EINVAL if the file descriptor is not
* backed by a vnode. Silently drop all changes except
@@ -560,7 +565,10 @@ fdesc_setattr(struct vop_setattr_args *ap)
VOP_UNLOCK(vp);
vn_finished_write(mp);
}
+out:
+ VOP_UNLOCK(ap->a_vp);
fdrop(fp, td);
+ vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
return (error);
}