git: adc3506d56d7 - main - Extract tmpfs-specific part of tmpfs_access() into a helper
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 13 Feb 2023 23:16:47 UTC
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=adc3506d56d76981a0e251080b186c26edb843b4 commit adc3506d56d76981a0e251080b186c26edb843b4 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2023-02-12 22:25:25 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2023-02-13 23:16:38 +0000 Extract tmpfs-specific part of tmpfs_access() into a helper The helper tmpfs_access_locked() requires either the vnode or node locked for consistency of the access check, unlike the pure vnode op. Reviewed by: markj, mjg Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D38557 --- sys/fs/tmpfs/tmpfs_vnops.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index c7371de28896..cd460636b647 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -375,6 +375,23 @@ tmpfs_fplookup_vexec(struct vop_fplookup_vexec_args *v) return (vaccess_vexec_smr(mode, node->tn_uid, node->tn_gid, cred)); } +static int +tmpfs_access_locked(struct vnode *vp, struct tmpfs_node *node, + accmode_t accmode, struct ucred *cred) +{ +#ifdef DEBUG_VFS_LOCKS + if (!mtx_owned(TMPFS_NODE_MTX(node))) { + ASSERT_VOP_LOCKED(vp, + "tmpfs_access_locked needs locked vnode or node"); + } +#endif + + if ((accmode & VWRITE) != 0 && (node->tn_flags & IMMUTABLE) != 0) + return (EPERM); + return (vaccess(vp->v_type, node->tn_mode, node->tn_uid, node->tn_gid, + accmode, cred)); +} + int tmpfs_access(struct vop_access_args *v) { @@ -383,7 +400,6 @@ tmpfs_access(struct vop_access_args *v) struct tmpfs_node *node = VP_TO_TMPFS_NODE(vp); mode_t all_x = S_IXUSR | S_IXGRP | S_IXOTH; accmode_t accmode = v->a_accmode; - int error; /* * Common case path lookup. @@ -399,10 +415,8 @@ tmpfs_access(struct vop_access_args *v) /* FALLTHROUGH */ case VREG: if ((accmode & VWRITE) != 0 && - (vp->v_mount->mnt_flag & MNT_RDONLY) != 0) { - error = EROFS; - goto out; - } + (vp->v_mount->mnt_flag & MNT_RDONLY) != 0) + return (EROFS); break; case VBLK: @@ -415,20 +429,10 @@ tmpfs_access(struct vop_access_args *v) break; default: - error = EINVAL; - goto out; - } - - if ((accmode & VWRITE) != 0 && (node->tn_flags & IMMUTABLE) != 0) { - error = EPERM; - goto out; + return (EINVAL); } - error = vaccess(vp->v_type, node->tn_mode, node->tn_uid, node->tn_gid, - accmode, cred); - -out: - return (error); + return (tmpfs_access_locked(vp, node, accmode, cred)); } int