1 // SPDX-License-Identifier: GPL-2.0
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 only,
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License version 2 for more details (a copy is included
15 * in the LICENSE file that accompanied this code).
17 * You should have received a copy of the GNU General Public License
18 * version 2 along with this program; If not, see http://www.gnu.org/licenses
24 * Copyright (c) 2014 Bull SAS
25 * Author: Sebastien Buisson sebastien.buisson@bull.net
29 * lustre/llite/xattr_security.c
30 * Handler for storing security labels as extended attributes.
33 #include <linux/types.h>
34 #include <linux/security.h>
35 #include <linux/selinux.h>
36 #include <linux/xattr.h>
37 #include "llite_internal.h"
40 * A helper function for ll_security_inode_init_security()
41 * that takes care of setting xattrs
43 * Get security context of @inode from @xattr_array,
44 * and put it in 'security.xxx' xattr of dentry
48 * \retval -ENOMEM if no memory could be allocated for xattr name
49 * \retval < 0 failure to set xattr
52 ll_initxattrs(struct inode *inode, const struct xattr *xattr_array,
55 struct dentry *dentry = fs_info;
56 const struct xattr *xattr;
59 for (xattr = xattr_array; xattr->name; xattr++) {
62 full_name = kasprintf(GFP_KERNEL, "%s%s",
63 XATTR_SECURITY_PREFIX, xattr->name);
69 err = __vfs_setxattr(dentry, inode, full_name, xattr->value,
70 xattr->value_len, XATTR_CREATE);
79 * Initializes security context
81 * Get security context of @inode in @dir,
82 * and put it in 'security.xxx' xattr of @dentry.
84 * \retval 0 success, or SELinux is disabled
85 * \retval -ENOMEM if no memory could be allocated for xattr name
86 * \retval < 0 failure to get security context or set xattr
89 ll_init_security(struct dentry *dentry, struct inode *inode, struct inode *dir)
91 if (!selinux_is_enabled())
94 return security_inode_init_security(inode, dir, NULL,
95 &ll_initxattrs, dentry);