remarkable-linux/include
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
..
acpi Merge branches 'release' and 'fluff' into release 2008-02-07 03:38:22 -05:00
asm-alpha Add cmpxchg64 and cmpxchg64_local to alpha 2008-02-07 08:42:30 -08:00
asm-arm Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input 2008-02-07 12:57:44 -08:00
asm-avr32 Add cmpxchg_local to avr32 2008-02-07 08:42:31 -08:00
asm-blackfin Add cmpxchg_local to blackfin, replace __cmpxchg by generic cmpxchg 2008-02-07 08:42:31 -08:00
asm-cris Add cmpxchg_local to cris 2008-02-07 08:42:31 -08:00
asm-frv Add cmpxchg_local to frv 2008-02-07 08:42:32 -08:00
asm-generic Add cmpxchg_local to asm-generic for per cpu atomic operations 2008-02-07 08:42:30 -08:00
asm-h8300 Add cmpxchg_local to h8300 2008-02-07 08:42:32 -08:00
asm-ia64 Add cmpxchg_local, cmpxchg64 and cmpxchg64_local to ia64 2008-02-07 08:42:32 -08:00
asm-m32r local_t m32r use architecture specific cmpxchg_local 2008-02-07 08:42:32 -08:00
asm-m68k m68k: kill page walker compile warning 2008-02-07 09:10:06 -08:00
asm-m68knommu Add cmpxchg_local to m68knommu 2008-02-07 08:42:32 -08:00
asm-mips Add cmpxchg64 and cmpxchg64_local to mips 2008-02-07 08:42:30 -08:00
asm-parisc Add cmpxchg_local to parisc 2008-02-07 08:42:32 -08:00
asm-powerpc Merge branch 'for-2.6.25' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc 2008-02-07 09:02:26 -08:00
asm-ppc Add cmpxchg_local to ppc 2008-02-07 08:42:32 -08:00
asm-s390 proc: seqfile convert proc_pid_status to properly handle pid namespaces 2008-02-08 09:22:24 -08:00
asm-sh Sanitize the type of struct user.u_ar0 2008-02-07 08:42:30 -08:00
asm-sparc Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6 2008-02-07 10:21:26 -08:00
asm-sparc64 Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6 2008-02-07 10:21:26 -08:00
asm-um
asm-v850 Add cmpxchg_local to v850 2008-02-07 08:42:33 -08:00
asm-x86 Add cmpxchg64 and cmpxchg64_local to x86_64 2008-02-07 08:42:31 -08:00
asm-xtensa Add cmpxchg_local to xtensa 2008-02-07 08:42:33 -08:00
crypto
keys
linux proc: fix ->open'less usage due to ->proc_fops flip 2008-02-08 09:22:24 -08:00
math-emu
media
mtd
net 9p: add support for sticky bit 2008-02-06 19:25:06 -06:00
pcmcia
rdma
rxrpc
scsi [SCSI] Small cleanups for scsi_host.h 2008-02-07 18:02:43 -06:00
sound
video
xen
Kbuild