blob: 7a28facd71750c80f087db06f50e71be8d556710 [file] [log] [blame]
KaiGai Kohei652ecc22006-05-13 15:18:27 +09001/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +09003 *
David Woodhousec00c3102007-04-25 14:16:47 +01004 * Copyright © 2006 NEC Corporation
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +09005 *
KaiGai Kohei652ecc22006-05-13 15:18:27 +09006 * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
10 */
David Woodhousec00c3102007-04-25 14:16:47 +010011
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090012#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 Zohar9d8f13b2011-06-06 15:29:25 -040025/* ---- Initial Security Label(s) Attachment callback --- */
Nikola Pajkovsky273a65a2012-02-19 19:51:42 +010026static int jffs2_initxattrs(struct inode *inode,
27 const struct xattr *xattr_array, void *fs_info)
Mimi Zohar9d8f13b2011-06-06 15:29:25 -040028{
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 Paris2a7dba32011-02-01 11:05:39 -050043int jffs2_init_security(struct inode *inode, struct inode *dir,
44 const struct qstr *qstr)
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090045{
Mimi Zohar9d8f13b2011-06-06 15:29:25 -040046 return security_inode_init_security(inode, dir, qstr,
47 &jffs2_initxattrs, NULL);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090048}
49
50/* ---- XATTR Handler for "security.*" ----------------- */
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020051static int jffs2_security_getxattr(const struct xattr_handler *handler,
52 struct dentry *dentry, const char *name,
53 void *buffer, size_t size)
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090054{
David Howells2b0143b2015-03-17 22:25:59 +000055 return do_jffs2_getxattr(d_inode(dentry), JFFS2_XPREFIX_SECURITY,
Christoph Hellwig431547b2009-11-13 09:52:56 +000056 name, buffer, size);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090057}
58
Andreas Gruenbacherd9a82a02015-10-04 19:18:51 +020059static int jffs2_security_setxattr(const struct xattr_handler *handler,
60 struct dentry *dentry, const char *name,
61 const void *buffer, size_t size, int flags)
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090062{
David Howells2b0143b2015-03-17 22:25:59 +000063 return do_jffs2_setxattr(d_inode(dentry), JFFS2_XPREFIX_SECURITY,
Christoph Hellwig431547b2009-11-13 09:52:56 +000064 name, buffer, size, flags);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090065}
66
Stephen Hemminger365f0cb2010-05-13 17:53:21 -070067const struct xattr_handler jffs2_security_xattr_handler = {
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090068 .prefix = XATTR_SECURITY_PREFIX,
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090069 .set = jffs2_security_setxattr,
70 .get = jffs2_security_getxattr
71};