Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * linux/fs/ext2/xattr_security.c
0004  * Handler for storing security labels as extended attributes.
0005  */
0006 
0007 #include "ext2.h"
0008 #include <linux/security.h>
0009 #include "xattr.h"
0010 
0011 static int
0012 ext2_xattr_security_get(const struct xattr_handler *handler,
0013             struct dentry *unused, struct inode *inode,
0014             const char *name, void *buffer, size_t size)
0015 {
0016     return ext2_xattr_get(inode, EXT2_XATTR_INDEX_SECURITY, name,
0017                   buffer, size);
0018 }
0019 
0020 static int
0021 ext2_xattr_security_set(const struct xattr_handler *handler,
0022             struct user_namespace *mnt_userns,
0023             struct dentry *unused, struct inode *inode,
0024             const char *name, const void *value,
0025             size_t size, int flags)
0026 {
0027     return ext2_xattr_set(inode, EXT2_XATTR_INDEX_SECURITY, name,
0028                   value, size, flags);
0029 }
0030 
0031 static int ext2_initxattrs(struct inode *inode, const struct xattr *xattr_array,
0032                void *fs_info)
0033 {
0034     const struct xattr *xattr;
0035     int err = 0;
0036 
0037     for (xattr = xattr_array; xattr->name != NULL; xattr++) {
0038         err = ext2_xattr_set(inode, EXT2_XATTR_INDEX_SECURITY,
0039                      xattr->name, xattr->value,
0040                      xattr->value_len, 0);
0041         if (err < 0)
0042             break;
0043     }
0044     return err;
0045 }
0046 
0047 int
0048 ext2_init_security(struct inode *inode, struct inode *dir,
0049            const struct qstr *qstr)
0050 {
0051     return security_inode_init_security(inode, dir, qstr,
0052                         &ext2_initxattrs, NULL);
0053 }
0054 
0055 const struct xattr_handler ext2_xattr_security_handler = {
0056     .prefix = XATTR_SECURITY_PREFIX,
0057     .get    = ext2_xattr_security_get,
0058     .set    = ext2_xattr_security_set,
0059 };