The patch titled proc: introduce proc_create_data to setup de->data has been added to the -mm tree. Its filename is proc-introduce-proc_create_data-to-setup-de-data.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/ ------------------------------------------------------ Subject: proc: introduce proc_create_data to setup de->data From: "Denis V. Lunev" <den@xxxxxxxxxx> This set of patches fixes an proc ->open'less usage due to ->proc_fops flip in the most part of the kernel code. The original OOPS is described in the commit 2d3a4e3666325a9709cc8ea2e88151394e8f20fc: 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. In addition to this, proc_create_data is introduced to fix reading from proc without PDE->data. The race is basically the same as above. create_proc_entries is replaced in the entire kernel code as new method is also simply better. This patch: The problem is the same as for de->proc_fops. Right now PDE becomes visible without data set. So, the entry could be looked up without data. This, in most cases, will simply OOPS. proc_create_data call is created to address this issue. proc_create now becomes a wrapper around it. Signed-off-by: Denis V. Lunev <den@xxxxxxxxxx> Cc: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx> Cc: "J. Bruce Fields" <bfields@xxxxxxxxxxxx> Cc: Alessandro Zummo <a.zummo@xxxxxxxxxxxx> Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx> Cc: Bartlomiej Zolnierkiewicz <bzolnier@xxxxxxxxx> Cc: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx> Cc: Bjorn Helgaas <bjorn.helgaas@xxxxxx> Cc: Chris Mason <chris.mason@xxxxxxxxxx> Cc: David Howells <dhowells@xxxxxxxxxx> Cc: Dmitry Torokhov <dtor@xxxxxxx> Cc: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx> Cc: Grant Grundler <grundler@xxxxxxxxxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxx> Cc: Haavard Skinnemoen <hskinnemoen@xxxxxxxxx> Cc: Heiko Carstens <heiko.carstens@xxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxx> Cc: James Bottomley <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx> Cc: Jaroslav Kysela <perex@xxxxxxx> Cc: Jeff Garzik <jgarzik@xxxxxxxxx> Cc: Jeff Mahoney <jeffm@xxxxxxxx> Cc: Jesper Nilsson <jesper.nilsson@xxxxxxxx> Cc: Karsten Keil <kkeil@xxxxxxx> Cc: Kyle McMartin <kyle@xxxxxxxxxxxxxxxx> Cc: Len Brown <lenb@xxxxxxxxxx> Cc: Martin Schwidefsky <schwidefsky@xxxxxxxxxx> Cc: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxx> Cc: Matthew Wilcox <matthew@xxxxxx> Cc: Mauro Carvalho Chehab <mchehab@xxxxxxxxxxxxx> Cc: Mikael Starvik <starvik@xxxxxxxx> Cc: Nadia Derbey <Nadia.Derbey@xxxxxxxx> Cc: Neil Brown <neilb@xxxxxxx> Cc: Paul Mackerras <paulus@xxxxxxxxx> Cc: Peter Osterlund <petero2@xxxxxxxxx> Cc: Pierre Peiffer <peifferp@xxxxxxxxx> Cc: Russell King <rmk@xxxxxxxxxxxxxxxx> Cc: Takashi Iwai <tiwai@xxxxxxx> Cc: Tony Luck <tony.luck@xxxxxxxxx> Cc: Trond Myklebust <trond.myklebust@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/proc/generic.c | 8 +++++--- fs/proc/root.c | 2 +- include/linux/proc_fs.h | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff -puN fs/proc/generic.c~proc-introduce-proc_create_data-to-setup-de-data fs/proc/generic.c --- a/fs/proc/generic.c~proc-introduce-proc_create_data-to-setup-de-data +++ a/fs/proc/generic.c @@ -675,9 +675,10 @@ struct proc_dir_entry *create_proc_entry return ent; } -struct proc_dir_entry *proc_create(const char *name, mode_t mode, - struct proc_dir_entry *parent, - const struct file_operations *proc_fops) +struct proc_dir_entry *proc_create_data(const char *name, mode_t mode, + struct proc_dir_entry *parent, + const struct file_operations *proc_fops, + void *data) { struct proc_dir_entry *pde; nlink_t nlink; @@ -698,6 +699,7 @@ struct proc_dir_entry *proc_create(const if (!pde) goto out; pde->proc_fops = proc_fops; + pde->data = data; if (proc_register(parent, pde) < 0) goto out_free; return pde; diff -puN fs/proc/root.c~proc-introduce-proc_create_data-to-setup-de-data fs/proc/root.c --- a/fs/proc/root.c~proc-introduce-proc_create_data-to-setup-de-data +++ a/fs/proc/root.c @@ -230,5 +230,5 @@ void pid_ns_release_proc(struct pid_name EXPORT_SYMBOL(proc_symlink); EXPORT_SYMBOL(proc_mkdir); EXPORT_SYMBOL(create_proc_entry); -EXPORT_SYMBOL(proc_create); +EXPORT_SYMBOL(proc_create_data); EXPORT_SYMBOL(remove_proc_entry); diff -puN include/linux/proc_fs.h~proc-introduce-proc_create_data-to-setup-de-data include/linux/proc_fs.h --- a/include/linux/proc_fs.h~proc-introduce-proc_create_data-to-setup-de-data +++ a/include/linux/proc_fs.h @@ -116,9 +116,10 @@ void de_put(struct proc_dir_entry *de); extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode, struct proc_dir_entry *parent); -struct proc_dir_entry *proc_create(const char *name, mode_t mode, +struct proc_dir_entry *proc_create_data(const char *name, mode_t mode, struct proc_dir_entry *parent, - const struct file_operations *proc_fops); + const struct file_operations *proc_fops, + void *data); extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent); extern struct vfsmount *proc_mnt; @@ -173,6 +174,12 @@ extern struct proc_dir_entry *proc_mkdir extern struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode, struct proc_dir_entry *parent); +static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode, + struct proc_dir_entry *parent, const struct file_operations *proc_fops) +{ + return proc_create_data(name, mode, parent, proc_fops, NULL); +} + static inline struct proc_dir_entry *create_proc_read_entry(const char *name, mode_t mode, struct proc_dir_entry *base, read_proc_t *read_proc, void * data) @@ -214,6 +221,12 @@ static inline struct proc_dir_entry *pro { return NULL; } +static inline struct proc_dir_entry *proc_create_data(const char *name, + mode_t mode, struct proc_dir_entry *parent, + const struct file_operations *proc_fops, void *data) +{ + return NULL; +} #define remove_proc_entry(name, parent) do {} while (0) static inline struct proc_dir_entry *proc_symlink(const char *name, _ Patches currently in -mm which might be from den@xxxxxxxxxx are git-net.patch proc-introduce-proc_create_data-to-setup-de-data.patch nfsd-use-proc_create-to-setup-de-proc_fops.patch nfs-use-proc_create-to-setup-de-proc_fops.patch afs-use-non-racy-method-for-proc-entries-creation.patch ext4-use-non-racy-method-for-proc-entries-creation.patch reiserfs-use-non-racy-method-for-proc-entries-creation.patch jbd2-use-non-racy-method-for-proc-entries-creation.patch sysvipc-use-non-racy-method-for-proc-entries-creation.patch mm-use-non-racy-method-for-proc-swaps-creation.patch sound-use-non-racy-method-for-proc-driver-snd-page-alloc-creation.patch zorro-use-non-racy-method-for-proc-entries-creation.patch samples-use-non-racy-method-for-proc-marker-example-creation.patch scsi-use-non-racy-method-for-proc-entries-creation.patch usb-use-non-racy-method-for-proc-entries-creation.patch s390-use-non-racy-method-for-proc-entries-creation.patch arm-use-non-racy-method-for-proc-davinci_clocks-creation.patch avr32-proc-use-non-racy-method-for-proc-tlb-creation.patch cris-use-non-racy-method-for-proc-system_profile-creation.patch ia64-use-non-racy-method-for-proc-entries-creation.patch parisc-use-non-racy-method-for-proc-pcxl_dma-creation.patch powerpc-use-non-racy-method-for-proc-entries-creation.patch acpi-use-non-racy-method-for-proc-entries-creation.patch netdev-use-non-racy-method-for-proc-entries-creation.patch isdn-use-non-racy-method-for-proc-entries-creation.patch kernel-use-non-racy-method-for-proc-entries-creation.patch parisc-use-non-racy-method-for-proc-entries-creation.patch drivers-use-non-racy-method-for-proc-entries-creation.patch drivers-use-non-racy-method-for-proc-entries-creation-2.patch sysctl-merge-equal-proc_sys_read-and-proc_sys_write.patch sysctl-clean-from-unneeded-extern-and-forward-declarations.patch sysctl-add-the-permissions-callback-on-the-ctl_table_root.patch proc-use-non-racy-method-for-proc-page_owner-creation-page_owner.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html