Changing v_op for vnode on the fly

Brian F. Feldman green at freebsd.org
Fri Feb 13 18:50:01 PST 2004


Andrey Simonenko <simon at comsys.ntu-kpi.kiev.ua> wrote:
> Hello all,
> 
> I want to control in a KLD module when any process make any
> VOPs, which can change the content of some file.  For this I change
> v_op field in the needed vnode to my vnodeop_p, currently my VOPs
> print some debug information and call original VOPs for the vnode.
> 
> I can't simply wrap syscall entries for a process to control write()
> and read() syscalls, because it is unknown in my task which process
> can access a file and processes can mmap a file and modify or read it
> directly in their memory.
> 
> Is it enough to get exclusive lock on vnode, before changing
> v_op pointer?  Here is my code:
> 
> 	vn_lock(cvp->vp, LK_EXCLUSIVE | LK_RETRY, p);
> 
> 	if (flag > 0)
> 		cvp->vp->v_op = catch_vnode_vnodeop_p;	/* My vnodeop_p. */
> 	else
> 		cvp->vp->v_op = cvp->vnodeop_p;		/* Original v_op. */
> 
> 	VOP_UNLOCK(cvp->vp, 0, p);
> 
> I made some tests and see that most of VOP_xxx require lock (shared
> or exclusive) on vnode, as well this is documented in the manual pages.

No, you are not allowed to change v_op, ever.  Can you do what you're trying 
to do in the MAC framework?  It seems like that is what you want to be 
doing!  The other possibility is using something like umapfs/lomacfs/
unionfs.

-- 
Brian Fundakowski Feldman                           \'[ FreeBSD ]''''''''''\
  <> green at FreeBSD.org                               \  The Power to Serve! \
 Opinions expressed are my own.                       \,,,,,,,,,,,,,,,,,,,,,,\




More information about the freebsd-hackers mailing list