blob: 3e81bdca071a6776fa16422bdd9006ddb2abf1e6 [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,
16 struct dentry *dentry, const char *name,
17 void *buffer, size_t size)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070018{
David Howells2b0143b2015-03-17 22:25:59 +000019 return ext4_xattr_get(d_inode(dentry), 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,
25 struct dentry *dentry, const char *name,
26 const void *value, size_t size, int flags)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070027{
David Howells2b0143b2015-03-17 22:25:59 +000028 return ext4_xattr_set(d_inode(dentry), EXT4_XATTR_INDEX_SECURITY,
Christoph Hellwig431547b2009-11-13 09:52:56 +000029 name, value, size, flags);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070030}
31
Djalal Harouni176576d2012-01-04 22:32:12 -050032static int
33ext4_initxattrs(struct inode *inode, const struct xattr *xattr_array,
34 void *fs_info)
Mimi Zohar9d8f13b2011-06-06 15:29:25 -040035{
36 const struct xattr *xattr;
37 handle_t *handle = fs_info;
38 int err = 0;
39
40 for (xattr = xattr_array; xattr->name != NULL; xattr++) {
41 err = ext4_xattr_set_handle(handle, inode,
42 EXT4_XATTR_INDEX_SECURITY,
43 xattr->name, xattr->value,
44 xattr->value_len, 0);
45 if (err < 0)
46 break;
47 }
48 return err;
49}
50
Dave Kleikampac27a0e2006-10-11 01:20:50 -070051int
Eric Paris2a7dba32011-02-01 11:05:39 -050052ext4_init_security(handle_t *handle, struct inode *inode, struct inode *dir,
53 const struct qstr *qstr)
Dave Kleikampac27a0e2006-10-11 01:20:50 -070054{
Mimi Zohar9d8f13b2011-06-06 15:29:25 -040055 return security_inode_init_security(inode, dir, qstr,
56 &ext4_initxattrs, handle);
Dave Kleikampac27a0e2006-10-11 01:20:50 -070057}
58
Stephen Hemminger11e27522010-05-13 17:53:18 -070059const struct xattr_handler ext4_xattr_security_handler = {
Dave Kleikampac27a0e2006-10-11 01:20:50 -070060 .prefix = XATTR_SECURITY_PREFIX,
Mingming Cao617ba132006-10-11 01:20:53 -070061 .get = ext4_xattr_security_get,
62 .set = ext4_xattr_security_set,
Dave Kleikampac27a0e2006-10-11 01:20:50 -070063};