Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys cache_enter_id(): give it a boolean parameter to indicat...
details: https://anonhg.NetBSD.org/src/rev/bc4cdb001ee5
branches: trunk
changeset: 972009:bc4cdb001ee5
user: ad <ad%NetBSD.org@localhost>
date: Tue May 12 23:17:41 2020 +0000
description:
cache_enter_id(): give it a boolean parameter to indicate whether the cached
identity is valid.
diffstat:
sys/fs/tmpfs/tmpfs_subr.c | 10 +++++-----
sys/kern/vfs_cache.c | 43 ++++++++++++++++++++++++++-----------------
sys/sys/namei.src | 4 ++--
sys/ufs/ffs/ffs_vfsops.c | 8 ++++----
sys/ufs/ufs/ufs_vnops.c | 10 +++++-----
5 files changed, 42 insertions(+), 33 deletions(-)
diffs (244 lines):
diff -r 3ebe20648dd6 -r bc4cdb001ee5 sys/fs/tmpfs/tmpfs_subr.c
--- a/sys/fs/tmpfs/tmpfs_subr.c Tue May 12 21:56:17 2020 +0000
+++ b/sys/fs/tmpfs/tmpfs_subr.c Tue May 12 23:17:41 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs_subr.c,v 1.109 2020/04/23 21:47:08 ad Exp $ */
+/* $NetBSD: tmpfs_subr.c,v 1.110 2020/05/12 23:17:41 ad Exp $ */
/*
* Copyright (c) 2005-2013 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.109 2020/04/23 21:47:08 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.110 2020/05/12 23:17:41 ad Exp $");
#include <sys/param.h>
#include <sys/cprng.h>
@@ -148,7 +148,7 @@
node->tn_vnode = vp;
uvm_vnp_setsize(vp, node->tn_size);
KASSERT(node->tn_mode != VNOVAL);
- cache_enter_id(vp, node->tn_mode, node->tn_uid, node->tn_gid);
+ cache_enter_id(vp, node->tn_mode, node->tn_uid, node->tn_gid, true);
}
/*
@@ -1041,7 +1041,7 @@
node->tn_mode = (mode & ALLPERMS);
tmpfs_update(vp, TMPFS_UPDATE_CTIME);
VN_KNOTE(vp, NOTE_ATTRIB);
- cache_enter_id(vp, node->tn_mode, node->tn_uid, node->tn_gid);
+ cache_enter_id(vp, node->tn_mode, node->tn_uid, node->tn_gid, true);
return 0;
}
@@ -1086,7 +1086,7 @@
node->tn_gid = gid;
tmpfs_update(vp, TMPFS_UPDATE_CTIME);
VN_KNOTE(vp, NOTE_ATTRIB);
- cache_enter_id(vp, node->tn_mode, node->tn_uid, node->tn_gid);
+ cache_enter_id(vp, node->tn_mode, node->tn_uid, node->tn_gid, true);
return 0;
}
diff -r 3ebe20648dd6 -r bc4cdb001ee5 sys/kern/vfs_cache.c
--- a/sys/kern/vfs_cache.c Tue May 12 21:56:17 2020 +0000
+++ b/sys/kern/vfs_cache.c Tue May 12 23:17:41 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_cache.c,v 1.141 2020/04/23 22:58:36 ad Exp $ */
+/* $NetBSD: vfs_cache.c,v 1.142 2020/05/12 23:17:41 ad Exp $ */
/*-
* Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -172,7 +172,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.141 2020/04/23 22:58:36 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.142 2020/05/12 23:17:41 ad Exp $");
#define __NAMECACHE_PRIVATE
#ifdef _KERNEL_OPT
@@ -683,8 +683,10 @@
* First up check if the user is allowed to look up files in this
* directory.
*/
- KASSERT(dvi->vi_nc_mode != VNOVAL && dvi->vi_nc_uid != VNOVAL &&
- dvi->vi_nc_gid != VNOVAL);
+ if (dvi->vi_nc_mode == VNOVAL) {
+ return false;
+ }
+ KASSERT(dvi->vi_nc_uid != VNOVAL && dvi->vi_nc_gid != VNOVAL);
error = kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(VEXEC,
dvp->v_type, dvi->vi_nc_mode & ALLPERMS), dvp, NULL,
genfs_can_access(dvp->v_type, dvi->vi_nc_mode & ALLPERMS,
@@ -763,8 +765,11 @@
*
* I don't like it, I didn't come up with it, don't blame me!
*/
- KASSERT(vi->vi_nc_mode != VNOVAL && vi->vi_nc_uid != VNOVAL &&
- vi->vi_nc_gid != VNOVAL);
+ if (vi->vi_nc_mode == VNOVAL) {
+ rw_exit(&vi->vi_nc_listlock);
+ return -1;
+ }
+ KASSERT(vi->vi_nc_uid != VNOVAL && vi->vi_nc_gid != VNOVAL);
error = kauth_authorize_vnode(curlwp->l_cred,
KAUTH_ACCESS_ACTION(VEXEC, vp->v_type, vi->vi_nc_mode &
ALLPERMS), vp, NULL, genfs_can_access(vp->v_type,
@@ -941,10 +946,11 @@
/*
* Set identity info in cache for a vnode. We only care about directories
- * so ignore other updates.
+ * so ignore other updates. The cached info may be marked invalid if the
+ * inode has an ACL.
*/
void
-cache_enter_id(struct vnode *vp, mode_t mode, uid_t uid, gid_t gid)
+cache_enter_id(struct vnode *vp, mode_t mode, uid_t uid, gid_t gid, bool valid)
{
vnode_impl_t *vi = VNODE_TO_VIMPL(vp);
@@ -952,9 +958,15 @@
/* Grab both locks, for forward & reverse lookup. */
rw_enter(&vi->vi_nc_lock, RW_WRITER);
rw_enter(&vi->vi_nc_listlock, RW_WRITER);
- vi->vi_nc_mode = mode;
- vi->vi_nc_uid = uid;
- vi->vi_nc_gid = gid;
+ if (valid) {
+ vi->vi_nc_mode = mode;
+ vi->vi_nc_uid = uid;
+ vi->vi_nc_gid = gid;
+ } else {
+ vi->vi_nc_mode = VNOVAL;
+ vi->vi_nc_uid = VNOVAL;
+ vi->vi_nc_gid = VNOVAL;
+ }
rw_exit(&vi->vi_nc_listlock);
rw_exit(&vi->vi_nc_lock);
}
@@ -965,18 +977,15 @@
* opportunity to confirm that everything squares up.
*
* Because of shared code, some file systems could provide partial
- * information, missing some updates, so always check the mount flag
- * instead of looking for !VNOVAL.
+ * information, missing some updates, so check the mount flag too.
*/
bool
cache_have_id(struct vnode *vp)
{
if (vp->v_type == VDIR &&
- (vp->v_mount->mnt_iflag & IMNT_NCLOOKUP) != 0) {
- KASSERT(VNODE_TO_VIMPL(vp)->vi_nc_mode != VNOVAL);
- KASSERT(VNODE_TO_VIMPL(vp)->vi_nc_uid != VNOVAL);
- KASSERT(VNODE_TO_VIMPL(vp)->vi_nc_gid != VNOVAL);
+ (vp->v_mount->mnt_iflag & IMNT_NCLOOKUP) != 0 &&
+ atomic_load_relaxed(&VNODE_TO_VIMPL(vp)->vi_nc_mode) != VNOVAL) {
return true;
} else {
return false;
diff -r 3ebe20648dd6 -r bc4cdb001ee5 sys/sys/namei.src
--- a/sys/sys/namei.src Tue May 12 21:56:17 2020 +0000
+++ b/sys/sys/namei.src Tue May 12 23:17:41 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: namei.src,v 1.53 2020/04/04 20:49:31 ad Exp $ */
+/* $NetBSD: namei.src,v 1.54 2020/05/12 23:17:41 ad Exp $ */
/*
* Copyright (c) 1985, 1989, 1991, 1993
@@ -294,7 +294,7 @@
int cache_diraccess(struct vnode *, int);
void cache_enter(struct vnode *, struct vnode *,
const char *, size_t, uint32_t);
-void cache_enter_id(struct vnode *, mode_t, uid_t, gid_t);
+void cache_enter_id(struct vnode *, mode_t, uid_t, gid_t, bool);
bool cache_have_id(struct vnode *);
void cache_vnode_init(struct vnode * );
void cache_vnode_fini(struct vnode * );
diff -r 3ebe20648dd6 -r bc4cdb001ee5 sys/ufs/ffs/ffs_vfsops.c
--- a/sys/ufs/ffs/ffs_vfsops.c Tue May 12 21:56:17 2020 +0000
+++ b/sys/ufs/ffs/ffs_vfsops.c Tue May 12 23:17:41 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ffs_vfsops.c,v 1.367 2020/04/04 20:49:31 ad Exp $ */
+/* $NetBSD: ffs_vfsops.c,v 1.368 2020/05/12 23:17:41 ad Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.367 2020/04/04 20:49:31 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.368 2020/05/12 23:17:41 ad Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@@ -2084,7 +2084,7 @@
ip->i_gid = ip->i_ffs1_ogid; /* XXX */
} /* XXX */
uvm_vnp_setsize(vp, ip->i_size);
- cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid);
+ cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, true);
*new_key = &ip->i_number;
return 0;
}
@@ -2206,7 +2206,7 @@
}
uvm_vnp_setsize(vp, ip->i_size);
- cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid);
+ cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, true);
*new_key = &ip->i_number;
return 0;
}
diff -r 3ebe20648dd6 -r bc4cdb001ee5 sys/ufs/ufs/ufs_vnops.c
--- a/sys/ufs/ufs/ufs_vnops.c Tue May 12 21:56:17 2020 +0000
+++ b/sys/ufs/ufs/ufs_vnops.c Tue May 12 23:17:41 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_vnops.c,v 1.252 2020/04/18 19:18:34 christos Exp $ */
+/* $NetBSD: ufs_vnops.c,v 1.253 2020/05/12 23:17:41 ad Exp $ */
/*-
* Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.252 2020/04/18 19:18:34 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.253 2020/05/12 23:17:41 ad Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@@ -621,7 +621,7 @@
}
VN_KNOTE(vp, NOTE_ATTRIB);
out:
- cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid);
+ cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, true);
return (error);
}
@@ -649,7 +649,7 @@
ip->i_flag |= IN_CHANGE;
DIP_ASSIGN(ip, mode, ip->i_mode);
UFS_WAPBL_UPDATE(vp, NULL, NULL, 0);
- cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid);
+ cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, true);
return (0);
}
@@ -710,7 +710,7 @@
#endif /* QUOTA || QUOTA2 */
ip->i_flag |= IN_CHANGE;
UFS_WAPBL_UPDATE(vp, NULL, NULL, 0);
- cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid);
+ cache_enter_id(vp, ip->i_mode, ip->i_uid, ip->i_gid, true);
return (0);
}
Home |
Main Index |
Thread Index |
Old Index