git: 9d7c65d1c79f - stable/15 - 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:06:16 UTC
The branch stable/15 has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=9d7c65d1c79f636037f74030ed01d65c11f8b225
commit 9d7c65d1c79f636037f74030ed01d65c11f8b225
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-12 19:29:20 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-17 16:57:23 +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 d29ce4236eac..e312e09cf4a6 100644
--- a/sys/fs/fdescfs/fdesc_vnops.c
+++ b/sys/fs/fdescfs/fdesc_vnops.c
@@ -525,19 +525,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
@@ -558,7 +563,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);
}