Alexey Dobriyan 2d3a4e3666 proc: fix ->open'less usage due to ->proc_fops flip
Typical PDE creation code looks like:

	pde = create_proc_entry("foo", 0, NULL);
	if (pde)
		pde->proc_fops = &foo_proc_fops;

Notice that PDE is first created, only then ->proc_fops is set up to
final value. This is a problem because right after creation
a) PDE is fully visible in /proc , and
b) ->proc_fops are proc_file_operations which do not have ->open callback. So, it's
   possible to ->read without ->open (see one class of oopses below).

The fix is new API called proc_create() which makes sure ->proc_fops are
set up before gluing PDE to main tree. Typical new code looks like:

	pde = proc_create("foo", 0, NULL, &foo_proc_fops);
	if (!pde)
		return -ENOMEM;

Fix most networking users for a start.

In the long run, create_proc_entry() for regular files will go.

BUG: unable to handle kernel NULL pointer dereference at virtual address 00000024
printing eip: c1188c1b *pdpt = 000000002929e001 *pde = 0000000000000000
Oops: 0002 [#1] PREEMPT SMP DEBUG_PAGEALLOC
last sysfs file: /sys/block/sda/sda1/dev
Modules linked in: foo af_packet ipv6 cpufreq_ondemand loop serio_raw psmouse k8temp hwmon sr_mod cdrom

Pid: 24679, comm: cat Not tainted (2.6.24-rc3-mm1 #2)
EIP: 0060:[<c1188c1b>] EFLAGS: 00210002 CPU: 0
EIP is at mutex_lock_nested+0x75/0x25d
EAX: 000006fe EBX: fffffffb ECX: 00001000 EDX: e9340570
ESI: 00000020 EDI: 00200246 EBP: e9340570 ESP: e8ea1ef8
 DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
Process cat (pid: 24679, ti=E8EA1000 task=E9340570 task.ti=E8EA1000)
Stack: 00000000 c106f7ce e8ee05b4 00000000 00000001 458003d0 f6fb6f20 fffffffb
       00000000 c106f7aa 00001000 c106f7ce 08ae9000 f6db53f0 00000020 00200246
       00000000 00000002 00000000 00200246 00200246 e8ee05a0 fffffffb e8ee0550
Call Trace:
 [<c106f7ce>] seq_read+0x24/0x28a
 [<c106f7aa>] seq_read+0x0/0x28a
 [<c106f7ce>] seq_read+0x24/0x28a
 [<c106f7aa>] seq_read+0x0/0x28a
 [<c10818b8>] proc_reg_read+0x60/0x73
 [<c1081858>] proc_reg_read+0x0/0x73
 [<c105a34f>] vfs_read+0x6c/0x8b
 [<c105a6f3>] sys_read+0x3c/0x63
 [<c10025f2>] sysenter_past_esp+0x5f/0xa5
 [<c10697a7>] destroy_inode+0x24/0x33
 =======================
INFO: lockdep is turned off.
Code: 75 21 68 e1 1a 19 c1 68 87 00 00 00 68 b8 e8 1f c1 68 25 73 1f c1 e8 84 06 e9 ff e8 52 b8 e7 ff 83 c4 10 9c 5f fa e8 28 89 ea ff <f0> fe 4e 04 79 0a f3 90 80 7e 04 00 7e f8 eb f0 39 76 34 74 33
EIP: [<c1188c1b>] mutex_lock_nested+0x75/0x25d SS:ESP 0068:e8ea1ef8

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Alexey Dobriyan <adobriyan@sw.ru>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-02-08 09:22:24 -08:00
..
2008-01-28 14:54:13 -08:00
2008-02-06 10:41:15 -08:00
2008-02-07 08:42:23 -08:00
2007-10-14 20:17:39 -07:00
2008-02-05 09:44:13 -08:00
2007-12-26 19:36:35 -08:00
2008-02-05 03:20:13 -08:00
2008-02-07 08:42:30 -08:00
2008-02-06 10:41:02 -08:00
2007-10-18 14:37:20 -07:00
2007-10-10 16:51:59 -07:00
2008-01-23 05:24:15 -05:00
2008-01-28 15:00:14 -08:00
2007-10-17 08:42:45 -07:00
2007-10-17 08:43:07 -07:00
2007-10-18 14:37:29 -07:00
2007-10-19 11:53:42 -07:00
2007-10-19 11:53:42 -07:00
2008-02-01 11:34:49 +01:00
2008-01-29 21:55:15 +01:00
2008-01-28 14:54:10 -08:00
2007-10-19 11:53:36 -07:00
2008-02-03 17:45:46 +02:00
2008-01-28 23:21:18 +01:00
2008-01-28 23:21:18 +01:00
2008-01-28 23:21:18 +01:00
2007-12-06 17:40:19 -05:00
2007-10-17 08:42:52 -07:00
2008-01-25 21:08:02 +01:00
2008-01-30 13:31:10 +01:00
2008-02-03 17:45:46 +02:00
2008-02-03 15:42:53 +02:00
2007-10-16 09:43:09 -07:00
2007-10-21 02:37:45 -04:00
2007-10-19 11:53:36 -07:00
2008-02-08 02:09:56 +00:00
2008-02-07 20:39:40 -05:00
2007-10-22 08:13:19 -07:00
2007-10-17 08:42:51 -07:00
2008-02-07 08:42:30 -08:00
2008-01-28 23:21:18 +01:00
2008-02-03 17:45:46 +02:00
2007-10-29 07:41:32 -07:00
2007-10-22 08:13:21 -07:00
2007-10-17 08:43:02 -07:00
2007-10-17 08:42:48 -07:00
2007-10-17 08:43:01 -07:00
2007-11-29 09:24:54 -08:00
2008-01-25 21:08:33 +01:00
2008-02-03 15:42:53 +02:00
2008-01-28 14:51:22 +01:00
2008-02-05 09:44:19 -08:00
2008-01-30 13:30:27 +01:00
2008-02-07 20:39:44 -05:00
2008-01-27 18:14:52 +01:00
2007-10-16 11:21:00 +02:00
2007-10-22 00:56:52 -04:00
2008-02-06 02:57:51 +01:00
2008-02-01 16:13:16 -05:00
2007-10-10 16:51:59 -07:00
2008-01-28 15:08:27 -08:00
2007-10-17 08:42:52 -07:00
2008-01-28 15:07:58 -08:00
2007-10-10 16:52:04 -07:00
2008-01-28 15:07:57 -08:00
2008-01-28 14:55:09 -08:00
2008-01-28 14:55:09 -08:00
2007-12-05 05:37:32 -08:00
2008-02-06 22:39:45 +01:00
2008-02-06 10:41:02 -08:00
2007-10-18 14:37:32 -07:00
2008-01-31 19:28:20 -08:00
2008-01-28 23:58:27 -05:00
2008-02-06 10:41:21 -08:00
2007-11-05 15:12:32 -08:00
2007-10-17 08:42:52 -07:00
2008-02-07 08:42:30 -08:00
2007-11-29 09:24:52 -08:00
2008-01-08 16:10:35 -08:00
2008-01-24 20:40:05 -08:00
2008-01-25 21:08:34 +01:00
2007-10-25 15:02:50 +10:00
2008-01-30 13:33:13 +01:00
2008-02-03 17:45:46 +02:00
2008-02-06 10:41:01 -08:00
2007-10-19 11:53:55 -07:00
2007-10-10 16:54:03 -07:00
2008-02-05 09:44:16 -08:00
2008-01-28 23:21:18 +01:00
2007-10-19 11:53:44 -07:00
2007-12-06 17:37:59 -05:00
2008-01-28 14:56:29 -08:00
2008-01-28 14:54:18 -08:00
2008-01-30 02:06:08 -05:00
2007-10-17 08:42:58 -07:00
2008-02-06 16:29:59 +11:00
2008-02-05 09:44:19 -08:00
2007-10-16 09:43:02 -07:00
2007-12-06 17:35:41 -05:00
2008-02-02 11:32:01 -08:00
2008-02-02 02:44:34 +03:00
2007-10-17 08:42:44 -07:00
2007-10-19 11:53:41 -07:00
2008-02-03 17:45:46 +02:00
2008-02-06 10:41:20 -08:00
2007-10-19 11:53:41 -07:00
2007-10-17 08:42:45 -07:00
2008-02-06 10:41:07 -08:00
2007-10-17 08:42:56 -07:00
2008-01-25 21:08:24 +01:00
2008-01-25 21:08:24 +01:00
2008-01-25 21:08:24 +01:00
2008-02-05 09:44:22 -08:00
2008-01-30 13:31:47 +01:00
2007-10-22 08:13:20 -07:00
2008-01-31 19:26:46 -08:00
2007-11-29 09:24:54 -08:00
2008-02-07 08:42:18 -08:00
2007-10-16 09:43:17 -07:00
2007-10-19 11:53:44 -07:00
2008-02-07 08:42:34 -08:00
2007-11-29 09:24:53 -08:00
2008-02-07 08:42:30 -08:00
2008-02-06 10:41:02 -08:00
2008-01-02 13:04:48 -08:00
2008-01-02 13:04:48 -08:00
2008-02-03 17:45:46 +02:00
2008-01-25 21:08:33 +01:00
2008-01-31 19:28:30 -08:00
2008-01-24 00:47:27 -05:00
2008-01-30 13:31:20 +01:00
2008-01-30 13:31:20 +01:00
2008-01-30 13:31:20 +01:00
2008-01-25 21:08:34 +01:00
2008-02-07 08:42:34 -08:00
2008-02-05 09:44:16 -08:00
2008-02-05 09:44:07 -08:00
2008-02-01 23:20:26 -05:00
2008-02-01 17:45:14 +01:00
2008-02-06 10:41:02 -08:00
2008-02-07 08:42:16 -08:00
2008-01-24 20:40:26 -08:00
2007-12-26 19:36:35 -08:00
2007-10-23 13:47:31 -05:00
2008-02-04 23:50:13 +11:00
2008-02-04 23:50:03 +11:00
2007-10-23 15:49:55 +10:00
2008-02-04 23:50:02 +11:00
2008-02-04 23:50:03 +11:00
2008-02-06 10:41:03 -08:00
2007-10-19 11:53:34 -07:00
2008-02-05 09:44:07 -08:00
2008-02-03 15:42:53 +02:00