blob: 239f51216a68ee6e9ec1f4dc156ff513b686bc85 [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
25/* ---- Initial Security Label Attachment -------------- */
26int jffs2_init_security(struct inode *inode, struct inode *dir)
27{
28 int rc;
29 size_t len;
30 void *value;
31 char *name;
32
33 rc = security_inode_init_security(inode, dir, &name, &value, &len);
34 if (rc) {
35 if (rc == -EOPNOTSUPP)
36 return 0;
37 return rc;
38 }
39 rc = do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY, name, value, len, 0);
40
David Woodhouseef53cb02007-07-10 10:01:22 +010041 kfree(name);
42 kfree(value);
43 return rc;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090044}
45
46/* ---- XATTR Handler for "security.*" ----------------- */
Christoph Hellwig431547b2009-11-13 09:52:56 +000047static int jffs2_security_getxattr(struct dentry *dentry, const char *name,
48 void *buffer, size_t size, int type)
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090049{
50 if (!strcmp(name, ""))
51 return -EINVAL;
52
Christoph Hellwig431547b2009-11-13 09:52:56 +000053 return do_jffs2_getxattr(dentry->d_inode, JFFS2_XPREFIX_SECURITY,
54 name, buffer, size);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090055}
56
Christoph Hellwig431547b2009-11-13 09:52:56 +000057static int jffs2_security_setxattr(struct dentry *dentry, const char *name,
58 const void *buffer, size_t size, int flags, int type)
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090059{
60 if (!strcmp(name, ""))
61 return -EINVAL;
62
Christoph Hellwig431547b2009-11-13 09:52:56 +000063 return do_jffs2_setxattr(dentry->d_inode, JFFS2_XPREFIX_SECURITY,
64 name, buffer, size, flags);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090065}
66
Christoph Hellwig431547b2009-11-13 09:52:56 +000067static size_t jffs2_security_listxattr(struct dentry *dentry, char *list,
68 size_t list_size, const char *name, size_t name_len, int type)
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090069{
70 size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1;
71
72 if (list && retlen <= list_size) {
73 strcpy(list, XATTR_SECURITY_PREFIX);
74 strcpy(list + XATTR_SECURITY_PREFIX_LEN, name);
75 }
76
77 return retlen;
78}
79
Stephen Hemminger365f0cb2010-05-13 17:53:21 -070080const struct xattr_handler jffs2_security_xattr_handler = {
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090081 .prefix = XATTR_SECURITY_PREFIX,
82 .list = jffs2_security_listxattr,
83 .set = jffs2_security_setxattr,
84 .get = jffs2_security_getxattr
85};