blob: c2332e30f218ae7f942e51a279d357ebd46fbf69 [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,
Al Virob2968212016-04-10 20:48:24 -040052 struct dentry *unused, struct inode *inode,
53 const char *name, void *buffer, size_t size)
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090054{
Al Virob2968212016-04-10 20:48:24 -040055 return do_jffs2_getxattr(inode, 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,
Al Viro59301222016-05-27 10:19:30 -040060 struct dentry *unused, struct inode *inode,
61 const char *name, const void *buffer,
62 size_t size, int flags)
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090063{
Al Viro59301222016-05-27 10:19:30 -040064 return do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY,
Christoph Hellwig431547b2009-11-13 09:52:56 +000065 name, buffer, size, flags);
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090066}
67
Stephen Hemminger365f0cb2010-05-13 17:53:21 -070068const struct xattr_handler jffs2_security_xattr_handler = {
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090069 .prefix = XATTR_SECURITY_PREFIX,
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090070 .set = jffs2_security_setxattr,
71 .get = jffs2_security_getxattr
72};