VOP_SETLABEL(9)

NAME
VOP_SETLABEL - persistently store an updated MAC label on a vnode

SYNOPSIS
#include <sys/param.h>
#include <sys/vnode.h>
#include <security/mac.h>
int
VOP_SETLABEL(struct vnode *vp, label *label);

DESCRIPTION
This vnode call is made by mac(9) file relabeling operation has been authorized, and the filesystem must now be updated.

  Single-Label vs. Multi-Label Filesystems
Filesystems that do not implement per-file labels -- known as single-label filesystems -- can simply leave the vnode(9) operation undefined. These filesystems must not set the MNT_MULTLABEL flag in their struct mount.

Filesystems that do implement per-vnode label storage -- known as multi-label filesystems -- will set the MNT_MULTILABEL flag in their struct mount. The UFS filesystem uses a superblock flag to persisently configure whether a specific filesystem implements a label for each vnode(9), and then keys various behaviors on whether that flag is set.

  Extended Attributes
If the filesystem implements extended attributes, then the MAC Framework's vop_stdsetlabel_ea() function can be used, and maps operations into a series of VOP_OPENEXTATTR(9), VOP_WRITEEXTATTR(9), and VOP_CLOSEEXTATTR(9).

Filesystems will also need to call mac_vnode_create_extattr() when a new filesystem object is created, so that suitable extended attributes can be written out, and mac_vnode_associate_extattr() when a vnode(9) is associated with a filesystem object for the first time. These utility functions use VOP_OPENEXTATTR(9), VOP_READEXTATTR(9), VOP_WRITEEXTATTR(9), and VOP_CLOSEEXTATTR(9) as required.

  Locking and Crash Safety
In all cases, it is important that exclusive vnode(9) locks be held to prevent concurrent access when a MAC label may not yet be initialized. It is also important that operations are ordered so that a system crash does not leave a file improperly labeled. For example, the extended attribute for a newly created file must be written to disk before the file is linked by its parent directory, so that there is no opportunity for a crash to lead to an unlabeled file.

LOCKS
The vnode will be locked on entry and should remain locked on return.

RETURN VALUES
If the MAC label is successfully set, then zero is returned. Otherwise, an appropriate error code is returned.

ERRORS

[EOPNOTSUPP]
    The file system does not support VOP_SETLABEL().

[ENOSPC]
    The file system is out of space.

[EROFS]
    The file system is read-only.

Depending on the underlying implementation of VOP_SETLABEL(), other errors may also be possible.

SEE ALSO
mac(9), mount(9), vnode(9), VOP_CLOSEEXTATTR(9), VOP_OPENEXTATTR(9), VOP_READEXTATTR(9), VOP_WRITEXTATTR(9)

AUTHORS
This manual page was written by Robert Watson.