git: a95917bab311 - stable/15 - fdescfs: add VOP_ACCESS() implementation

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 17:06:15 UTC
The branch stable/15 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=a95917bab31131e65c71b32be80363a94a9cb509

commit a95917bab31131e65c71b32be80363a94a9cb509
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-06 00:00:19 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-17 16:57:23 +0000

    fdescfs: add VOP_ACCESS() implementation
    
    kern_truncate() checks VWRITE only through VOP_ACCESS() on the fdescfs
    vnode, which always succeeded until now. So a file opened read-only
    could be truncated, even if the caller has no write permission for it.
    
    Note that reopen on mounts without nodup already performs the permission
    checks in dupfdopen().  For nodup mounts, the VOP_ACCESS() implementation
    of the real filesystem is used.
    
    Approved by:    so
    Security:       FreeBSD-SA-26:91.fdescfs
    Security:       CVE-2026-127745
    Reported by:    Kevin Day <kevin@your.org>
    Sponsored by:   The FreeBSD Foundation
---
 sys/fs/fdescfs/fdesc_vnops.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/sys/fs/fdescfs/fdesc_vnops.c b/sys/fs/fdescfs/fdesc_vnops.c
index 0ff11591cabf..d29ce4236eac 100644
--- a/sys/fs/fdescfs/fdesc_vnops.c
+++ b/sys/fs/fdescfs/fdesc_vnops.c
@@ -73,11 +73,12 @@ static vop_readdir_t	fdesc_readdir;
 static vop_readlink_t	fdesc_readlink;
 static vop_reclaim_t	fdesc_reclaim;
 static vop_setattr_t	fdesc_setattr;
+static vop_access_t	fdesc_access;
 
 static struct vop_vector fdesc_vnodeops = {
 	.vop_default =		&default_vnodeops,
 
-	.vop_access =		VOP_NULL,
+	.vop_access =		fdesc_access,
 	.vop_getattr =		fdesc_getattr,
 	.vop_lookup =		fdesc_lookup,
 	.vop_open =		fdesc_open,
@@ -704,3 +705,34 @@ out:
 	vn_lock(vn, lockflags | LK_RETRY);
 	return (error);
 }
+
+static int
+fdesc_access(struct vop_access_args *va)
+{
+	struct vnode *vp;
+	struct fdescnode *fd;
+	struct file *fp;
+	int error, flags, locked;
+
+	vp = va->a_vp;
+	fd = VTOFDESC(vp);
+	if (fd->fd_type == Froot)
+		return (0);
+	error = fget(va->a_td, fd->fd_fd, &cap_no_rights, &fp);
+	if (error != 0)
+		return (error);
+	flags = 0;
+	if ((va->a_accmode & VREAD) != 0)
+		flags |= FREAD;
+	if ((va->a_accmode & (VWRITE | VAPPEND)) != 0)
+		flags |= FWRITE;
+	if ((va->a_accmode & VEXEC) != 0)
+		flags |= FEXEC;
+	if ((flags & fp->f_flag) != flags)
+		error = EACCES;
+	locked = VOP_ISLOCKED(vp);
+	VOP_UNLOCK(vp);
+	fdrop(fp, va->a_td);
+	vn_lock(vp, locked | LK_RETRY);
+	return (error);
+}