Commit aed54175 authored by Vegard Nossum's avatar Vegard Nossum Committed by Linus Torvalds

proc: calculate the correct /proc/<pid> link count

This patch:

  commit e9720acd
  Author: Pavel Emelyanov <xemul@openvz.org>
  Date:   Fri Mar 7 11:08:40 2008 -0800

    [NET]: Make /proc/net a symlink on /proc/self/net (v3)

introduced a /proc/self/net directory without bumping the corresponding
link count for /proc/self.

This patch replaces the static link count initializations with a call that
counts the number of directory entries in the given pid_entry table
whenever it is instantiated, and thus relieves the burden of manually
keeping the two in sync.

[akpm@linux-foundation.org: cleanup]
Acked-by: default avatarEric W. Biederman <ebiederm@xmission.com>
Cc: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: default avatarVegard Nossum <vegard.nossum@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: <stable@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent aabe1885
...@@ -127,6 +127,25 @@ struct pid_entry { ...@@ -127,6 +127,25 @@ struct pid_entry {
NULL, &proc_single_file_operations, \ NULL, &proc_single_file_operations, \
{ .proc_show = &proc_##OTYPE } ) { .proc_show = &proc_##OTYPE } )
/*
* Count the number of hardlinks for the pid_entry table, excluding the .
* and .. links.
*/
static unsigned int pid_entry_count_dirs(const struct pid_entry *entries,
unsigned int n)
{
unsigned int i;
unsigned int count;
count = 0;
for (i = 0; i < n; ++i) {
if (S_ISDIR(entries[i].mode))
++count;
}
return count;
}
int maps_protect; int maps_protect;
EXPORT_SYMBOL(maps_protect); EXPORT_SYMBOL(maps_protect);
...@@ -2585,10 +2604,9 @@ static struct dentry *proc_pid_instantiate(struct inode *dir, ...@@ -2585,10 +2604,9 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
inode->i_op = &proc_tgid_base_inode_operations; inode->i_op = &proc_tgid_base_inode_operations;
inode->i_fop = &proc_tgid_base_operations; inode->i_fop = &proc_tgid_base_operations;
inode->i_flags|=S_IMMUTABLE; inode->i_flags|=S_IMMUTABLE;
inode->i_nlink = 5;
#ifdef CONFIG_SECURITY inode->i_nlink = 2 + pid_entry_count_dirs(tgid_base_stuff,
inode->i_nlink += 1; ARRAY_SIZE(tgid_base_stuff));
#endif
dentry->d_op = &pid_dentry_operations; dentry->d_op = &pid_dentry_operations;
...@@ -2816,10 +2834,9 @@ static struct dentry *proc_task_instantiate(struct inode *dir, ...@@ -2816,10 +2834,9 @@ static struct dentry *proc_task_instantiate(struct inode *dir,
inode->i_op = &proc_tid_base_inode_operations; inode->i_op = &proc_tid_base_inode_operations;
inode->i_fop = &proc_tid_base_operations; inode->i_fop = &proc_tid_base_operations;
inode->i_flags|=S_IMMUTABLE; inode->i_flags|=S_IMMUTABLE;
inode->i_nlink = 4;
#ifdef CONFIG_SECURITY inode->i_nlink = 2 + pid_entry_count_dirs(tid_base_stuff,
inode->i_nlink += 1; ARRAY_SIZE(tid_base_stuff));
#endif
dentry->d_op = &pid_dentry_operations; dentry->d_op = &pid_dentry_operations;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment