#include <linux/mount.h>
#include <linux/tty.h>
#include <linux/devpts_fs.h>
-#include <linux/vinline.h>
-#include "xattr.h"
+#include <linux/xattr.h>
-#define DEVPTS_SUPER_MAGIC 0x1cd1
+extern struct xattr_handler devpts_xattr_security_handler;
+
+static struct xattr_handler *devpts_xattr_handlers[] = {
+#ifdef CONFIG_DEVPTS_FS_SECURITY
+ &devpts_xattr_security_handler,
+#endif
+ NULL
+};
+
+static int devpts_permission(struct inode *inode, int mask, struct nameidata *nd)
+{
+ int ret = -EACCES;
+
+ if (vx_check(inode->i_xid, VX_IDENT))
+ ret = generic_permission(inode, mask, NULL);
+ return ret;
+}
+
+static struct inode_operations devpts_file_inode_operations = {
+#ifdef CONFIG_DEVPTS_FS_XATTR
+ .setxattr = generic_setxattr,
+ .getxattr = generic_getxattr,
+ .listxattr = generic_listxattr,
+ .removexattr = generic_removexattr,
+#endif
+ .permission = devpts_permission,
+};
static struct vfsmount *devpts_mnt;
static struct dentry *devpts_root;
return 0;
}
+static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
+{
+ struct dentry *dentry = filp->f_dentry;
+ struct dentry *cursor = filp->private_data;
+ struct list_head *p, *q = &cursor->d_child;
+ ino_t ino;
+ int i = filp->f_pos;
+
+ switch (i) {
+ case 0:
+ ino = dentry->d_inode->i_ino;
+ if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0)
+ break;
+ filp->f_pos++;
+ i++;
+ /* fallthrough */
+ case 1:
+ ino = parent_ino(dentry);
+ if (filldir(dirent, "..", 2, i, ino, DT_DIR) < 0)
+ break;
+ filp->f_pos++;
+ i++;
+ /* fallthrough */
+ default:
+ spin_lock(&dcache_lock);
+ if (filp->f_pos == 2) {
+ list_del(q);
+ list_add(q, &dentry->d_subdirs);
+ }
+ for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
+ struct dentry *next;
+ next = list_entry(p, struct dentry, d_child);
+ if (d_unhashed(next) || !next->d_inode)
+ continue;
+ if (!vx_check(next->d_inode->i_xid, VX_IDENT))
+ continue;
+
+ spin_unlock(&dcache_lock);
+ if (filldir(dirent, next->d_name.name,
+ next->d_name.len, filp->f_pos,
+ next->d_inode->i_ino, DT_CHR) < 0)
+ return 0;
+ spin_lock(&dcache_lock);
+ /* next is still alive */
+ list_del(q);
+ list_add(q, p);
+ p = q;
+ filp->f_pos++;
+ }
+ spin_unlock(&dcache_lock);
+ }
+ return 0;
+}
+
+static struct file_operations devpts_dir_operations = {
+ .open = dcache_dir_open,
+ .release = dcache_dir_close,
+ .llseek = dcache_dir_lseek,
+ .read = generic_read_dir,
+ .readdir = devpts_readdir,
+};
+
static struct super_operations devpts_sops = {
.statfs = simple_statfs,
.remount_fs = devpts_remount,
s->s_blocksize_bits = 10;
s->s_magic = DEVPTS_SUPER_MAGIC;
s->s_op = &devpts_sops;
+ s->s_xattr = devpts_xattr_handlers;
+ s->s_time_gran = 1;
inode = new_inode(s);
if (!inode)
inode->i_uid = inode->i_gid = 0;
inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
inode->i_op = &simple_dir_inode_operations;
- inode->i_fop = &simple_dir_operations;
+ inode->i_fop = &devpts_dir_operations;
inode->i_nlink = 2;
+ inode->i_xid = vx_current_xid();
devpts_root = s->s_root = d_alloc_root(inode);
if (s->s_root)
return lookup_one_len(s, root, sprintf(s, "%d", num));
}
-static int devpts_permission(struct inode *inode, int mask, struct nameidata *nd)
-{
- int ret = -EACCES;
-
- if (vx_check(inode->i_xid, VX_IDENT))
- ret = vfs_permission(inode, mask);
- return ret;
-}
-
-static struct inode_operations devpts_file_inode_operations = {
- .setxattr = devpts_setxattr,
- .getxattr = devpts_getxattr,
- .listxattr = devpts_listxattr,
- .removexattr = devpts_removexattr,
- .permission = devpts_permission,
-};
-
int devpts_pty_new(struct tty_struct *tty)
{
int number = tty->index;
struct dentry *dentry = get_node(number);
struct tty_struct *tty;
- tty = (IS_ERR(dentry) || !dentry->d_inode) ? NULL :
- dentry->d_inode->u.generic_ip;
+ tty = NULL;
+ if (!IS_ERR(dentry)) {
+ if (dentry->d_inode)
+ tty = dentry->d_inode->u.generic_ip;
+ dput(dentry);
+ }
up(&devpts_root->d_inode->i_sem);
static int __init init_devpts_fs(void)
{
- int err = init_devpts_xattr();
- if (err)
- return err;
- err = register_filesystem(&devpts_fs_type);
+ int err = register_filesystem(&devpts_fs_type);
if (!err) {
devpts_mnt = kern_mount(&devpts_fs_type);
if (IS_ERR(devpts_mnt))
{
unregister_filesystem(&devpts_fs_type);
mntput(devpts_mnt);
- exit_devpts_xattr();
}
module_init(init_devpts_fs)