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 | |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 25 | /* ---- Initial Security Label(s) Attachment callback --- */ |
Nikola Pajkovsky | 273a65a | 2012-02-19 19:51:42 +0100 | [diff] [blame] | 26 | static int jffs2_initxattrs(struct inode *inode, |
| 27 | const struct xattr *xattr_array, void *fs_info) |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 28 | { |
| 29 | const struct xattr *xattr; |
| 30 | int err = 0; |
| 31 | |
| 32 | for (xattr = xattr_array; xattr->name != NULL; xattr++) { |
| 33 | err = do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY, |
| 34 | xattr->name, xattr->value, |
| 35 | xattr->value_len, 0); |
| 36 | if (err < 0) |
| 37 | break; |
| 38 | } |
| 39 | return err; |
| 40 | } |
| 41 | |
| 42 | /* ---- Initial Security Label(s) Attachment ----------- */ |
Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 43 | int jffs2_init_security(struct inode *inode, struct inode *dir, |
| 44 | const struct qstr *qstr) |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 45 | { |
Mimi Zohar | 9d8f13b | 2011-06-06 15:29:25 -0400 | [diff] [blame] | 46 | return security_inode_init_security(inode, dir, qstr, |
| 47 | &jffs2_initxattrs, NULL); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /* ---- XATTR Handler for "security.*" ----------------- */ |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 51 | static int jffs2_security_getxattr(const struct xattr_handler *handler, |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 52 | struct dentry *unused, struct inode *inode, |
| 53 | const char *name, void *buffer, size_t size) |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 54 | { |
Al Viro | b296821 | 2016-04-10 20:48:24 -0400 | [diff] [blame] | 55 | return do_jffs2_getxattr(inode, JFFS2_XPREFIX_SECURITY, |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 56 | name, buffer, size); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 57 | } |
| 58 | |
Andreas Gruenbacher | d9a82a0 | 2015-10-04 19:18:51 +0200 | [diff] [blame] | 59 | static int jffs2_security_setxattr(const struct xattr_handler *handler, |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 60 | struct dentry *unused, struct inode *inode, |
| 61 | const char *name, const void *buffer, |
| 62 | size_t size, int flags) |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 63 | { |
Al Viro | 5930122 | 2016-05-27 10:19:30 -0400 | [diff] [blame] | 64 | return do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY, |
Christoph Hellwig | 431547b | 2009-11-13 09:52:56 +0000 | [diff] [blame] | 65 | name, buffer, size, flags); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 66 | } |
| 67 | |
Stephen Hemminger | 365f0cb | 2010-05-13 17:53:21 -0700 | [diff] [blame] | 68 | const struct xattr_handler jffs2_security_xattr_handler = { |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 69 | .prefix = XATTR_SECURITY_PREFIX, |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 70 | .set = jffs2_security_setxattr, |
| 71 | .get = jffs2_security_getxattr |
| 72 | }; |