Back to home page

OSCL-LXR

 
 

    


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