Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99b76233 authored by Alexey Dobriyan's avatar Alexey Dobriyan
Browse files

proc 2/2: remove struct proc_dir_entry::owner

Setting ->owner as done currently (pde->owner = THIS_MODULE) is racy
as correctly noted at bug #12454. Someone can lookup entry with NULL
->owner, thus not pinning enything, and release it later resulting
in module refcount underflow.

We can keep ->owner and supply it at registration time like ->proc_fops
and ->data.

But this leaves ->owner as easy-manipulative field (just one C assignment)
and somebody will forget to unpin previous/pin current module when
switching ->owner. ->proc_fops is declared as "const" which should give
some thoughts.

->read_proc/->write_proc were just fixed to not require ->owner for
protection.

rmmod'ed directories will be empty and return "." and ".." -- no harm.
And directories with tricky enough readdir and lookup shouldn't be modular.
We definitely don't want such modular code.

Removing ->owner will also make PDE smaller.

So, let's nuke it.

Kudos to Jeff Layton for reminding about this, let's say, oversight.

http://bugzilla.kernel.org/show_bug.cgi?id=12454



Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
parent 3dec7f59
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -117,9 +117,6 @@ static int __init init_procfs_example(void)
		rv = -ENOMEM;
		goto out;
	}
	
	example_dir->owner = THIS_MODULE;
	
	/* create jiffies using convenience function */
	jiffies_file = create_proc_read_entry("jiffies", 
					      0444, example_dir, 
@@ -130,8 +127,6 @@ static int __init init_procfs_example(void)
		goto no_jiffies;
	}

	jiffies_file->owner = THIS_MODULE;

	/* create foo and bar files using same callback
	 * functions 
	 */
@@ -146,7 +141,6 @@ static int __init init_procfs_example(void)
	foo_file->data = &foo_data;
	foo_file->read_proc = proc_read_foobar;
	foo_file->write_proc = proc_write_foobar;
	foo_file->owner = THIS_MODULE;
		
	bar_file = create_proc_entry("bar", 0644, example_dir);
	if(bar_file == NULL) {
@@ -159,7 +153,6 @@ static int __init init_procfs_example(void)
	bar_file->data = &bar_data;
	bar_file->read_proc = proc_read_foobar;
	bar_file->write_proc = proc_write_foobar;
	bar_file->owner = THIS_MODULE;
		
	/* create symlink */
	symlink = proc_symlink("jiffies_too", example_dir, 
@@ -169,8 +162,6 @@ static int __init init_procfs_example(void)
		goto no_symlink;
	}

	symlink->owner = THIS_MODULE;

	/* everything OK */
	printk(KERN_INFO "%s %s initialised\n",
	       MODULE_NAME, MODULE_VERS);
+0 −5
Original line number Diff line number Diff line
@@ -218,7 +218,6 @@ srm_env_init(void)
				BASE_DIR);
		goto cleanup;
	}
	base_dir->owner = THIS_MODULE;

	/*
	 * Create per-name subdirectory
@@ -229,7 +228,6 @@ srm_env_init(void)
				BASE_DIR, NAMED_DIR);
		goto cleanup;
	}
	named_dir->owner = THIS_MODULE;

	/*
	 * Create per-number subdirectory
@@ -241,7 +239,6 @@ srm_env_init(void)
		goto cleanup;

	}
	numbered_dir->owner = THIS_MODULE;

	/*
	 * Create all named nodes
@@ -254,7 +251,6 @@ srm_env_init(void)
			goto cleanup;

		entry->proc_entry->data		= (void *) entry;
		entry->proc_entry->owner	= THIS_MODULE;
		entry->proc_entry->read_proc	= srm_env_read;
		entry->proc_entry->write_proc	= srm_env_write;

@@ -275,7 +271,6 @@ srm_env_init(void)

		entry->id			= var_num;
		entry->proc_entry->data		= (void *) entry;
		entry->proc_entry->owner	= THIS_MODULE;
		entry->proc_entry->read_proc	= srm_env_read;
		entry->proc_entry->write_proc	= srm_env_write;
	}
+0 −1
Original line number Diff line number Diff line
@@ -854,7 +854,6 @@ static int __init sram_proc_init(void)
		printk(KERN_WARNING "unable to create /proc/sram\n");
		return -1;
	}
	ptr->owner = THIS_MODULE;
	ptr->read_proc = sram_proc_read;
	return 0;
}
+0 −2
Original line number Diff line number Diff line
@@ -1002,8 +1002,6 @@ create_palinfo_proc_entries(unsigned int cpu)
		*pdir = create_proc_read_entry(
				palinfo_entries[j].name, 0, cpu_dir,
				palinfo_read_entry, (void *)f.value);
		if (*pdir)
			(*pdir)->owner = THIS_MODULE;
		pdir++;
	}
}
+2 −7
Original line number Diff line number Diff line
@@ -225,7 +225,6 @@ static struct proc_dir_entry *sgi_prominfo_entry;
int __init prominfo_init(void)
{
	struct proc_dir_entry **entp;
	struct proc_dir_entry *p;
	cnodeid_t cnodeid;
	unsigned long nasid;
	int size;
@@ -246,14 +245,10 @@ int __init prominfo_init(void)
		sprintf(name, "node%d", cnodeid);
		*entp = proc_mkdir(name, sgi_prominfo_entry);
		nasid = cnodeid_to_nasid(cnodeid);
		p = create_proc_read_entry("fit", 0, *entp, read_fit_entry,
		create_proc_read_entry("fit", 0, *entp, read_fit_entry,
					   (void *)nasid);
		if (p)
			p->owner = THIS_MODULE;
		p = create_proc_read_entry("version", 0, *entp,
		create_proc_read_entry("version", 0, *entp,
					   read_version_entry, (void *)nasid);
		if (p)
			p->owner = THIS_MODULE;
		entp++;
	}

Loading