From: Chris Mason From: jeffm@suse.com reiserfs support for selinux --- 25-akpm/fs/Kconfig | 12 +++++ 25-akpm/fs/reiserfs/Makefile | 4 + 25-akpm/fs/reiserfs/xattr.c | 3 + 25-akpm/fs/reiserfs/xattr_security.c | 69 +++++++++++++++++++++++++++++++++ 25-akpm/include/linux/reiserfs_xattr.h | 3 + 5 files changed, 91 insertions(+) diff -puN fs/Kconfig~reiserfs-selinux-02 fs/Kconfig --- 25/fs/Kconfig~reiserfs-selinux-02 Fri Apr 23 14:36:51 2004 +++ 25-akpm/fs/Kconfig Fri Apr 23 14:36:51 2004 @@ -266,6 +266,18 @@ config REISERFS_FS_POSIX_ACL If you don't know what Access Control Lists are, say N +config REISERFS_FS_SECURITY + bool "ReiserFS Security Labels" + depends on REISERFS_FS_XATTR + help + Security labels support alternative access control models + implemented by security modules like SELinux. This option + enables an extended attribute handler for file security + labels in the ReiserFS filesystem. + + If you are not using a security module that requires using + extended attributes for file security labels, say N. + config JFS_FS tristate "JFS filesystem support" select NLS diff -puN fs/reiserfs/Makefile~reiserfs-selinux-02 fs/reiserfs/Makefile --- 25/fs/reiserfs/Makefile~reiserfs-selinux-02 Fri Apr 23 14:36:51 2004 +++ 25-akpm/fs/reiserfs/Makefile Fri Apr 23 14:36:51 2004 @@ -13,6 +13,10 @@ ifeq ($(CONFIG_REISERFS_FS_XATTR),y) reiserfs-objs += xattr.o xattr_user.o xattr_trusted.o endif +ifeq ($(CONFIG_REISERFS_FS_SECURITY),y) +reiserfs-objs += xattr_security.o +endif + ifeq ($(CONFIG_REISERFS_FS_POSIX_ACL),y) reiserfs-objs += xattr_acl.o endif diff -puN fs/reiserfs/xattr.c~reiserfs-selinux-02 fs/reiserfs/xattr.c --- 25/fs/reiserfs/xattr.c~reiserfs-selinux-02 Fri Apr 23 14:36:51 2004 +++ 25-akpm/fs/reiserfs/xattr.c Fri Apr 23 14:36:51 2004 @@ -1177,6 +1177,9 @@ reiserfs_xattr_register_handlers (void) /* Add the handlers */ list_add_tail (&user_handler.handlers, &xattr_handlers); list_add_tail (&trusted_handler.handlers, &xattr_handlers); +#ifdef CONFIG_REISERFS_FS_SECURITY + list_add_tail (&security_handler.handlers, &xattr_handlers); +#endif #ifdef CONFIG_REISERFS_FS_POSIX_ACL list_add_tail (&posix_acl_access_handler.handlers, &xattr_handlers); list_add_tail (&posix_acl_default_handler.handlers, &xattr_handlers); diff -puN /dev/null fs/reiserfs/xattr_security.c --- /dev/null Thu Apr 11 07:25:15 2002 +++ 25-akpm/fs/reiserfs/xattr_security.c Fri Apr 23 14:36:51 2004 @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include +#include +#include + +#define XATTR_SECURITY_PREFIX "security." + +static int +security_get (struct inode *inode, const char *name, void *buffer, size_t size) +{ + if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) + return -EINVAL; + + if (is_reiserfs_priv_object(inode)) + return -EPERM; + + return reiserfs_xattr_get (inode, name, buffer, size); +} + +static int +security_set (struct inode *inode, const char *name, const void *buffer, + size_t size, int flags) +{ + if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) + return -EINVAL; + + if (is_reiserfs_priv_object(inode)) + return -EPERM; + + return reiserfs_xattr_set (inode, name, buffer, size, flags); +} + +static int +security_del (struct inode *inode, const char *name) +{ + if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) + return -EINVAL; + + if (is_reiserfs_priv_object(inode)) + return -EPERM; + + return 0; +} + +static int +security_list (struct inode *inode, const char *name, int namelen, char *out) +{ + int len = namelen; + + if (is_reiserfs_priv_object(inode)) + return 0; + + if (out) + memcpy (out, name, len); + + return len; +} + + +struct reiserfs_xattr_handler security_handler = { + prefix: XATTR_SECURITY_PREFIX, + get: security_get, + set: security_set, + del: security_del, + list: security_list, +}; diff -puN include/linux/reiserfs_xattr.h~reiserfs-selinux-02 include/linux/reiserfs_xattr.h --- 25/include/linux/reiserfs_xattr.h~reiserfs-selinux-02 Fri Apr 23 14:36:51 2004 +++ 25-akpm/include/linux/reiserfs_xattr.h Fri Apr 23 14:36:51 2004 @@ -51,6 +51,9 @@ int reiserfs_xattr_set (struct inode *, extern struct reiserfs_xattr_handler user_handler; extern struct reiserfs_xattr_handler trusted_handler; +#ifdef CONFIG_REISERFS_FS_SECURITY +extern struct reiserfs_xattr_handler security_handler; +#endif int reiserfs_xattr_register_handlers (void) __init; void reiserfs_xattr_unregister_handlers (void); _