Skip to contentSkip to conversation

VFS: DazukoFS, stackable-fs, file access control

PATCH Superseded John Ogness 3 participants 13 messages Dec 21, 2008 – Dec 26, 2008

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover VFS: DazukoFS, stackable-fs, file access control

Hello,

This patchset introduces a new stackable filesystem: DazukoFS.

SUMMARY

DazukoFS is a stackable filesystem that provides functionality allowing userspace applications to perform online file access control. When a file is accessed on DazukoFS, registered userspace processes will be notified and given the opportunity to allow or deny the access. To help a registered process make its decision, it receives a read-only open file descriptor to the file being accessed. DazukoFS uses named grouping to determine if multiple registered processes are working together.

The features of DazukoFS can be briefly summarized as follows:

1. Parallel Event Handling
Multiple processes (or threads) may register using the same group name to signify that they are working together. When a file on DazukoFS is accessed, a file access event will be assigned to the first available process in the group. If another file access event occurs before the first has been handled, the next available process in the group will be assigned the event. If no processes in the group are currently available, that particular file access will block. This allows multiple files to be processed simultaneously.

2. Multiple Groups
Different applications may register, each using their own group name. Each group will be given the opportunity to determine if access may be allowed. Access is denied if any group decides to deny access. This allows different access control applications to run simultaneously and independent from one another.

3. Device-Determined Privileges
Each group uses its own dedicated device. When performing file access control, an application only needs read/write access to its group device. The application does not require any other privileges. Since DazukoFS already opens the file being accessed (read-only), a non-privileged registered application is able to perform online file access control for all files (including those that it would normally not have access to).

MOTIVATION

Since 2001 various anti-virus vendors have been providing out-of-tree solutions for online virus scanning. Although GNU/Linux systems currently are not targets of virus authors, many organizations are interested in online virus scanning on Linux-based servers in order to help protect Microsoft Windows clients. It is often argued that file scanning should be implemented in the various services (such as Samba, Apache, vsftpd, etc.), and indeed many such solutions have been implemented. However, there is a continued demand for a kernel-based solution because it can guard the entire filesystem independent from the types and numbers of services running on a system.

In 2002, the Dazuko project was started with the goal of providing a userspace interface on top of a kernel-based file access control mechanism. From early on, the project has aimed to support multiple anti-virus applications simultaneously without any bias towards a particular application. Today several anti-virus vendors choose Dazuko as a basis for their online file scanning solution.

Dazuko originally used syscall-table hooking for its access control mechanism. With the arrival of Linux 2.6, Dazuko switched to using LSM. However, in February 2004, Christoph Hellwig suggested that file access events should be intercepted using a stackable filesystem. After many discussions and several prototypes, it was decided that the Dazuko project would move to become a stackable
filesystem: DazukoFS.

Implementing online file access control using a stackable filesystem has several benefits:

1. No core Linux code must be modified. As a stackable filesystem, DazukoFS is a separate component of the kernel. This could prove very useful if/when anti-virus vendors want to develop new DazukoFS features. With DazukoFS as a separate component, new features could be added without requiring core Linux code changes.

2. On LKML, an interest in a stackable filesystem framework has been expressed. With DazukoFS being another stackable filesystem, we can begin looking at common code between the stackable filesystems and possibly begin identifying a stackable filesystem framework. Using real stackable filesystems as a model is much easier than guessing what should go into a stackable filesystem framework.

The Dazuko project is interested in going mainline with DazukoFS. Nearly seven years of out-of-tree development were more than enough to prove that out-of-tree kernel drivers have an unnecessarily large maintenance cost (which increases with each new kernel release). With DazukoFS mainline, anti-virus vendors would finally have an official interface and implementation on which to base their online scanning applications.

CURRENT STATE

DazukoFS currently includes a minimal set of features. This was done on purpose to try to minimize the amount of code for the initial presentation for mainline acceptance. Here is a brief listing of the current state of the project:

- Only file access events for "open" file operations are intercepted.

- Writing to memory mapped files is not supported.

- Many exotic VFS calls are not stacked upon.

- A bug was recently reported at Red Hat regarding problems using SElinux and stackable filesystems. This affects DazukoFS as well as other stackable filesystems.
https://bugzilla.redhat.com/show_bug.cgi?id=475985

- DazukoFS has been tested primarily on top of ext3 (read/write) for the powerpc architecture.

A WORD ON FANOTIFY

I am aware of the current work of Eric Paris to implement a file access control mechanism within a unified inotify/dnotify framework. Although I welcome any official interface to provide a file access control mechanism for userspace applications in Linux, I feel that DazukoFS provides a more elegant solution. (Note that the two projects do not conflict with each other.) I am open to discuss this point further if anyone is interested.

SUBMISSION PATCHSET

A series of 5 patches will be posted. Each patch provides new features and working code so that DazukoFS can be evaluated with various feature (patch) subsets. The patches can be briefly summarized as follows:

Patch 1: Introduces DazukoFS as a nullfs. This is the raw stackable
filesystem part of DazukoFS and does nothing except stack and pass filesystem calls to the lower filesystem.

Patch 2: Creates /dev/dazukofs.0 for userspace applications to perform
file access control. At this point, all applications are considered to be working together (in the same group).

Patch 3: Creates /dev/dazukofs.ctrl to allow for groups to be added,
listed, and deleted. Also, /dev/dazukofs.[0-9] devices are created to support multiple groups.

Patch 4: Adds a new (optional) command to allow registered processes
to be tracked. The tracking allows processes to be automatically unregistered if they crash and also allows groups to be automatically deleted if no more processes are registered.

Patch 5: Creates /dev/dazukofs.ign as an (optional) mechanism for any
processes to hide themselves from DazukoFS file access control.

Device permissions can be best set using udev rules. The file "Documentation/filesystems/dazukofs.txt" (also updated with each patch) describes how to use and write applications for DazukoFS.

John Ogness

#1 lore raw

PATCH 1/5 VFS: DazukoFS, stackable-fs, file access control

Patch 1: Introduces DazukoFS as a nullfs. This is the raw stackable
filesystem part of DazukoFS and does nothing except stack and pass filesystem calls to the lower filesystem.

Patched against 2.6.28-rc9.

---
 Documentation/filesystems/dazukofs.txt |   81 ++
 fs/Kconfig                             |   11 
 fs/Makefile                            |    1 
 fs/dazukofs/Makefile                   |    7 
 fs/dazukofs/dazukofs_fs.h              |  163 ++++
 fs/dazukofs/dentry.c                   |  183 +++++
 fs/dazukofs/file.c                     |  340 +++++++++
 fs/dazukofs/inode.c                    |  832 +++++++++++++++++++++++
 fs/dazukofs/mmap.c                     |  117 +++
 fs/dazukofs/super.c                    |  337 +++++++++
 10 files changed, 2072 insertions(+)
fs/dazukofs/dazukofs_fs.h new file +163 -0
Index: linux-2.6.27/fs/dazukofs/dazukofs_fs.h
===================================================================
@@ -0,0 +1,163 @@
+/* dazukofs: access control stackable filesystem
+
+   Copyright (C) 1997-2004 Erez Zadok
+   Copyright (C) 2001-2004 Stony Brook University
+   Copyright (C) 2004-2007 International Business Machines Corp.
+   Copyright (C) 2008 John Ogness
+     Author: John Ogness <[email protected]>
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   as published by the Free Software Foundation; either version 2
+   of the License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+#ifndef __DAZUKOFS_FS_H
+#define __DAZUKOFS_FS_H
+
+extern struct kmem_cache *dazukofs_dentry_info_cachep;
+extern struct kmem_cache *dazukofs_file_info_cachep;
+extern struct file_operations dazukofs_main_fops;
+extern const struct file_operations dazukofs_dir_fops;
+extern struct dentry_operations dazukofs_dops;
+extern struct address_space_operations dazukofs_aops;
+
+extern int dazukofs_interpose(struct dentry *lower_dentry,
+			      struct dentry *dentry, struct super_block *sb,
+			      int already_hashed);
+
+struct dazukofs_sb_info {
+	struct super_block *lower_sb;
+};
+
+struct dazukofs_inode_info {
+	struct inode *lower_inode;
+
+	/*
+	 * the inode (embedded)
+	 */
+	struct inode vfs_inode;
+};
+
+struct dazukofs_dentry_info {
+	struct dentry *lower_dentry;
+	struct vfsmount *lower_mnt;
+};
+
+struct dazukofs_file_info {
+	struct file *lower_file;
+};
+
+static inline
+struct dazukofs_sb_info *GET_SB_INFO(struct super_block *upper_sb)
+{
+	return upper_sb->s_fs_info;
+}
+
+static inline void SET_SB_INFO(struct super_block *upper_sb,
+			       struct dazukofs_sb_info *sbi)
+{
+	upper_sb->s_fs_info = sbi;
+}
+
+static inline struct super_block *GET_LOWER_SB(struct super_block *upper_sb)
+{
+	return ((struct dazukofs_sb_info *)upper_sb->s_fs_info)->lower_sb;
+}
+
+static inline void SET_LOWER_SB(struct super_block *upper_sb,
+				struct super_block *lower_sb)
+{
+       ((struct dazukofs_sb_info *)upper_sb->s_fs_info)->lower_sb = lower_sb;
+}
+
+static inline
+struct dazukofs_inode_info *GET_INODE_INFO(struct inode *upper_inode)
+{
+	return container_of(upper_inode, struct dazukofs_inode_info,
+			    vfs_inode);
+}
+
+static inline struct inode *GET_LOWER_INODE(struct inode *upper_inode)
+{
+	return ((struct dazukofs_inode_info *)
+		container_of(upper_inode, struct dazukofs_inode_info,
+			     vfs_inode))->lower_inode;
+}
+
+static inline void SET_LOWER_INODE(struct inode *upper_inode,
+				   struct inode *lower_inode)
+{
+	((struct dazukofs_inode_info *)
+	 container_of(upper_inode, struct dazukofs_inode_info,
+		      vfs_inode))->lower_inode = lower_inode;
+}
+
+static inline
+struct dazukofs_dentry_info *GET_DENTRY_INFO(struct dentry *upper_dentry)
+{
+	return upper_dentry->d_fsdata;
+}
+
+static inline void SET_DENTRY_INFO(struct dentry *upper_dentry,
+				   struct dazukofs_dentry_info *dentryi)
+{
+	upper_dentry->d_fsdata = dentryi;
+}
+
+static inline struct dentry *GET_LOWER_DENTRY(struct dentry *upper_dentry)
+{
+	return ((struct dazukofs_dentry_info *)
+		upper_dentry->d_fsdata)->lower_dentry;
+}
+
+static inline struct vfsmount *GET_LOWER_MNT(struct dentry *upper_dentry)
+{
+	return ((struct dazukofs_dentry_info *)
+		upper_dentry->d_fsdata)->lower_mnt;
+}
+
+static inline void SET_LOWER_DENTRY(struct dentry *upper_dentry,
+				    struct dentry *lower_dentry,
+				    struct vfsmount *lower_mnt)
+{
+	((struct dazukofs_dentry_info *)upper_dentry->d_fsdata)->lower_dentry =
+		lower_dentry;
+	((struct dazukofs_dentry_info *)upper_dentry->d_fsdata)->lower_mnt =
+		lower_mnt;
+}
+
+static inline struct dazukofs_file_info *GET_FILE_INFO(struct file *upper_file)
+{
+	return upper_file->private_data;
+}
+
+static inline void SET_FILE_INFO(struct file *upper_file,
+				 struct dazukofs_file_info *filei)
+{
+	upper_file->private_data = filei;
+}
+
+static inline struct file *GET_LOWER_FILE(struct file *upper_file)
+{
+	return ((struct dazukofs_file_info *)
+		upper_file->private_data)->lower_file;
+}
+
+static inline void SET_LOWER_FILE(struct file *upper_file,
+				  struct file *lower_file)
+{
+	((struct dazukofs_file_info *)upper_file->private_data)->lower_file =
+		lower_file;
+}
+
+#endif  /* __DAZUKOFS_FS_H */
fs/dazukofs/dentry.c new file +183 -0

183 lines not on this page · raw message

fs/dazukofs/super.c new file +337 -0

337 lines not on this page · raw message

fs/dazukofs/file.c new file +340 -0

340 lines not on this page · raw message

fs/dazukofs/inode.c new file +832 -0

832 lines not on this page · raw message

fs/dazukofs/mmap.c new file +117 -0

117 lines not on this page · raw message

fs/dazukofs/Makefile new file +7 -0
Index: linux-2.6.27/fs/dazukofs/Makefile
===================================================================
@@ -0,0 +1,7 @@
+#
+# Makefile for the Linux dazukofs-filesystem routines.
+#
+
+obj-$(CONFIG_DAZUKOFS_FS) += dazukofs.o
+
+dazukofs-objs := super.o inode.o file.o dentry.o mmap.o
fs/Kconfig +11 -0
Index: linux-2.6.27/fs/Kconfig
===================================================================
@@ -816,6 +816,17 @@
 	  To compile this file system support as a module, choose M here: the
 	  module will be called ecryptfs.
 
+config DAZUKOFS_FS
+	tristate "DazukoFS filesystem layer support (EXPERIMENTAL)"
+	depends on EXPERIMENTAL
+	help
+	  A pass-through stackable filesystem (also referred to as nullfs).
+	  See <file:Documentation/filesystems/dazukofs.txt> to learn more
+	  about DazukoFS.
+
+	  To compile this file system support as a module, choose M here: the
+	  module will be called dazukofs.
+
 config HFS_FS
 	tristate "Apple Macintosh file system support (EXPERIMENTAL)"
 	depends on BLOCK && EXPERIMENTAL
fs/Makefile +1 -0
Index: linux-2.6.27/fs/Makefile
===================================================================
@@ -86,6 +86,7 @@
 obj-$(CONFIG_HFSPLUS_FS)	+= hfsplus/ # Before hfs to find wrapped HFS+
 obj-$(CONFIG_HFS_FS)		+= hfs/
 obj-$(CONFIG_ECRYPT_FS)		+= ecryptfs/
+obj-$(CONFIG_DAZUKOFS_FS)	+= dazukofs/
 obj-$(CONFIG_VXFS_FS)		+= freevxfs/
 obj-$(CONFIG_NFS_FS)		+= nfs/
 obj-$(CONFIG_EXPORTFS)		+= exportfs/
Documentation/filesystems/dazukofs.txt new file +81 -0

81 lines not on this page · raw message

#2 lore raw

PATCH 2/5 VFS: DazukoFS, stackable-fs, file access control

Patch 2: Creates /dev/dazukofs.0 for userspace applications to perform
file access control. At this point, all applications are considered to be working together (in the same group).

Patched against 2.6.28-rc9.

---
 Documentation/filesystems/dazukofs.txt |   89 +++
 fs/Kconfig                             |    3 
 fs/dazukofs/Makefile                   |    3 
 fs/dazukofs/dev.c                      |   85 +++
 fs/dazukofs/dev.h                      |   37 +
 fs/dazukofs/event.c                    |  628 +++++++++++++++++++++++
 fs/dazukofs/event.h                    |   32 +
 fs/dazukofs/file.c                     |    7 
 fs/dazukofs/group_dev.c                |  159 +++++
 fs/dazukofs/super.c                    |   16 
 10 files changed, 1046 insertions(+), 13 deletions(-)
fs/dazukofs/dev.c new file +85 -0
Index: linux-2.6.27/fs/dazukofs/dev.c
===================================================================
@@ -0,0 +1,85 @@
+/* dazukofs: access control stackable filesystem
+
+   Copyright (C) 2008 John Ogness
+     Author: John Ogness <[email protected]>
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   as published by the Free Software Foundation; either version 2
+   of the License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+#include <linux/device.h>
+#include <linux/fs.h>
+#include <linux/cdev.h>
+#include <linux/uaccess.h>
+
+#include "dazukofs_fs.h"
+#include "event.h"
+#include "dev.h"
+
+static struct class *dazukofs_class;
+
+static int dev_major;
+static int dev_minor_start;
+static int dev_minor_end;
+
+int dazukofs_dev_init(void)
+{
+	int err = 0;
+	dev_t devt;
+
+	err = dazukofs_init_events();
+	if (err)
+		goto error_out1;
+
+	err = alloc_chrdev_region(&devt, 0, 1, DEVICE_NAME);
+	if (err)
+		goto error_out2;
+	dev_major = MAJOR(devt);
+	dev_minor_start = MINOR(devt);
+
+	/* create class */
+	dazukofs_class = class_create(THIS_MODULE, DEVICE_NAME);
+	if (IS_ERR(dazukofs_class)) {
+		err = PTR_ERR(dazukofs_class);
+		goto error_out3;
+	}
+
+	dev_minor_end = dazukofs_group_dev_init(dev_major,
+						dev_minor_start + 1,
+						dazukofs_class);
+	if (dev_minor_end < 0) {
+		err = dev_minor_end;
+		goto error_out4;
+	}
+
+	return 0;
+
+error_out4:
+	class_destroy(dazukofs_class);
+error_out3:
+	unregister_chrdev_region(MKDEV(dev_major, dev_minor_start), 1);
+error_out2:
+	dazukofs_destroy_events();
+error_out1:
+	return err;
+}
+
+void dazukofs_dev_destroy(void)
+{
+	dazukofs_group_dev_destroy(dev_major, dev_minor_start + 1,
+				   dev_minor_end, dazukofs_class);
+	class_destroy(dazukofs_class);
+	unregister_chrdev_region(MKDEV(dev_major, dev_minor_start), 1);
+	dazukofs_destroy_events();
+}
fs/dazukofs/group_dev.c new file +159 -0

159 lines not on this page · raw message

fs/dazukofs/event.c new file +628 -0

628 lines not on this page · raw message

fs/dazukofs/dev.h new file +37 -0
Index: linux-2.6.27/fs/dazukofs/dev.h
===================================================================
@@ -0,0 +1,37 @@
+/* dazukofs: access control stackable filesystem
+
+   Copyright (C) 2008 John Ogness
+     Author: John Ogness <[email protected]>
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   as published by the Free Software Foundation; either version 2
+   of the License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+#ifndef __DEV_H
+#define __DEV_H
+
+struct class;
+
+#define DEVICE_NAME	"dazukofs"
+
+extern int dazukofs_dev_init(void);
+extern void dazukofs_dev_destroy(void);
+
+extern int dazukofs_group_dev_init(int dev_major, int dev_minor_start,
+				   struct class *dazukofs_class);
+extern void dazukofs_group_dev_destroy(int dev_major, int dev_minor_start,
+				       int dev_minor_end,
+				       struct class *dazukofs_class);
+
+#endif /* __DEV_H */
fs/dazukofs/Makefile +2 -1
Index: linux-2.6.27/fs/dazukofs/Makefile
===================================================================
@@ -4,4 +4,5 @@
 
 obj-$(CONFIG_DAZUKOFS_FS) += dazukofs.o
 
-dazukofs-objs := super.o inode.o file.o dentry.o mmap.o
+dazukofs-objs := super.o inode.o file.o dentry.o mmap.o event.o \
+		 dev.o group_dev.o
fs/dazukofs/super.c +12 -4
Index: linux-2.6.27/fs/dazukofs/super.c
===================================================================
@@ -28,6 +28,7 @@
 #include <linux/mount.h>
 
 #include "dazukofs_fs.h"
+#include "dev.h"
 
 static struct kmem_cache *dazukofs_inode_info_cachep;
 static struct kmem_cache *dazukofs_sb_info_cachep;
@@ -306,19 +307,25 @@
 {
 	int err = 0;
 
-	err = init_caches();
+	err = dazukofs_dev_init();
 	if (err)
 		goto error_out1;
 
-	err = register_filesystem(&dazukofs_fs_type);
+	err = init_caches();
 	if (err)
 		goto error_out2;
 
+	err = register_filesystem(&dazukofs_fs_type);
+	if (err)
+		goto error_out3;
+
 	printk(KERN_INFO "dazukofs: loaded\n");
 	return 0;
 
-error_out2:
+error_out3:
 	destroy_caches();
+error_out2:
+	dazukofs_dev_destroy();
 error_out1:
 	return err;
 }
@@ -327,11 +334,12 @@
 {
 	unregister_filesystem(&dazukofs_fs_type);
 	destroy_caches();
+	dazukofs_dev_destroy();
 	printk(KERN_INFO "dazukofs: unloaded\n");
 }
 
 MODULE_AUTHOR("John Ogness");
-MODULE_DESCRIPTION("pass-through stackable filesystem");
+MODULE_DESCRIPTION("access control stackable filesystem");
 MODULE_LICENSE("GPL");
 module_init(init_dazukofs_fs)
 module_exit(exit_dazukofs_fs)
fs/dazukofs/file.c +6 -1
Index: linux-2.6.27/fs/dazukofs/file.c
===================================================================
@@ -28,6 +28,7 @@
 #include <linux/fs_stack.h>
 
 #include "dazukofs_fs.h"
+#include "event.h"
 
 /**
  * Description: Called when the VFS needs to move the file position index.
@@ -174,7 +175,11 @@
 	struct dentry *lower_dentry = dget(GET_LOWER_DENTRY(dentry));
 	struct vfsmount *lower_mnt = mntget(GET_LOWER_MNT(dentry));
 	struct file *lower_file;
-	int err = 0;
+	int err;
+
+	err = dazukofs_check_access(file->f_dentry, file->f_vfsmnt);
+	if (err)
+		goto error_out1;
 
 	SET_FILE_INFO(file, kmem_cache_zalloc(dazukofs_file_info_cachep,
 		      GFP_KERNEL));
fs/dazukofs/event.h new file +32 -0
Index: linux-2.6.27/fs/dazukofs/event.h
===================================================================
@@ -0,0 +1,32 @@
+/* dazukofs: access control stackable filesystem
+
+   Copyright (C) 2008 John Ogness
+     Author: John Ogness <[email protected]>
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   as published by the Free Software Foundation; either version 2
+   of the License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+#ifndef __EVENT_H
+#define __EVENT_H
+
+extern int dazukofs_init_events(void);
+extern void dazukofs_destroy_events(void);
+
+extern int dazukofs_get_event(unsigned long *event_id, int *fd, pid_t *pid);
+extern int dazukofs_return_event(unsigned long event_id, int deny);
+
+extern int dazukofs_check_access(struct dentry *dentry, struct vfsmount *mnt);
+
+#endif /* __EVENT_H */
fs/Kconfig +2 -1
Index: linux-2.6.27/fs/Kconfig
===================================================================
@@ -820,7 +820,8 @@
 	tristate "DazukoFS filesystem layer support (EXPERIMENTAL)"
 	depends on EXPERIMENTAL
 	help
-	  A pass-through stackable filesystem (also referred to as nullfs).
+	  A stackable filesystem to allow userspace applications to perform
+	  online file access control.
 	  See <file:Documentation/filesystems/dazukofs.txt> to learn more
 	  about DazukoFS.
 
Documentation/filesystems/dazukofs.txt +83 -6

112 lines not on this page · raw message

#3 lore raw

PATCH 3/5 VFS: DazukoFS, stackable-fs, file access control

Patch 3: Creates /dev/dazukofs.ctrl to allow for groups to be added,
listed, and deleted. Also, /dev/dazukofs.[0-9] devices are created to support multiple groups.

Patched against 2.6.28-rc9.

---
 Documentation/filesystems/dazukofs.txt |   73 ++-
 fs/dazukofs/Makefile                   |    2 
 fs/dazukofs/ctrl_dev.c                 |  198 ++++++++
 fs/dazukofs/dev.c                      |   18 
 fs/dazukofs/dev.h                      |    6 
 fs/dazukofs/event.c                    |  537 +++++++++++++++++++++--
 fs/dazukofs/event.h                    |   10 
 fs/dazukofs/group_dev.c                |  107 +++-
 8 files changed, 867 insertions(+), 84 deletions(-)
fs/dazukofs/event.c +497 -40
Index: linux-2.6.27/fs/dazukofs/event.c
===================================================================
@@ -25,6 +25,7 @@
 #include <linux/mount.h>
 #include <linux/freezer.h>
 
+#include "dev.h"
 #include "dazukofs_fs.h"
 
 struct dazukofs_proc {
@@ -55,20 +56,34 @@
 };
 
 struct dazukofs_group {
+	struct list_head list;
+	char *name;
+	size_t name_length;
+	unsigned long group_id;
 	struct dazukofs_event_container todo_list;
 	wait_queue_head_t queue;
 	struct dazukofs_event_container working_list;
+	atomic_t use_count;
+	int deprecated;
 };
 
-static struct dazukofs_group reg_group;
+static struct dazukofs_group group_list;
+
+static wait_queue_head_t __group_count_queue;
+static int __group_count;
+static int __group_count_busy; /* if set, __group_count is protected */
 
-/* protects: grp->members, last_event_id,
+/* protects: group_list, grp->members, last_event_id,
  *	     todo_list, working_list */
 static struct mutex work_mutex;
 
+/* protects: __group_count_busy */
+static struct mutex group_count_mutex;
+
 static struct mutex proc_mutex;
 static struct dazukofs_proc proc_list;
 
+static struct kmem_cache *dazukofs_group_cachep;
 static struct kmem_cache *dazukofs_event_container_cachep;
 static struct kmem_cache *dazukofs_event_cachep;
 
@@ -86,11 +101,19 @@
 {
 	mutex_init(&proc_mutex);
 	mutex_init(&work_mutex);
+	mutex_init(&group_count_mutex);
+
 	INIT_LIST_HEAD(&proc_list.list);
+	INIT_LIST_HEAD(&group_list.list);
+
+	init_waitqueue_head(&__group_count_queue);
 
-	init_waitqueue_head(&reg_group.queue);
-	INIT_LIST_HEAD(&reg_group.todo_list.list);
-	INIT_LIST_HEAD(&reg_group.working_list.list);
+	dazukofs_group_cachep =
+		kmem_cache_create("dazukofs_group_cache",
+				  sizeof(struct dazukofs_group), 0,
+				  SLAB_HWCACHE_ALIGN, NULL);
+	if (!dazukofs_group_cachep)
+		goto error_out;
 
 	dazukofs_event_container_cachep =
 		kmem_cache_create("dazukofs_event_container_cache",
@@ -109,6 +132,8 @@
 	return 0;
 
 error_out:
+	if (dazukofs_group_cachep)
+		kmem_cache_destroy(dazukofs_group_cachep);
 	if (dazukofs_event_container_cachep)
 		kmem_cache_destroy(dazukofs_event_container_cachep);
 	if (dazukofs_event_cachep)
@@ -117,6 +142,81 @@
 }
 
 /**
+ * capture_group_count - try to lock the group count
+ * @cache: a black-box argument to make sure that a process does not try
+ *         lock the group count recursively
+ *
+ * Description: This function will attempt to lock the group count. If it
+ * is already locked, this function returns an error. Kernel locking is
+ * only used to protect the "busy" flag. The group count is handled this
+ * way because it needs to be protected AND there is a lot of sleeping
+ * and blocking between the "get" and "put" of the group count.
+ *
+ * The cache argument is needed because of the way wait_event_freezable()
+ * in get_group_count() is implememted. Even if the condition is
+ * successful, it will be called one more time. Both calls must return
+ * success. The cache is set on success. On the next call we notice that
+ * it is set and immediately return success again.
+ *
+ * Returns 0 if the group count lock was acquired.
+ */
+static int capture_group_count(int *cache)
+{
+	int err = 0;
+
+	if (*cache)
+		return 0;
+
+	mutex_lock(&group_count_mutex);
+	if (__group_count_busy)
+		err = -1;
+	else
+		__group_count_busy = 1;
+	mutex_unlock(&group_count_mutex);
+
+	if (err == 0)
+		*cache = 1;
+	return err;
+}
+
+/**
+ * get_group_count - lock the group count (blocking)
+ *
+ * Description: This function will block until the group count lock has been
+ * acquired (or the process was interrupted). If successful, a process is
+ * required to later call put_group_count() to free the lock.
+ *
+ * It is allowed to sleep/block while this lock is held. However, no other
+ * processes may be able to acquire the lock during this time.
+ *
+ * Returns 0 if the group count lock was acquired.
+ */
+static int get_group_count(void)
+{
+	int cache = 0;
+	int ret = wait_event_freezable(__group_count_queue,
+				       capture_group_count(&cache) == 0);
+	if (ret == 0)
+		ret = __group_count;
+	return ret;
+}
+
+/**
+ * put_group_count - releases the group count lock
+ *
+ * Description: This function will release the group count lock. The
+ * function must only be called after a successful call to
+ * get_group_count().
+ */
+static void put_group_count(void)
+{
+	mutex_lock(&group_count_mutex);
+	__group_count_busy = 0;
+	mutex_unlock(&group_count_mutex);
+	wake_up(&__group_count_queue);
+}
+
+/**
  * release_event - release (and possible free) an event
  * @evt: the event to release
  * @decrement_assigned: flag to signal if the assigned count should be
@@ -210,10 +310,17 @@
  * Description: All pending and in-progress events are released/freed.
  * Any processes waiting on the queue are woken.
  *
+ * The actual group structure is not deleted, but rather marked as
+ * deprecated. Deprecated group structures are deleted as new
+ * groups are added.
+ *
  * IMPORTANT: This function requires work_mutex to be held!
  */
 static void __remove_group(struct dazukofs_group *grp)
 {
+	grp->deprecated = 1;
+	__group_count--;
+
 	__clear_group_event_list(&grp->working_list.list);
 	__clear_group_event_list(&grp->todo_list.list);
 
@@ -228,17 +335,282 @@
  */
 void dazukofs_destroy_events(void)
 {
-	/* free the group items */
-	mutex_lock(&work_mutex);
-	__remove_group(&reg_group);
-	mutex_unlock(&work_mutex);
+	struct dazukofs_group *grp;
+	struct list_head *pos;
+	struct list_head *q;
+
+	/*
+	 * We are not using any locks here because we assume
+	 * everything else has been already cleaned up by
+	 * the device layer.
+	 */
+
+	/* free the groups */
+	list_for_each_safe(pos, q, &group_list.list) {
+		grp = list_entry(pos, struct dazukofs_group, list);
+		list_del(pos);
+
+		__remove_group(grp);
+
+		/* free group name */
+		kfree(grp->name);
+
+		/* free group */
+		kmem_cache_free(dazukofs_group_cachep, grp);
+	}
 
 	/* free everything else */
+	kmem_cache_destroy(dazukofs_group_cachep);
 	kmem_cache_destroy(dazukofs_event_container_cachep);
 	kmem_cache_destroy(dazukofs_event_cachep);
 }
 
 /**
+ * __check_for_group - check if a group exists
+ * @name: a group name to check for
+ * @id: a group id to check for
+ * @already_exists: will be set if the group already exists
+ *
+ * Description: This function checks names and id's to see if a group may
+ * be created. If the id already exists, but with a different group name,
+ * the group cannot be created. If the group name exists, but with a
+ * different id, the group cannot be created.
+ *
+ * If the group name exists and the id is already that which is requested,
+ * the function returns success, but sets the already_exists flag.
+ *
+ * IMPORTANT: This function requires work_mutex to be held!
+ *
+ * Returns 0 if the group exists or may be created.
+ */
+static int __check_for_group(const char *name, int id, int *already_exists)
+{
+	struct dazukofs_group *grp;
+	struct list_head *pos;
+	struct list_head *q;
+	int id_available = 1;
+
+	*already_exists = 0;
+
+	list_for_each_safe(pos, q, &group_list.list) {
+		grp = list_entry(pos, struct dazukofs_group, list);
+		if (grp->deprecated) {
+			/* cleanup deprecated groups */
+			if (atomic_read(&grp->use_count) == 0) {
+				list_del(pos);
+				kfree(grp->name);
+				kmem_cache_free(dazukofs_group_cachep, grp);
+			}
+		} else {
+			if (strcmp(name, grp->name) == 0) {
+				*already_exists = 1;
+				break;
+			} else if (grp->group_id == id) {
+				id_available = 0;
+				break;
+			}
+		}
+	}
+
+	if (*already_exists)
+		return 0;
+
+	if (id_available) {
+		/* we have found a free id */
+		return 0;
+	}
+
+	return -1;
+}
+
+/**
+ * create_group - allocate and initialize a group structure
+ * @name: the name of the new group
+ * @id: the id of the new group
+ *
+ * Description: This function allocates and initializes a group
+ * structure. The group_count should be locked to ensure that
+ * the group id remains available until the group can be
+ * added to the group list.
+ *
+ * Returns the newly created and initialized group structure.
+ */
+static struct dazukofs_group *create_group(const char *name, int id)
+{
+	struct dazukofs_group *grp;
+
+	grp = kmem_cache_zalloc(dazukofs_group_cachep, GFP_KERNEL);
+	if (!grp)
+		return NULL;
+
+	atomic_set(&grp->use_count, 0);
+	grp->group_id = id;
+	grp->name = kstrdup(name, GFP_KERNEL);
+	if (!grp->name) {
+		kmem_cache_free(dazukofs_group_cachep, grp);
+		return NULL;
+	}
+	grp->name_length = strlen(name);
+	init_waitqueue_head(&grp->queue);
+	INIT_LIST_HEAD(&grp->todo_list.list);
+	INIT_LIST_HEAD(&grp->working_list.list);
+	return grp;
+}
+
+/**
+ * dazukofs_add_group - add a new group
+ * @name: the name of the group to add
+ *
+ * Description: This function is called by the device layer to add a new
+ * group. It returns success if the group has been successfully created
+ * or if the group already exists.
+ *
+ * Returns 0 on success.
+ */
+int dazukofs_add_group(const char *name)
+{
+	int ret = 0;
+	int already_exists;
+	int available_id = 0;
+	struct dazukofs_group *grp;
+	int grp_count = get_group_count();
+
+	if (grp_count < 0) {
+		ret = grp_count;
+		goto out1;
+	}
+
+	mutex_lock(&work_mutex);
+	while (__check_for_group(name, available_id, &already_exists) != 0) {
+		/* try again with the next id */
+		available_id++;
+	}
+	mutex_unlock(&work_mutex);
+
+	if (already_exists)
+		goto out2;
+
+	/* if we are here, the group doesn't already exist */
+
+	/* do we have room for a new group? */
+	if (grp_count == GROUP_COUNT) {
+		ret = -EPERM;
+		goto out2;
+	}
+
+	grp = create_group(name, available_id);
+	if (!grp) {
+		ret = -ENOMEM;
+		goto out2;
+	}
+
+	mutex_lock(&work_mutex);
+	list_add_tail(&grp->list, &group_list.list);
+	mutex_unlock(&work_mutex);
+
+	__group_count++;
+out2:
+	put_group_count();
+out1:
+	return ret;
+}
+
+/**
+ * dazukofs_remove_group - remove a group
+ * @name: the name of the group to remove
+ *
+ * Description: This function is called by the device layer to remove a
+ * group. It returns success if the group has been deleted or the group
+ * does not exist.
+ *
+ * Returns 0 on success.
+ */
+int dazukofs_remove_group(const char *name)
+{
+	int ret = 0;
+	struct dazukofs_group *grp;
+	struct list_head *pos;
+	int grp_count = get_group_count();
+
+	if (grp_count < 0) {
+		ret = grp_count;
+		goto out1;
+	}
+
+	if (grp_count == 0)
+		goto out2;
+
+	mutex_lock(&work_mutex);
+	/* set group deprecated */
+	list_for_each(pos, &group_list.list) {
+		grp = list_entry(pos, struct dazukofs_group, list);
+		if (!grp->deprecated && strcmp(name, grp->name) == 0) {
+			__remove_group(grp);
+			break;
+		}
+	}
+	mutex_unlock(&work_mutex);
+out2:
+	put_group_count();
+out1:
+	return ret;
+}
+
+/**
+ * dazukofs_get_groups - get the names and id's of active groups as strings
+ * @buf: to be assigned the list of groups as a single printable string
+ *
+ * Description: This function will allocate a string that includes all the
+ * active (not deprecated) groups and their id's. This function is called
+ * by the device layer for presenting userspace with the list of groups.
+ *
+ * This function will allocate memory that must be freed by the caller.
+ *
+ * Returns 0 on success.
+ */
+int dazukofs_get_groups(char **buf)
+{
+	struct dazukofs_group *grp;
+	char *tmp;
+	struct list_head *pos;
+	size_t buflen;
+	size_t allocsize = 256;
+
+tryagain:
+	*buf = kzalloc(allocsize, GFP_KERNEL);
+	if (!*buf)
+		return -ENOMEM;
+	tmp = *buf;
+	buflen = 1;
+
+	mutex_lock(&work_mutex);
+	list_for_each(pos, &group_list.list) {
+		grp = list_entry(pos, struct dazukofs_group, list);
+		if (!grp->deprecated)
+			buflen += grp->name_length + 3;
+	}
+	if (buflen < allocsize) {
+		list_for_each(pos, &group_list.list) {
+			grp = list_entry(pos, struct dazukofs_group, list);
+			if (!grp->deprecated) {
+				snprintf(tmp, (allocsize - 1) - (tmp - *buf),
+					 "%lu:%s\n", grp->group_id,
+					 grp->name);
+				tmp += grp->name_length + 3;
+			}
+		}
+		mutex_unlock(&work_mutex);
+	} else {
+		mutex_unlock(&work_mutex);
+		allocsize *= 2;
+		kfree(*buf);
+		goto tryagain;
+	}
+
+	return 0;
+}
+
+/**
  * check_recursion - check if current process is recursing
  *
  * Description: A list of anonymous processes is managed to prevent
@@ -295,14 +667,19 @@
 
 /**
  * check_access_precheck - check if an access event should be generated
+ * @grp_count: the current number of groups
  *
  * Description: Check if the current process should cause an access event
  * to be generated.
  *
  * Returns 0 if an access event should be generated.
  */
-static int check_access_precheck(void)
+static int check_access_precheck(int grp_count)
 {
+	/* do we have any groups? */
+	if (grp_count == 0)
+		return -1;
+
 	/* am I a recursion process? */
 	if (!check_recursion())
 		return -1;
@@ -311,19 +688,22 @@
 }
 
 /**
- * assign_event_to_group - post an event to be processed
+ * assign_event_to_groups - post an event to be processed
  * @evt: the event to be posted
- * @ec: the container for the event
+ * @ec_array: the containers for the event
  *
  * Description: This function will assign a unique id to the event.
- * The event will be associated with its container and placed on the
- * group's todo list. The group will also be woken to handle the new
- * event.
+ * The event will be associated with each container and the container is
+ * placed on each group's todo list. Each group will also be woken to
+ * handle the new event.
  */
 static void
-assign_event_to_group(struct dazukofs_event *evt,
-		      struct dazukofs_event_container *ec) {
-	struct dazukofs_group *grp = &reg_group;
+assign_event_to_groups(struct dazukofs_event *evt,
+		       struct dazukofs_event_container *ec_array[])
+{
+	struct dazukofs_group *grp;
+	struct list_head *pos;
+	int i;
 
 	mutex_lock(&work_mutex);
 	mutex_lock(&evt->assigned_mutex);
@@ -333,44 +713,67 @@
 	last_event_id++;
 	evt->event_id = last_event_id;
 
-	ec->event = evt;
-	evt->assigned = 1;
-	list_add_tail(&ec->list, &grp->todo_list.list);
+	/* assign the event to each group */
+	i = 0;
+	list_for_each(pos, &group_list.list) {
+		grp = list_entry(pos, struct dazukofs_group, list);
+		if (!grp->deprecated) {
+			ec_array[i]->event = evt;
+
+			evt->assigned++;
+			list_add_tail(&ec_array[i]->list,
+				      &grp->todo_list.list);
 
-	/* notify someone to handle the event */
-	wake_up(&grp->queue);
+			/* notify someone to handle the event */
+			wake_up(&grp->queue);
+
+			i++;
+		}
+	}
 
 	mutex_unlock(&evt->assigned_mutex);
 	mutex_unlock(&work_mutex);
 }
 
 /**
- * allocate_event_and_container - allocate an event and event container
+ * allocate_event_and_containers - allocate an event and event containers
  * @evt: event pointer to be assigned a new event
- * @ec: event container to be assigned a new container
+ * @ec: event container array to be filled with new array of containers
+ * @grp_count: the number of groups (size of the array)
  *
  * Description: New event and event container structures are allocated
  * and initialized.
  *
  * Returns 0 on success.
  */
-static int allocate_event_and_container(struct dazukofs_event **evt,
-					struct dazukofs_event_container **ec)
+static int
+allocate_event_and_containers(struct dazukofs_event **evt,
+			      struct dazukofs_event_container *ec_array[],
+			      int grp_count)
 {
+	int i;
+
 	*evt = kmem_cache_zalloc(dazukofs_event_cachep, GFP_KERNEL);
 	if (!*evt)
 		return -1;
 	init_waitqueue_head(&(*evt)->queue);
 	mutex_init(&(*evt)->assigned_mutex);
 
-	/* allocate container now while we don't have a lock */
-	*ec = kmem_cache_zalloc(dazukofs_event_container_cachep, GFP_KERNEL);
-	if (!*ec)
-		goto error_out;
+	/* allocate containers now while we don't have a lock */
+	for (i = 0; i < grp_count; i++) {
+		ec_array[i] = kmem_cache_zalloc(
+				dazukofs_event_container_cachep, GFP_KERNEL);
+		if (!ec_array[i])
+			goto error_out;
+	}
 
 	return 0;
 
 error_out:
+	for (i--; i >= 0; i--) {
+		kmem_cache_free(dazukofs_event_container_cachep, ec_array[i]);
+		ec_array[i] = NULL;
+	}
 	kmem_cache_free(dazukofs_event_cachep, *evt);
 	*evt = NULL;
 	return -1;
@@ -388,16 +791,23 @@
  */
 int dazukofs_check_access(struct dentry *dentry, struct vfsmount *mnt)
 {
-	struct dazukofs_event_container *ec;
+	struct dazukofs_event_container *ec_array[GROUP_COUNT];
 	struct dazukofs_event *evt;
+	int grp_count = get_group_count();
 	int err;
 
-	if (check_access_precheck())
+	if (grp_count < 0)
+		return grp_count;
+
+	if (check_access_precheck(grp_count)) {
+		put_group_count();
 		return 0;
+	}
 
 	/* at this point, the access should be handled */
 
-	if (allocate_event_and_container(&evt, &ec)) {
+	if (allocate_event_and_containers(&evt, ec_array, grp_count)) {
+		put_group_count();
 		err = -ENOMEM;
 		goto out;
 	}
@@ -406,7 +816,9 @@
 	evt->mnt = mntget(mnt);
 	evt->pid = current->pid;
 
-	assign_event_to_group(evt, ec);
+	assign_event_to_groups(evt, ec_array);
+
+	put_group_count();
 
 	/* wait until event completely processed or signal */
 	err = wait_event_freezable(evt->queue, event_assigned(evt) == 0);
@@ -421,6 +833,7 @@
 
 /**
  * dazukofs_return_event - return checked file access results
+ * @group_id: id of the group the event came from
  * @event_id: the id of the event
  * @deny: a flag indicating if file access should be denied
  *
@@ -430,9 +843,10 @@
  *
  * Returns 0 on success.
  */
-int dazukofs_return_event(unsigned long event_id, int deny)
+int dazukofs_return_event(unsigned long group_id, unsigned long event_id,
+			  int deny)
 {
-	struct dazukofs_group *grp = &reg_group;
+	struct dazukofs_group *grp;
 	struct dazukofs_event_container *ec;
 	struct dazukofs_event *evt = NULL;
 	struct list_head *pos;
@@ -440,6 +854,20 @@
 	int ret = 0;
 
 	mutex_lock(&work_mutex);
+	list_for_each(pos, &group_list.list) {
+		grp = list_entry(pos, struct dazukofs_group, list);
+		if (!grp->deprecated && grp->group_id == group_id) {
+			found = 1;
+			break;
+		}
+	}
+	if (!found) {
+		ret = -EFAULT;
+		mutex_unlock(&work_mutex);
+		goto out;
+	}
+
+	found = 0;
 	list_for_each(pos, &grp->working_list.list) {
 		ec = list_entry(pos, struct dazukofs_event_container, list);
 		evt = ec->event;
@@ -456,6 +884,7 @@
 		release_event(evt, 1, deny);
 	else
 		ret = -EFAULT;
+out:
 	return ret;
 }
 
@@ -589,6 +1018,7 @@
 
 /**
  * dazukofs_get_event - get an event to process
+ * @group_id: id of the group we belong to
  * @event_id: to be filled in with the new event id
  * @fd: to be filled in with the opened file descriptor
  * @pid: to be filled in with the pid of the process generating the event
@@ -599,18 +1029,43 @@
  *
  * Returns 0 on success.
  */
-int dazukofs_get_event(unsigned long *event_id, int *fd, pid_t *pid)
+int dazukofs_get_event(unsigned long group_id, unsigned long *event_id,
+		       int *fd, pid_t *pid)
 {
-	struct dazukofs_group *grp = &reg_group;
+	struct dazukofs_group *grp;
 	struct dazukofs_event_container *ec;
+	struct list_head *pos;
+	int found = 0;
 	int ret = 0;
 
+	mutex_lock(&work_mutex);
+	list_for_each(pos, &group_list.list) {
+		grp = list_entry(pos, struct dazukofs_group, list);
+		if (!grp->deprecated && grp->group_id == group_id) {
+			atomic_inc(&grp->use_count);
+			found = 1;
+			break;
+		}
+	}
+	mutex_unlock(&work_mutex);
+
+	if (!found) {
+		ret = -EFAULT;
+		goto out;
+	}
+
 	while (1) {
 		ret = wait_event_freezable(grp->queue,
-					   is_event_available(grp));
+					   is_event_available(grp) ||
+					   grp->deprecated);
 		if (ret != 0)
 			break;
 
+		if (grp->deprecated) {
+			ret = -EFAULT;
+			break;
+		}
+
 		ec = claim_event(grp);
 		if (ec) {
 			ret = open_file(ec);
@@ -624,5 +1079,7 @@
 			}
 		}
 	}
+	atomic_dec(&grp->use_count);
+out:
 	return ret;
 }
fs/dazukofs/Makefile +1 -1
Index: linux-2.6.27/fs/dazukofs/Makefile
===================================================================
@@ -5,4 +5,4 @@
 obj-$(CONFIG_DAZUKOFS_FS) += dazukofs.o
 
 dazukofs-objs := super.o inode.o file.o dentry.o mmap.o event.o \
-		 dev.o group_dev.o
+		 dev.o group_dev.o ctrl_dev.o
fs/dazukofs/ctrl_dev.c new file +198 -0

198 lines not on this page · raw message

fs/dazukofs/group_dev.c +81 -26

156 lines not on this page · raw message

fs/dazukofs/dev.c +14 -4
Index: linux-2.6.27/fs/dazukofs/dev.c
===================================================================
@@ -42,7 +42,7 @@
 	if (err)
 		goto error_out1;
 
-	err = alloc_chrdev_region(&devt, 0, 1, DEVICE_NAME);
+	err = alloc_chrdev_region(&devt, 0, 1 + GROUP_COUNT, DEVICE_NAME);
 	if (err)
 		goto error_out2;
 	dev_major = MAJOR(devt);
@@ -55,20 +55,28 @@
 		goto error_out3;
 	}
 
+	err = dazukofs_ctrl_dev_init(dev_major, dev_minor_start,
+				     dazukofs_class);
+	if (err)
+		goto error_out4;
+
 	dev_minor_end = dazukofs_group_dev_init(dev_major,
 						dev_minor_start + 1,
 						dazukofs_class);
 	if (dev_minor_end < 0) {
 		err = dev_minor_end;
-		goto error_out4;
+		goto error_out5;
 	}
 
 	return 0;
 
+error_out5:
+	dazukofs_ctrl_dev_destroy(dev_major, dev_minor_start, dazukofs_class);
 error_out4:
 	class_destroy(dazukofs_class);
 error_out3:
-	unregister_chrdev_region(MKDEV(dev_major, dev_minor_start), 1);
+	unregister_chrdev_region(MKDEV(dev_major, dev_minor_start),
+				 1 + GROUP_COUNT);
 error_out2:
 	dazukofs_destroy_events();
 error_out1:
@@ -79,7 +87,9 @@
 {
 	dazukofs_group_dev_destroy(dev_major, dev_minor_start + 1,
 				   dev_minor_end, dazukofs_class);
+	dazukofs_ctrl_dev_destroy(dev_major, dev_minor_start, dazukofs_class);
 	class_destroy(dazukofs_class);
-	unregister_chrdev_region(MKDEV(dev_major, dev_minor_start), 1);
+	unregister_chrdev_region(MKDEV(dev_major, dev_minor_start),
+				 1 + GROUP_COUNT);
 	dazukofs_destroy_events();
 }
fs/dazukofs/dev.h +6 -0
Index: linux-2.6.27/fs/dazukofs/dev.h
===================================================================
@@ -24,6 +24,7 @@
 struct class;
 
 #define DEVICE_NAME	"dazukofs"
+#define GROUP_COUNT	10
 
 extern int dazukofs_dev_init(void);
 extern void dazukofs_dev_destroy(void);
@@ -34,4 +35,9 @@
 				       int dev_minor_end,
 				       struct class *dazukofs_class);
 
+extern int dazukofs_ctrl_dev_init(int dev_major, int dev_minor,
+				  struct class *dazukofs_class);
+extern void dazukofs_ctrl_dev_destroy(int dev_major, int dev_minor,
+				      struct class *dazukofs_class);
+
 #endif /* __DEV_H */
fs/dazukofs/event.h +8 -2
Index: linux-2.6.27/fs/dazukofs/event.h
===================================================================
@@ -24,9 +24,15 @@
 extern int dazukofs_init_events(void);
 extern void dazukofs_destroy_events(void);
 
-extern int dazukofs_get_event(unsigned long *event_id, int *fd, pid_t *pid);
-extern int dazukofs_return_event(unsigned long event_id, int deny);
+extern int dazukofs_get_event(unsigned long group_id,
+			      unsigned long *event_id, int *fd, pid_t *pid);
+extern int dazukofs_return_event(unsigned long group_id,
+				 unsigned long event_id, int deny);
 
 extern int dazukofs_check_access(struct dentry *dentry, struct vfsmount *mnt);
 
+extern int dazukofs_get_groups(char **buf);
+extern int dazukofs_add_group(const char *name);
+extern int dazukofs_remove_group(const char *name);
+
 #endif /* __EVENT_H */
Documentation/filesystems/dazukofs.txt +62 -11

89 lines not on this page · raw message

#4 lore raw

PATCH 4/5 VFS: DazukoFS, stackable-fs, file access control

Patch 4: Adds a new (optional) command to allow registered processes
to be tracked. The tracking allows processes to be automatically unregistered if they crash and also allows groups to be automatically deleted if no more processes are registered.

Patched against 2.6.28-rc9.

---
 Documentation/filesystems/dazukofs.txt |   24 ++++-
 fs/dazukofs/ctrl_dev.c                 |   15 ++-
 fs/dazukofs/event.c                    |  102 +++++++++++++++++++++--
 fs/dazukofs/event.h                    |    7 +
 fs/dazukofs/group_dev.c                |   30 ++++++
 5 files changed, 161 insertions(+), 17 deletions(-)
fs/dazukofs/ctrl_dev.c +11 -4
Index: linux-2.6.27/fs/dazukofs/ctrl_dev.c
===================================================================
@@ -85,7 +85,7 @@
 }
 
 static int process_command(char *buf, const char *key,
-			   int (*func)(const char *),
+			   int (*func)(const char *, int), int arg2,
 			   int *retcode)
 {
 	char *p;
@@ -104,7 +104,7 @@
 		*retcode = -EINVAL;
 	} else {
 		*p2 = 0;
-		*retcode = func(p);
+		*retcode = func(p, arg2);
 		*p2 = ' ';
 	}
 
@@ -131,14 +131,21 @@
 
 	if (!match || (match && ret >= 0)) {
 		if (process_command(tmp, "del=",
-				    dazukofs_remove_group, &ret) == 0) {
+				    dazukofs_remove_group, 0, &ret) == 0) {
 			match = 1;
 		}
 	}
 
 	if (!match || (match && ret >= 0)) {
 		if (process_command(tmp, "add=",
-				    dazukofs_add_group, &ret) == 0) {
+				    dazukofs_add_group, 0, &ret) == 0) {
+			match = 1;
+		}
+	}
+
+	if (!match || (match && ret >= 0)) {
+		if (process_command(tmp, "addtrack=",
+				    dazukofs_add_group, 1, &ret) == 0) {
 			match = 1;
 		}
 	}
fs/dazukofs/event.c +95 -7

194 lines not on this page · raw message

fs/dazukofs/event.h +5 -2
Index: linux-2.6.27/fs/dazukofs/event.h
===================================================================
@@ -31,8 +31,11 @@
 
 extern int dazukofs_check_access(struct dentry *dentry, struct vfsmount *mnt);
 
+extern int dazukofs_group_open_tracking(unsigned long group_id);
+extern void dazukofs_group_release_tracking(unsigned long group_id);
+
 extern int dazukofs_get_groups(char **buf);
-extern int dazukofs_add_group(const char *name);
-extern int dazukofs_remove_group(const char *name);
+extern int dazukofs_add_group(const char *name, int track);
+extern int dazukofs_remove_group(const char *name, int unused);
 
 #endif /* __EVENT_H */
fs/dazukofs/group_dev.c +30 -0
Index: linux-2.6.27/fs/dazukofs/group_dev.c
===================================================================
@@ -27,6 +27,24 @@
 #include "event.h"
 #include "dev.h"
 
+static int dazukofs_group_open(int group_id, struct inode *inode,
+			       struct file *file)
+{
+	if (dazukofs_group_open_tracking(group_id))
+		file->private_data = file;
+	else
+		file->private_data = NULL;
+	return 0;
+}
+
+static int dazukofs_group_release(int group_id, struct inode *inode,
+				  struct file *file)
+{
+	if (file->private_data)
+		dazukofs_group_release_tracking(group_id);
+	return 0;
+}
+
 static ssize_t dazukofs_group_read(int group_id, struct file *file,
 				   char __user *buffer, size_t length,
 				   loff_t *pos)
@@ -112,6 +130,16 @@
 }
 
 #define DECLARE_GROUP_FOPS(group_id) \
+static int \
+dazukofs_group_open_##group_id(struct inode *inode, struct file *file) \
+{ \
+	return dazukofs_group_open(group_id, inode, file); \
+} \
+static int \
+dazukofs_group_release_##group_id(struct inode *inode, struct file *file) \
+{ \
+	return dazukofs_group_release(group_id, inode, file); \
+} \
 static ssize_t \
 dazukofs_group_read_##group_id(struct file *file, char __user *buffer, \
 			       size_t length, loff_t *pos) \
@@ -127,6 +155,8 @@
 } \
 static struct file_operations group_fops_##group_id = { \
 	.owner		= THIS_MODULE, \
+	.open		= dazukofs_group_open_##group_id, \
+	.release	= dazukofs_group_release_##group_id, \
 	.read		= dazukofs_group_read_##group_id, \
 	.write		= dazukofs_group_write_##group_id, \
 };
Documentation/filesystems/dazukofs.txt +20 -4
Index: linux-2.6.27/Documentation/filesystems/dazukofs.txt
===================================================================
@@ -180,10 +180,26 @@
 
 By closing the device, the application will unregister itself.
 
-NOTE: It is not necessary for the device to be open while the application
-      decides if access should be allowed. In fact, it doesn't even have to
-      be the same process that responds. DazukoFS is only interested in a
-      response that matches the pending event id.
+To provide crash protection for applications, groups can be added using
+the "addtrack" keyword instead of "add". The keyword "addtrack" tells
+DazukoFS to add the group and track the number of registered processes in
+that group. Tracking begins as soon as the first process has registered
+with DazukoFS. Once all processes of the group have unregistered, DazukoFS
+will automatically delete the group.
+
+If an application crashes, is killed, or ends without closing the device,
+DazukoFS will still unregister that process. Using "addtrack" will ensure
+that a created group is automatically deleted if the application is not
+able to shutdown in a clean manner.
+
+NOTE: If "addtrack" is used, it is necessary for the device to be kept open
+      the entire time the application is performing online file access
+      control. Otherwise the group may become unintentionally deleted.
+
+      If "add" is used, it is not necessary for the device to be kept open
+      while the application decides if access should be allowed. Actually,
+      DazukoFS doesn't care which process responds to a file access event.
+      DazukoFS is only interested in a response for the given event id.
 
 A group can be deleted by writing to the /dev/dazukofs.ctrl device. For
 example, writing:
#5 lore raw

PATCH 5/5 VFS: DazukoFS, stackable-fs, file access control

Patch 5: Creates /dev/dazukofs.ign as an (optional) mechanism for any
processes to hide themselves from DazukoFS file access control.

Patched against 2.6.28-rc9.

---
 Documentation/filesystems/dazukofs.txt |   24 ++
 fs/dazukofs/Makefile                   |    2 
 fs/dazukofs/dev.c                      |   22 +-
 fs/dazukofs/dev.h                      |    6 
 fs/dazukofs/event.c                    |    4 
 fs/dazukofs/ign_dev.c                  |  186 +++++++++++++++++++++++
 6 files changed, 237 insertions(+), 7 deletions(-)
fs/dazukofs/ign_dev.c new file +186 -0
Index: linux-2.6.27/fs/dazukofs/ign_dev.c
===================================================================
@@ -0,0 +1,186 @@
+/* dazukofs: access control stackable filesystem
+
+   Copyright (C) 2008 John Ogness
+     Author: John Ogness <[email protected]>
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   as published by the Free Software Foundation; either version 2
+   of the License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+#include <linux/device.h>
+#include <linux/fs.h>
+#include <linux/cdev.h>
+#include <linux/uaccess.h>
+
+#include "dazukofs_fs.h"
+#include "dev.h"
+
+struct dazukofs_proc {
+	struct list_head list;
+	struct task_struct *curr;
+};
+
+static struct dazukofs_proc ign_list;
+static struct mutex ign_list_mutex;
+static struct kmem_cache *dazukofs_ign_cachep;
+
+int dazukofs_check_ignore_process(void)
+{
+	struct list_head *pos;
+	struct dazukofs_proc *proc;
+	int found = 0;
+
+	mutex_lock(&ign_list_mutex);
+	list_for_each(pos, &ign_list.list) {
+		proc = list_entry(pos, struct dazukofs_proc, list);
+		if (proc->curr == current) {
+			found = 1;
+			break;
+		}
+	}
+	mutex_unlock(&ign_list_mutex);
+
+	return !found;
+}
+
+static int dazukofs_add_ign(struct file *file)
+{
+	struct dazukofs_proc *proc =
+		kmem_cache_zalloc(dazukofs_ign_cachep, GFP_KERNEL);
+	if (!proc) {
+		file->private_data = NULL;
+		return -ENOMEM;
+	}
+
+	file->private_data = proc;
+	proc->curr = current;
+
+	mutex_lock(&ign_list_mutex);
+	list_add(&proc->list, &ign_list.list);
+	mutex_unlock(&ign_list_mutex);
+
+	return 0;
+}
+
+static void dazukofs_remove_ign(struct file *file)
+{
+	struct list_head *pos;
+	struct dazukofs_proc *proc = NULL;
+	struct dazukofs_proc *check_proc = file->private_data;
+	int found = 0;
+
+	if (!check_proc)
+		return;
+
+	mutex_lock(&ign_list_mutex);
+	list_for_each(pos, &ign_list.list) {
+		proc = list_entry(pos, struct dazukofs_proc, list);
+		if (proc->curr == check_proc->curr) {
+			found = 1;
+			list_del(pos);
+			break;
+		}
+	}
+	mutex_unlock(&ign_list_mutex);
+
+	if (found) {
+		file->private_data = NULL;
+		kmem_cache_free(dazukofs_ign_cachep, proc);
+	}
+}
+
+static int dazukofs_ign_open(struct inode *inode, struct file *file)
+{
+	return dazukofs_add_ign(file);
+}
+
+static int dazukofs_ign_release(struct inode *inode, struct file *file)
+{
+	dazukofs_remove_ign(file);
+	return 0;
+}
+
+static void dazukofs_destroy_ignlist(void)
+{
+	struct list_head *pos;
+	struct list_head *q;
+	struct dazukofs_proc *proc;
+
+	list_for_each_safe(pos, q, &ign_list.list) {
+		proc = list_entry(pos, struct dazukofs_proc, list);
+		list_del(pos);
+		kmem_cache_free(dazukofs_ign_cachep, proc);
+	}
+}
+
+static struct cdev ign_cdev;
+
+static struct file_operations ign_fops = {
+	.owner		= THIS_MODULE,
+	.open		= dazukofs_ign_open,
+	.release	= dazukofs_ign_release,
+};
+
+int dazukofs_ign_dev_init(int dev_major, int dev_minor,
+			  struct class *dazukofs_class)
+{
+	int err = 0;
+	struct device *dev;
+
+	INIT_LIST_HEAD(&ign_list.list);
+	mutex_init(&ign_list_mutex);
+
+	dazukofs_ign_cachep =
+		kmem_cache_create("dazukofs_ign_cache",
+				  sizeof(struct dazukofs_proc), 0,
+				  SLAB_HWCACHE_ALIGN, NULL);
+	if (!dazukofs_ign_cachep) {
+		err = -ENOMEM;
+		goto error_out1;
+	}
+
+	/* setup cdev for ignore */
+	cdev_init(&ign_cdev, &ign_fops);
+	ign_cdev.owner = THIS_MODULE;
+	err = cdev_add(&ign_cdev, MKDEV(dev_major, dev_minor), 1);
+	if (err)
+		goto error_out2;
+
+	/* create ignore device */
+	dev = device_create(dazukofs_class, NULL, MKDEV(dev_major, dev_minor),
+			    NULL, "%s.ign", DEVICE_NAME);
+	if (IS_ERR(dev)) {
+		err = PTR_ERR(dev);
+		goto error_out3;
+	}
+
+	return 0;
+
+error_out3:
+	cdev_del(&ign_cdev);
+error_out2:
+	dazukofs_destroy_ignlist();
+	kmem_cache_destroy(dazukofs_ign_cachep);
+error_out1:
+	return err;
+}
+
+void dazukofs_ign_dev_destroy(int dev_major, int dev_minor,
+			      struct class *dazukofs_class)
+{
+	device_destroy(dazukofs_class, MKDEV(dev_major, dev_minor));
+	cdev_del(&ign_cdev);
+	dazukofs_destroy_ignlist();
+	kmem_cache_destroy(dazukofs_ign_cachep);
+}
fs/dazukofs/Makefile +1 -1
Index: linux-2.6.27/fs/dazukofs/Makefile
===================================================================
@@ -5,4 +5,4 @@
 obj-$(CONFIG_DAZUKOFS_FS) += dazukofs.o
 
 dazukofs-objs := super.o inode.o file.o dentry.o mmap.o event.o \
-		 dev.o group_dev.o ctrl_dev.o
+		 dev.o group_dev.o ctrl_dev.o ign_dev.o
fs/dazukofs/event.c +4 -0
Index: linux-2.6.27/fs/dazukofs/event.c
===================================================================
@@ -707,6 +707,10 @@
 	if (!check_recursion())
 		return -1;
 
+	/* am I an ignored process? */
+	if (!dazukofs_check_ignore_process())
+		return -1;
+
 	return 0;
 }
 
fs/dazukofs/dev.c +16 -6
Index: linux-2.6.27/fs/dazukofs/dev.c
===================================================================
@@ -42,7 +42,7 @@
 	if (err)
 		goto error_out1;
 
-	err = alloc_chrdev_region(&devt, 0, 1 + GROUP_COUNT, DEVICE_NAME);
+	err = alloc_chrdev_region(&devt, 0, 2 + GROUP_COUNT, DEVICE_NAME);
 	if (err)
 		goto error_out2;
 	dev_major = MAJOR(devt);
@@ -60,23 +60,31 @@
 	if (err)
 		goto error_out4;
 
+	err = dazukofs_ign_dev_init(dev_major, dev_minor_start + 1,
+				    dazukofs_class);
+	if (err)
+		goto error_out5;
+
 	dev_minor_end = dazukofs_group_dev_init(dev_major,
-						dev_minor_start + 1,
+						dev_minor_start + 2,
 						dazukofs_class);
 	if (dev_minor_end < 0) {
 		err = dev_minor_end;
-		goto error_out5;
+		goto error_out6;
 	}
 
 	return 0;
 
+error_out6:
+	dazukofs_ign_dev_destroy(dev_major, dev_minor_start + 1,
+				 dazukofs_class);
 error_out5:
 	dazukofs_ctrl_dev_destroy(dev_major, dev_minor_start, dazukofs_class);
 error_out4:
 	class_destroy(dazukofs_class);
 error_out3:
 	unregister_chrdev_region(MKDEV(dev_major, dev_minor_start),
-				 1 + GROUP_COUNT);
+				 2 + GROUP_COUNT);
 error_out2:
 	dazukofs_destroy_events();
 error_out1:
@@ -85,11 +93,13 @@
 
 void dazukofs_dev_destroy(void)
 {
-	dazukofs_group_dev_destroy(dev_major, dev_minor_start + 1,
+	dazukofs_group_dev_destroy(dev_major, dev_minor_start + 2,
 				   dev_minor_end, dazukofs_class);
+	dazukofs_ign_dev_destroy(dev_major, dev_minor_start + 1,
+				 dazukofs_class);
 	dazukofs_ctrl_dev_destroy(dev_major, dev_minor_start, dazukofs_class);
 	class_destroy(dazukofs_class);
 	unregister_chrdev_region(MKDEV(dev_major, dev_minor_start),
-				 1 + GROUP_COUNT);
+				 2 + GROUP_COUNT);
 	dazukofs_destroy_events();
 }
fs/dazukofs/dev.h +6 -0
Index: linux-2.6.27/fs/dazukofs/dev.h
===================================================================
@@ -40,4 +40,10 @@
 extern void dazukofs_ctrl_dev_destroy(int dev_major, int dev_minor,
 				      struct class *dazukofs_class);
 
+extern int dazukofs_ign_dev_init(int dev_major, int dev_minor,
+				 struct class *dazukofs_class);
+extern void dazukofs_ign_dev_destroy(int dev_major, int dev_minor,
+				     struct class *dazukofs_class);
+extern int dazukofs_check_ignore_process(void);
+
 #endif /* __DEV_H */
Documentation/filesystems/dazukofs.txt +24 -0
Index: linux-2.6.27/Documentation/filesystems/dazukofs.txt
===================================================================
@@ -223,3 +223,27 @@
 access events to be handled by each group. For this reason it is important
 that an application deletes a group it has created, once it should no longer
 perform online file access control.
+
+All processes on the system that try to access files on a DazukoFS mount will
+require authorization (if at least one group exists). This is also true for
+registered process that try to access files on a DazukoFS mount.
+
+IMPORTANT: If registered processes access files on a DazukoFS mount, they
+           will cause new file access events that must be authorized. This
+           could lead to deadlock if not properly considered.
+
+Since the registered process receives an open file descriptor to the file
+being accessed, there should be no need for that process to open other
+files. However, if the process must open additional files (and these
+files potentially lie on a DazukoFS mount), it is possible for processes
+to hide themselves from DazukoFS.
+
+By opening the /dev/dazukofs.ign device, a process will be ignored by
+DazukoFS. It does not matter if the process is registered or not. No data
+must be written or read from the device. It simply needs to be opened.
+
+WARNING: Make sure the permissions for /dev/dazukofs.ign are securely
+         set. Otherwise, any process could potentially hide itself.
+
+As soon as the /dev/dazukofs.ign device is closed, the process is no
+longer hidden.
#6 lore raw
In reply to John Ogness

fs/dazukofs/dazukofs_fs.h line 25

Quoted 2 lines · John Ogness
fs/dazukofs/dazukofs_fs.h new file +2 -0
+#ifndef __DAZUKOFS_FS_H
+#define __DAZUKOFS_FS_H

There are several (okay, all) includes missing.

fs/dazukofs/dazukofs_fs.h line 61

Quoted 2 lines
fs/dazukofs/dazukofs_fs.h new file +2 -0
+static inline
+struct dazukofs_sb_info *GET_SB_INFO(struct super_block *upper_sb)

Coding-style.

fs/dazukofs/dazukofs_fs.h line 103

Quoted 7 lines
fs/dazukofs/dazukofs_fs.h new file +7 -0
+static inline void SET_LOWER_INODE(struct inode *upper_inode,
+				   struct inode *lower_inode)
+{
+	((struct dazukofs_inode_info *)
+	 container_of(upper_inode, struct dazukofs_inode_info,
+		      vfs_inode))->lower_inode = lower_inode;
+}

Please make such cast cascades explicit:

| struct dazukofs_inode_info *info = container_of(...); | info->lower_inode = lower_inode;

There are other people which want to read the code.

Quoted 4 lines
fs/dazukofs/dentry.c new file +4 -0
+static int dazukofs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
+{
+	struct vfsmount *lower_mnt;
+	struct dentry *lower_dentry;

fs/dazukofs/dentry.c line 64

Quoted 10 lines
fs/dazukofs/dentry.c new file +10 -0
+	struct vfsmount *vfsmount_save;
+	struct dentry *dentry_save;
+	int valid;
+
+	valid = 1;
+
+	lower_dentry = GET_LOWER_DENTRY(dentry);
+
+	if (!lower_dentry->d_op || !lower_dentry->d_op->d_revalidate)
+		goto out;

Why do you use goto instead of return?

fs/dazukofs/dentry.c line 114

Quoted 8 lines
fs/dazukofs/dentry.c new file +8 -0
+static int dazukofs_d_hash(struct dentry *dentry, struct qstr *name)
+{
+	struct dentry *lower_dentry = GET_LOWER_DENTRY(dentry);
+
+	if (!lower_dentry || !lower_dentry->d_op ||
+	    !lower_dentry->d_op->d_hash) {
+		return 0;
+	}

You mix rather different coding styles through the whole code. Also why do you say that lower_dentry can be 0 in _hash, but not in _revalidate?

fs/dazukofs/dentry.c line 132

Quoted 5 lines
fs/dazukofs/dentry.c new file +5 -0
+static void dazukofs_d_release(struct dentry *dentry)
+{
+	if (GET_DENTRY_INFO(dentry)) {
+		dput(GET_LOWER_DENTRY(dentry));
+		mntput(GET_LOWER_MNT(dentry));

Why do you push anything out in other functions while making it explicit would make it much easier readable?

Bastian

Signature · 2 lines
Killing is stupid; useless!
		-- McCoy, "A Private Little War", stardate 4211.8
#7 lore raw
Quoted 1 line · Bastian Blank

There are several (okay, all) includes missing.

Indeed. I will fix this.

Quoted 4 lines

fs/dazukofs/dazukofs_fs.h line 61

Quoted 2 lines
fs/dazukofs/dazukofs_fs.h new file +2 -0
+static inline
+struct dazukofs_sb_info *GET_SB_INFO(struct super_block *upper_sb)

Coding-style.

The functions were originally macros. The capitalization was inspired by macros such as IS_ERR, PTR_ERR, MKDEV, etc. That is the explanation, but it doesn't make it ok. I will change it.

Quoted 10 lines

fs/dazukofs/dazukofs_fs.h line 103

Quoted 7 lines
fs/dazukofs/dazukofs_fs.h new file +7 -0
+static inline void SET_LOWER_INODE(struct inode *upper_inode,
+				   struct inode *lower_inode)
+{
+	((struct dazukofs_inode_info *)
+	 container_of(upper_inode, struct dazukofs_inode_info,
+		      vfs_inode))->lower_inode = lower_inode;
+}

Please make such cast cascades explicit:

Quoted 4 lines

| struct dazukofs_inode_info *info = container_of(...); | info->lower_inode = lower_inode;

There are other people which want to read the code.

Agreed.

Quoted 8 lines
Quoted 8 lines
fs/dazukofs/dentry.c new file +8 -0
+static int dazukofs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
+{
+	struct vfsmount *lower_mnt;
+	struct dentry *lower_dentry;
+	struct vfsmount *vfsmount_save;
+	struct dentry *dentry_save;
+	int valid;
+
Quoted 8 lines

fs/dazukofs/dentry.c line 64

Quoted 6 lines
fs/dazukofs/dentry.c new file +6 -0
+	valid = 1;
+
+	lower_dentry = GET_LOWER_DENTRY(dentry);
+
+	if (!lower_dentry->d_op || !lower_dentry->d_op->d_revalidate)
+		goto out;

Why do you use goto instead of return?

I use a goto here so that only 1 exit point exists within the function. However, that probably doesn't make much sense when such basic sanity checks are performed at the beginning of the function. I will change this.

Quoted 10 lines

fs/dazukofs/dentry.c line 114

Quoted 8 lines
fs/dazukofs/dentry.c new file +8 -0
+static int dazukofs_d_hash(struct dentry *dentry, struct qstr *name)
+{
+	struct dentry *lower_dentry = GET_LOWER_DENTRY(dentry);
+
+	if (!lower_dentry || !lower_dentry->d_op ||
+	    !lower_dentry->d_op->d_hash) {
+		return 0;
+	}

You mix rather different coding styles through the whole code.

When I wrote the stacking code, it was the first time I started using the Linux coding style. I will go back through and see what I can clean up.

Quoted 2 lines

Also why do you say that lower_dentry can be 0 in _hash, but not in _revalidate?

_hash doesn't need this check. I will remove it.

Quoted 8 lines

fs/dazukofs/dentry.c line 132

Quoted 5 lines
fs/dazukofs/dentry.c new file +5 -0
+static void dazukofs_d_release(struct dentry *dentry)
+{
+	if (GET_DENTRY_INFO(dentry)) {
+		dput(GET_LOWER_DENTRY(dentry));
+		mntput(GET_LOWER_MNT(dentry));

Why do you push anything out in other functions while making it explicit would make it much easier readable?

For me, writing a stackable filesystem was quite complex. Using the all-caps functions for upper/lower layer translations helped me to easily see what I was doing. I agree that the all-caps thing is quite ugly. I will change that, but I would prefer to keep the translation functions as separate inline functions. (The same technique can be seen in ecryptfs as well.)

John Ogness

#8 lore raw
In reply to John Ogness

Hi!

Quoted 12 lines

MOTIVATION

Since 2001 various anti-virus vendors have been providing out-of-tree solutions for online virus scanning. Although GNU/Linux systems currently are not targets of virus authors, many organizations are interested in online virus scanning on Linux-based servers in order to help protect Microsoft Windows clients. It is often argued that file scanning should be implemented in the various services (such as Samba, Apache, vsftpd, etc.), and indeed many such solutions have been implemented. However, there is a continued demand for a kernel-based solution because it can guard the entire filesystem independent from the types and numbers of services running on a system.

Somewhere here you should mention that unlike other solutions that work 100% of time, dazuko is be design racy and may still allow viruses to be spread from linux system when mmap is used.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#9 lore raw
Quoted 15 lines · Pavel Machek
Quoted 14 lines

MOTIVATION

Since 2001 various anti-virus vendors have been providing out-of-tree solutions for online virus scanning. Although GNU/Linux systems currently are not targets of virus authors, many organizations are interested in online virus scanning on Linux-based servers in order to help protect Microsoft Windows clients. It is often argued that file scanning should be implemented in the various services (such as Samba, Apache, vsftpd, etc.), and indeed many such solutions have been implemented. However, there is a continued demand for a kernel-based solution because it can guard the entire filesystem independent from the types and numbers of services running on a system.

Quoted 3 lines

Somewhere here you should mention that unlike other solutions that work 100% of time, dazuko is be design racy and may still allow viruses to be spread from linux system when mmap is used.

This thread is about DazukoFS. I feel there is no need to discuss previous incarnations of Dazuko, all of which share _no_ code with DazukoFS.

If you are aware of a race condition in DazukoFS, please report it. Thank you.

John Ogness

#10 lore raw
Quoted 20 lines · John Ogness
Quoted 15 lines · Pavel Machek
Quoted 14 lines

MOTIVATION

Since 2001 various anti-virus vendors have been providing out-of-tree solutions for online virus scanning. Although GNU/Linux systems currently are not targets of virus authors, many organizations are interested in online virus scanning on Linux-based servers in order to help protect Microsoft Windows clients. It is often argued that file scanning should be implemented in the various services (such as Samba, Apache, vsftpd, etc.), and indeed many such solutions have been implemented. However, there is a continued demand for a kernel-based solution because it can guard the entire filesystem independent from the types and numbers of services running on a system.

Quoted 3 lines

Somewhere here you should mention that unlike other solutions that work 100% of time, dazuko is be design racy and may still allow viruses to be spread from linux system when mmap is used.

Quoted 6 lines

This thread is about DazukoFS. I feel there is no need to discuss previous incarnations of Dazuko, all of which share _no_ code with DazukoFS.

If you are aware of a race condition in DazukoFS, please report it. Thank you.

I'm surprised, do you claim there is none?

So how do you handle mmap(...MAP_SHARED) case?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#11 lore raw
Quoted 4 lines · Pavel Machek
Quoted 2 lines

If you are aware of a race condition in DazukoFS, please report it. Thank you.

I'm surprised, do you claim there is none?

It depends on how you want to define "race condition". DazukoFS (in its current form) closes as many holes as default UNIX permissions or SElinux. However, changing permissions (i.e. scanning files) _after_ two parties already have an open handle to the file is currently not covered. But this issue is not unique to DazukoFS (although as a stackable filesystem, DazukoFS could support this case as well).

Quoted 1 line

So how do you handle mmap(...MAP_SHARED) case?

DazukoFS currently does not support writing to memory mapped files for this very reason. It needs to be determined how writing to memory mapped files should be handled. I am choosing to tackle this issue together with the Linux kernel community, rather than trying to solve it within the much smaller Dazuko community.

Although memory mapped writing is currently not supported, I believe DazukoFS still offers value to the Linux kernel. I am not aware of any network services that require memory mapped writing for their sharing.

John Ogness

#12 lore raw
Quoted 4 lines · John Ogness
Quoted 3 lines · Pavel Machek
Quoted 2 lines

If you are aware of a race condition in DazukoFS, please report it. Thank you.

Quoted 8 lines
Quoted 1 line

I'm surprised, do you claim there is none?

It depends on how you want to define "race condition". DazukoFS (in its current form) closes as many holes as default UNIX permissions or SElinux. However, changing permissions (i.e. scanning files) _after_ two parties already have an open handle to the file is currently not covered. But this issue is not unique to DazukoFS (although as a stackable filesystem, DazukoFS could support this case as well).

Not unique to dazukofs, but regression to scanning at nfsd level, right? So I guess it should be mentioned in changelog if you compare yourself to solutions that do not have this problem.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html