Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 1 | /* |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 2 | * linux/fs/ext4/xattr_security.c |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 3 | * Handler for storing security labels as extended attributes. |
| 4 | */ |
| 5 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 6 | #include <linux/string.h> |
| 7 | #include <linux/fs.h> |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 8 | #include <linux/security.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/slab.h> |
Christoph Hellwig | 3dcf545 | 2008-04-29 18:13:32 -0400 | [diff] [blame] | 10 | #include "ext4_jbd2.h" |
| 11 | #include "ext4.h" |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 12 | #include "xattr.h" |
| 13 | |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 14 | static int |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 15 | ext4_xattr_security_get(const struct xattr_handler *handler, |
| 16 | struct dentry *dentry, const char *name, |
| 17 | void *buffer, size_t size) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 18 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 19 | return ext4_xattr_get(d_inode(dentry), EXT4_XATTR_INDEX_SECURITY, |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 20 | name, buffer, size); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | static int |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 24 | ext4_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 Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 27 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 28 | return ext4_xattr_set(d_inode(dentry), EXT4_XATTR_INDEX_SECURITY, |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 29 | name, value, size, flags); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Djalal Harouni | 176576d | 2012-01-04 22:32:12 -0500 | [diff] [blame] | 32 | static int |
| 33 | ext4_initxattrs(struct inode *inode, const struct xattr *xattr_array, |
| 34 | void *fs_info) |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 35 | { |
| 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 Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 51 | int |
Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 52 | ext4_init_security(handle_t *handle, struct inode *inode, struct inode *dir, |
| 53 | const struct qstr *qstr) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 54 | { |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 55 | return security_inode_init_security(inode, dir, qstr, |
| 56 | &ext4_initxattrs, handle); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Stephen Hemminger | 11e2752 | 2010-05-13 17:53:18 -0700 | [diff] [blame] | 59 | const struct xattr_handler ext4_xattr_security_handler = { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 60 | .prefix = XATTR_SECURITY_PREFIX, |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 61 | .get = ext4_xattr_security_get, |
| 62 | .set = ext4_xattr_security_set, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 63 | }; |