| KaiGai Kohei | 652ecc2 | 2006-05-13 15:18:27 +0900 | [diff] [blame] | 1 | /* | 
 | 2 |  * JFFS2 -- Journalling Flash File System, Version 2. | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 3 |  * | 
| David Woodhouse | c00c310 | 2007-04-25 14:16:47 +0100 | [diff] [blame] | 4 |  * Copyright © 2006  NEC Corporation | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 5 |  * | 
| KaiGai Kohei | 652ecc2 | 2006-05-13 15:18:27 +0900 | [diff] [blame] | 6 |  * Created by KaiGai Kohei <kaigai@ak.jp.nec.com> | 
 | 7 |  * | 
 | 8 |  * For licensing information, see the file 'LICENCE' in this directory. | 
 | 9 |  * | 
 | 10 |  */ | 
| David Woodhouse | c00c310 | 2007-04-25 14:16:47 +0100 | [diff] [blame] | 11 |  | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 12 | #include <linux/kernel.h> | 
 | 13 | #include <linux/slab.h> | 
 | 14 | #include <linux/fs.h> | 
 | 15 | #include <linux/time.h> | 
 | 16 | #include <linux/pagemap.h> | 
 | 17 | #include <linux/highmem.h> | 
 | 18 | #include <linux/crc32.h> | 
 | 19 | #include <linux/jffs2.h> | 
 | 20 | #include <linux/xattr.h> | 
 | 21 | #include <linux/mtd/mtd.h> | 
 | 22 | #include <linux/security.h> | 
 | 23 | #include "nodelist.h" | 
 | 24 |  | 
 | 25 | /* ---- Initial Security Label Attachment -------------- */ | 
| Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 26 | int jffs2_init_security(struct inode *inode, struct inode *dir, | 
 | 27 | 			const struct qstr *qstr) | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 28 | { | 
 | 29 | 	int rc; | 
 | 30 | 	size_t len; | 
 | 31 | 	void *value; | 
 | 32 | 	char *name; | 
 | 33 |  | 
| Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 34 | 	rc = security_inode_init_security(inode, dir, qstr, &name, &value, &len); | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 35 | 	if (rc) { | 
 | 36 | 		if (rc == -EOPNOTSUPP) | 
 | 37 | 			return 0; | 
 | 38 | 		return rc; | 
 | 39 | 	} | 
 | 40 | 	rc = do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY, name, value, len, 0); | 
 | 41 |  | 
| David Woodhouse | ef53cb0 | 2007-07-10 10:01:22 +0100 | [diff] [blame] | 42 | 	kfree(name); | 
 | 43 | 	kfree(value); | 
 | 44 | 	return rc; | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 45 | } | 
 | 46 |  | 
 | 47 | /* ---- XATTR Handler for "security.*" ----------------- */ | 
| Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 48 | static int jffs2_security_getxattr(struct dentry *dentry, const char *name, | 
 | 49 | 				   void *buffer, size_t size, int type) | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 50 | { | 
 | 51 | 	if (!strcmp(name, "")) | 
 | 52 | 		return -EINVAL; | 
 | 53 |  | 
| Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 54 | 	return do_jffs2_getxattr(dentry->d_inode, JFFS2_XPREFIX_SECURITY, | 
 | 55 | 				 name, buffer, size); | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 56 | } | 
 | 57 |  | 
| Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 58 | static int jffs2_security_setxattr(struct dentry *dentry, const char *name, | 
 | 59 | 		const void *buffer, size_t size, int flags, int type) | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 60 | { | 
 | 61 | 	if (!strcmp(name, "")) | 
 | 62 | 		return -EINVAL; | 
 | 63 |  | 
| Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 64 | 	return do_jffs2_setxattr(dentry->d_inode, JFFS2_XPREFIX_SECURITY, | 
 | 65 | 				 name, buffer, size, flags); | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 66 | } | 
 | 67 |  | 
| Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 68 | static size_t jffs2_security_listxattr(struct dentry *dentry, char *list, | 
 | 69 | 		size_t list_size, const char *name, size_t name_len, int type) | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 70 | { | 
 | 71 | 	size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1; | 
 | 72 |  | 
 | 73 | 	if (list && retlen <= list_size) { | 
 | 74 | 		strcpy(list, XATTR_SECURITY_PREFIX); | 
 | 75 | 		strcpy(list + XATTR_SECURITY_PREFIX_LEN, name); | 
 | 76 | 	} | 
 | 77 |  | 
 | 78 | 	return retlen; | 
 | 79 | } | 
 | 80 |  | 
| Stephen Hemminger | 365f0cb | 2010-05-13 17:53:21 -0700 | [diff] [blame] | 81 | const struct xattr_handler jffs2_security_xattr_handler = { | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 82 | 	.prefix = XATTR_SECURITY_PREFIX, | 
 | 83 | 	.list = jffs2_security_listxattr, | 
 | 84 | 	.set = jffs2_security_setxattr, | 
 | 85 | 	.get = jffs2_security_getxattr | 
 | 86 | }; |