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, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 16 | struct dentry *unused, struct inode *inode, |
| 17 | const char *name, void *buffer, size_t size) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 18 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 19 | return ext4_xattr_get(inode, 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, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 25 | struct dentry *unused, struct inode *inode, |
| 26 | const char *name, const void *value, |
| 27 | size_t size, int flags) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 28 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 29 | return ext4_xattr_set(inode, EXT4_XATTR_INDEX_SECURITY, |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 30 | name, value, size, flags); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Djalal Harouni | 176576d | 2012-01-04 22:32:12 -0500 | [diff] [blame] | 33 | static int |
| 34 | ext4_initxattrs(struct inode *inode, const struct xattr *xattr_array, |
| 35 | void *fs_info) |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 36 | { |
| 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 Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 52 | int |
Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 53 | ext4_init_security(handle_t *handle, struct inode *inode, struct inode *dir, |
| 54 | const struct qstr *qstr) |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 55 | { |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 56 | return security_inode_init_security(inode, dir, qstr, |
| 57 | &ext4_initxattrs, handle); |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Stephen Hemminger | 11e2752 | 2010-05-13 17:53:18 -0700 | [diff] [blame] | 60 | const struct xattr_handler ext4_xattr_security_handler = { |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 61 | .prefix = XATTR_SECURITY_PREFIX, |
Mingming Cao | 617ba13 | 2006-10-11 01:20:53 -0700 | [diff] [blame] | 62 | .get = ext4_xattr_security_get, |
| 63 | .set = ext4_xattr_security_set, |
Dave Kleikamp | ac27a0e | 2006-10-11 01:20:50 -0700 | [diff] [blame] | 64 | }; |