blob: a8921112030d31f00bd28e9cdd32d3f04c6f806c [file] [log] [blame]
Dave Kleikampac27a0e2006-10-11 01:20:50 -07001/*
Mingming Cao617ba132006-10-11 01:20:53 -07002 * linux/fs/ext4/xattr_security.c
Dave Kleikampac27a0e2006-10-11 01:20:50 -07003 * Handler for storing security labels as extended attributes.
4 */
5
Dave Kleikampac27a0e2006-10-11 01:20:50 -07006#include <linux/string.h>
7#include <linux/fs.h>
Dave Kleikampac27a0e2006-10-11 01:20:50 -07008#include <linux/security.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Christoph Hellwig3dcf5452008-04-29 18:13:32 -040010#include "ext4_jbd2.h"
11#include "ext4.h"
Dave Kleikampac27a0e2006-10-11 01:20:50 -070012#include "xattr.h"
13
Dave Kleikampac27a0e2006-10-11 01:20:50 -070014static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020015ext4_xattr_security_get(const struct xattr_handler *handler,
Al Virob2968212016-04-10 20:48:24 -040016 struct dentry *unused, struct inode *inode,
17 const char *name, void *buffer, size_t size)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070018{
Al Virob2968212016-04-10 20:48:24 -040019 return ext4_xattr_get(inode, EXT4_XATTR_INDEX_SECURITY,
Christoph Hellwig431547b2009-11-13 09:52:56 +000020 name, buffer, size);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070021}
22
23static int
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020024ext4_xattr_security_set(const struct xattr_handler *handler,
Al Viro59301222016-05-27 10:19:30 -040025 struct dentry *unused, struct inode *inode,
26 const char *name, const void *value,
27 size_t size, int flags)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070028{
Al Viro59301222016-05-27 10:19:30 -040029 return ext4_xattr_set(inode, EXT4_XATTR_INDEX_SECURITY,
Christoph Hellwig431547b2009-11-13 09:52:56 +000030 name, value, size, flags);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070031}
32
Djalal Harouni176576d2012-01-04 22:32:12 -050033static int
34ext4_initxattrs(struct inode *inode, const struct xattr *xattr_array,
35 void *fs_info)
Mimi Zohar9d8f13b2011-06-06 15:29:25 -040036{
37 const struct xattr *xattr;
38 handle_t *handle = fs_info;
39 int err = 0;
40
41 for (xattr = xattr_array; xattr->name != NULL; xattr++) {
42 err = ext4_xattr_set_handle(handle, inode,
43 EXT4_XATTR_INDEX_SECURITY,
44 xattr->name, xattr->value,
45 xattr->value_len, 0);
46 if (err < 0)
47 break;
48 }
49 return err;
50}
51
Dave Kleikampac27a0e2006-10-11 01:20:50 -070052int
Eric Paris2a7dba32011-02-01 11:05:39 -050053ext4_init_security(handle_t *handle, struct inode *inode, struct inode *dir,
54 const struct qstr *qstr)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070055{
Mimi Zohar9d8f13b2011-06-06 15:29:25 -040056 return security_inode_init_security(inode, dir, qstr,
57 &ext4_initxattrs, handle);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070058}
59
Stephen Hemminger11e27522010-05-13 17:53:18 -070060const struct xattr_handler ext4_xattr_security_handler = {
Dave Kleikampac27a0e2006-10-11 01:20:50 -070061 .prefix = XATTR_SECURITY_PREFIX,
Mingming Cao617ba132006-10-11 01:20:53 -070062 .get = ext4_xattr_security_get,
63 .set = ext4_xattr_security_set,
Dave Kleikampac27a0e2006-10-11 01:20:50 -070064};