patch-2.3.27 linux/fs/proc/inode.c

Next file: linux/fs/proc/kcore.c
Previous file: linux/fs/proc/inode-alloc.txt
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.26/linux/fs/proc/inode.c linux/fs/proc/inode.c
@@ -14,6 +14,7 @@
 #include <linux/locks.h>
 #include <linux/limits.h>
 #include <linux/config.h>
+#include <linux/module.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -51,9 +52,7 @@
 static void proc_put_inode(struct inode *inode)
 {
 #ifdef CONFIG_SUN_OPENPROMFS_MODULE
-	if ((inode->i_ino >= PROC_OPENPROM_FIRST) &&
-	    (inode->i_ino <  PROC_OPENPROM_FIRST + PROC_NOPENPROM) &&
-	    proc_openprom_use)
+	if (PROC_INODE_OPENPROM(inode) && proc_openprom_use)
 		(*proc_openprom_use)(inode, 0);
 #endif	
 	/*
@@ -71,18 +70,16 @@
 {
 	struct proc_dir_entry *de = inode->u.generic_ip;
 
-#if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE)
-	if ((inode->i_ino >= PROC_OPENPROM_FIRST) &&
-	    (inode->i_ino <  PROC_OPENPROM_FIRST + PROC_NOPENPROM))
+	if (PROC_INODE_PROPER(inode)) {
+		proc_pid_delete_inode(inode);
+		return;
+	}
+	if (PROC_INODE_OPENPROM(inode))
 		return;
-#endif	
 
 	if (de) {
-		/*
-		 * Call the fill_inode hook to release module counts.
-		 */
-		if (de->fill_inode)
-			de->fill_inode(inode, 0);
+		if (de->owner)
+			__MOD_DEC_USE_COUNT(de->owner);
 		de_put(de);
 	}
 }
@@ -142,113 +139,6 @@
 	return 1;
 }
 
-/*
- * The standard rules, copied from fs/namei.c:permission().
- */
-static int standard_permission(struct inode *inode, int mask)
-{
-	int mode = inode->i_mode;
-
-	if ((mask & S_IWOTH) && IS_RDONLY(inode) &&
-	    (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
-		return -EROFS; /* Nobody gets write access to a read-only fs */
-	else if ((mask & S_IWOTH) && IS_IMMUTABLE(inode))
-		return -EACCES; /* Nobody gets write access to an immutable file */
-	else if (current->fsuid == inode->i_uid)
-		mode >>= 6;
-	else if (in_group_p(inode->i_gid))
-		mode >>= 3;
-	if (((mode & mask & S_IRWXO) == mask) || capable(CAP_DAC_OVERRIDE))
-		return 0;
-	/* read and search access */
-	if ((mask == S_IROTH) ||
-	    (S_ISDIR(mode)  && !(mask & ~(S_IROTH | S_IXOTH))))
-		if (capable(CAP_DAC_READ_SEARCH))
-			return 0;
-	return -EACCES;
-}
-
-/* 
- * Set up permission rules for processes looking at other processes.
- * You're not allowed to see a process unless it has the same or more
- * restricted root than your own.  This prevents a chrooted processes
- * from escaping through the /proc entries of less restricted
- * processes, and thus allows /proc to be safely mounted in a chrooted
- * area.
- *
- * Note that root (uid 0) doesn't get permission for this either,
- * since chroot is stronger than root.
- *
- * XXX TODO: use the dentry mechanism to make off-limits procs simply
- * invisible rather than denied?  Does each namespace root get its own
- * dentry tree?
- *
- * This also applies the default permissions checks, as it only adds
- * restrictions.
- *
- * Jeremy Fitzhardinge <jeremy@zip.com.au>
- */
-int proc_permission(struct inode *inode, int mask)
-{
-	struct task_struct *p;
-	unsigned long ino = inode->i_ino;
-	unsigned long pid;
-	struct dentry *de, *base;
-
-	if (standard_permission(inode, mask) != 0)
-		return -EACCES;
-
-	/* 
-	 * Find the root of the processes being examined (if any).
-	 * XXX Surely there's a better way of doing this?
-	 */
-	if (ino >= PROC_OPENPROM_FIRST && 
-	    ino <  PROC_OPENPROM_FIRST + PROC_NOPENPROM)
-		return 0;		/* already allowed */
-
-	pid = ino >> 16;
-	if (pid == 0)
-		return 0;		/* already allowed */
-	
-	de = NULL;
-	base = current->fs->root;
-
-	read_lock(&tasklist_lock);
-	p = find_task_by_pid(pid);
-
-	if (p && p->fs)
-		de = p->fs->root;
-	read_unlock(&tasklist_lock);	/* FIXME! */
-
-	if (p == NULL)
-		return -EACCES;		/* ENOENT? */
-
-	if (de == NULL)
-	{
-		/* kswapd and bdflush don't have proper root or cwd... */
-		return -EACCES;
-	}
-	
-	/* XXX locking? */
-	for(;;)
-	{
-		struct dentry *parent;
-
-		if (de == base)
-			return 0;	/* already allowed */
-
-		de = de->d_covers;
-		parent = de->d_parent;
-
-		if (de == parent)
-			break;
-
-		de = parent;
-	}
-
-	return -EACCES;			/* incompatible roots */
-}
-
 struct inode * proc_get_inode(struct super_block * sb, int ino,
 				struct proc_dir_entry * de)
 {
@@ -269,14 +159,9 @@
 		goto out_fail;
 	
 #ifdef CONFIG_SUN_OPENPROMFS_MODULE
-	if ((inode->i_ino >= PROC_OPENPROM_FIRST)
-	    && (inode->i_ino < PROC_OPENPROM_FIRST + PROC_NOPENPROM)
-	    && proc_openprom_use)
+	if (PROC_INODE_OPENPROM(inode) && proc_openprom_use)
 		(*proc_openprom_use)(inode, 1);
 #endif	
-	/* N.B. How can this test ever fail?? */
-	if (inode->i_sb != sb)
-		printk("proc_get_inode: inode fubar\n");
 
 	inode->u.generic_ip = (void *) de;
 	if (de) {
@@ -291,12 +176,8 @@
 			inode->i_op = de->ops;
 		if (de->nlink)
 			inode->i_nlink = de->nlink;
-		/*
-		 * The fill_inode routine should use this call 
-		 * to increment module counts, if necessary.
-		 */
-		if (de->fill_inode)
-			de->fill_inode(inode, 1);
+		if (de->owner)
+			__MOD_INC_USE_COUNT(de->owner);
 	}
 	/*
 	 * Fixup the root inode's nlink value
@@ -366,63 +247,7 @@
 
 void proc_read_inode(struct inode * inode)
 {
-	unsigned long ino, pid;
-	struct task_struct * p;
-	
 	inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
-	inode->i_blocks = 0;
-	inode->i_blksize = 1024;
-	ino = inode->i_ino;
-	if (ino >= PROC_OPENPROM_FIRST && 
-	    ino <  PROC_OPENPROM_FIRST + PROC_NOPENPROM)
-		goto out;
-	inode->i_op = NULL;
-	inode->i_mode = 0;
-	inode->i_uid = 0;
-	inode->i_gid = 0;
-	inode->i_nlink = 1;
-	inode->i_size = 0;
-
-	pid = ino >> 16;
-	if (!pid)
-		goto out;
-
-	read_lock(&tasklist_lock);
-	p = find_task_by_pid(pid);
-	if (!p)
-		goto out_unlock;
-
-	ino &= 0x0000ffff;
-	if (ino == PROC_PID_INO || p->dumpable) {
-		inode->i_uid = p->euid;
-		inode->i_gid = p->egid;
-	}
-	if (ino & PROC_PID_FD_DIR) {
-		struct file * file;
-		ino &= 0x7fff;
-		if (!p->files)	/* can we ever get here if that's the case? */
-			goto out_unlock;
-		read_lock(&p->files->file_lock);
-		file = fcheck_task(p, ino);
-		if (!file)
-			goto out_unlock2;
-
-		inode->i_op = &proc_link_inode_operations;
-		inode->i_size = 64;
-		inode->i_mode = S_IFLNK;
-		if (file->f_mode & 1)
-			inode->i_mode |= S_IRUSR | S_IXUSR;
-		if (file->f_mode & 2)
-			inode->i_mode |= S_IWUSR | S_IXUSR;
-out_unlock2:
-		read_unlock(&p->files->file_lock);
-	}
-out_unlock:
-	/* Defer unlocking until we're done with the task */
-	read_unlock(&tasklist_lock);
-
-out:
-	return;
 }
 
 void proc_write_inode(struct inode * inode)

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)