drm: fix crash due to /proc registration race
PATCH 1/1 drm: fix crash due to /proc registration race
From: Arjan van de Ven <[email protected]>
Subject: [PATCH] drm: fix crash due to /proc registration race
The DRM layer creates proc entries like this:
ent = create_proc_entry(drm_proc_list[i].name,
S_IFREG | S_IRUGO, minor->dev_root);
if (!ent) {
... stuff ...
}
ent->read_proc = drm_proc_list[i].f;
ent->data = minor;however that leaves a short window where the /proc file is visible, but where ->data is not initialized yet.
It appears that this race is actually hit in practice:
http://www.kerneloops.org/search.php?search=drm_name_info
(of course it could be some other race.. but this race appears to be there at least)
--- drivers/char/drm/drm_proc.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-)
drivers/char/drm/drm_proc.c +12 -1
@@ -164,9 +164,20 @@ static int drm_name_info(char *buf, char **start, off_t offset, int request, int *eof, void *data) { struct drm_minor *minor = (struct drm_minor *) data; -struct drm_device *dev = minor->dev; +struct drm_device *dev;int len =0 ; +/* +* When creating the /proc files, there is a tiny race window +* where "data" isn't assigned yet... error out rather than dereference +*/ +if (!data) { + *eof =1 ; +return 0 ; + } + + dev = minor->dev; +if (offset >DRM_PROC_LIMIT ) { *eof =1 ;return 0 ;
Signature · 7 lines
1.5.5.1 -- If you want to reach me at my work email, use [email protected] For development, discussion and tips for power savings, visit http://www.lesswatts.org
PATCH 1/1 drm: make drm use create_proc_read_entry() instead
From: Arjan van de Ven <[email protected]>
Subject: [PATCH] drm: make drm use create_proc_read_entry() instead
Al Viro points out that DRM should have used create_proc_read_entry(), and although that is still racey right now, it at least has a chance of getting fixed on the api level.
--- drivers/char/drm/drm_proc.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
drivers/char/drm/drm_proc.c +3 -4
@@ -102,8 +102,9 @@ int drm_proc_init(struct drm_minor *minor, int minor_id, }for (i =0 ; i <DRM_PROC_ENTRIES ; i++) { - ent =create_proc_entry (drm_proc_list[i].name, -S_IFREG |S_IRUGO , minor->dev_root); + ent =create_proc_read_entry (drm_proc_list[i].name, +S_IFREG |S_IRUGO , minor->dev_root, + drm_proc_list[i].f, minor);if (!ent) {DRM_ERROR ("Cannot create /proc/dri/%s/%s\n" , name, drm_proc_list[i].name);
@@ -114,8 +115,6 @@ int drm_proc_init(struct drm_minor *minor, int minor_id, minor->dev_root =NULL ;return -1 ; } - ent->read_proc = drm_proc_list[i].f; - ent->data = minor; }return 0 ;
Signature · 1 line
1.5.5.1
Re: [PATCH] drm: make drm use create_proc_read_entry() instead
Quoted 5 lines · Arjan van de Ven
Subject: [PATCH] drm: make drm use
create_proc_read_entry()insteadAl Viro points out that DRM should have used
create_proc_read_entry(), and although that is still racey right now, it at least has a chance of getting fixed on the api level.
Fix on API level is proc_create_data(), so this patch is pointless.
Quoted 21 lines
drivers/char/drm/drm_proc.c +3
-4@@ -102,8 +102,9 @@ int drm_proc_init(struct drm_minor *minor, int minor_id, }for (i =0 ; i <DRM_PROC_ENTRIES ; i++) { - ent =create_proc_entry (drm_proc_list[i].name, -S_IFREG |S_IRUGO , minor->dev_root); + ent =create_proc_read_entry (drm_proc_list[i].name, +S_IFREG |S_IRUGO , minor->dev_root, + drm_proc_list[i].f, minor);if (!ent) {DRM_ERROR ("Cannot create /proc/dri/%s/%s\n" , name, drm_proc_list[i].name);@@ -114,8 +115,6 @@ int drm_proc_init(struct drm_minor *minor, int minor_id, minor->dev_root =NULL ;return -1 ; } - ent->read_proc = drm_proc_list[i].f; - ent->data = minor; }
Re: [PATCH] drm: make drm use create_proc_read_entry() instead
Quoted 8 lines · Alexey Dobriyan
Quoted 5 lines · Arjan van de Ven
Subject: [PATCH] drm: make drm use
create_proc_read_entry()insteadAl Viro points out that DRM should have used
create_proc_read_entry(), and although that is still racey right now, it at least has a chance of getting fixed on the api level.Fix on API level is
proc_create_data(), so this patch is pointless.
Yeah... OTOH, it might make sense to reorder assignments in the create_proc_read_entry() and slap the barrier in there - it would close at least some of the holes until we get around to proper proc_create_data() conversions and remove the ->read_proc() crap...
PATCH 1/1 drm: switch to seq_files
Quoted 8 lines · Al Viro
Quoted 7 lines · Alexey Dobriyan
Quoted 5 lines · Arjan van de Ven
Subject: [PATCH] drm: make drm use
create_proc_read_entry()insteadAl Viro points out that DRM should have used
create_proc_read_entry(), and although that is still racey right now, it at least has a chance of getting fixed on the api level.
Quoted 6 lines
Quoted 1 line
Fix on API level is
proc_create_data(), so this patch is pointless.Yeah... OTOH, it might make sense to reorder assignments in the
create_proc_read_entry()and slap the barrier in there - it would close at least some of the holes until we get around to properproc_create_data()conversions and remove the ->read_proc() crap...
Hmm, I already have drm conversion patch.
Could someone please test it, there are nvidias here...
[PATCH] drm: convert to seq_files
Switch to proc_create_data() while I'm at it, it fixes "->data is NULL"
race: http://www.kerneloops.org/search.php?search=drm_name_info
---
drivers/char/drm/drmP.h | 11 - drivers/char/drm/drm_memory.c | 13 - drivers/char/drm/drm_memory_debug.h | 23 -- drivers/char/drm/drm_proc.c | 311 ++++++++++++++++-------------------- 4 files changed, 151 insertions(+), 207 deletions(-)
drivers/char/drm/drmP.h +3 -8
@@ -49,6 +49,7 @@#include <linux/miscdevice.h> #include <linux/fs.h> #include <linux/proc_fs.h> +#include <linux/seq_file.h> #include <linux/init.h> #include <linux/file.h> #include <linux/pci.h>
@@ -198,12 +199,7 @@ struct drm_device;#define DRM_PROC_LIMIT (PAGE_SIZE-80) #define DRM_PROC_PRINT(fmt, arg...) \ - len += sprintf(&buf[len], fmt , ##arg); \ - if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; } - -#define DRM_PROC_PRINT_RET(ret, fmt, arg...) \ - len += sprintf(&buf[len], fmt , ##arg); \ - if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; } + seq_printf(m, fmt , ##arg); \/*@}*/
@@ -860,8 +856,7 @@ extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);/* Memory management support (drm_memory.h) */ #include "drm_memory.h" extern void drm_mem_init (void ); -extern int drm_mem_info (char *buf,char **start,off_t offset, -int request,int *eof,void *data); +extern int drm_mem_proc_show (struct seq_file *m,void *v);extern void *drm_realloc (void *oldpt,size_t oldsize,size_t size,int area);extern DRM_AGP_MEM *drm_alloc_agp (struct drm_device *dev,int pages,u32 type);
drivers/char/drm/drm_memory.c +1 -12
@@ -47,19 +47,8 @@ void drm_mem_init(void)/** * Called when "/proc/dri/%dev%/mem" is read. -* -* \param buf output buffer. -* \param start start of output data. -* \param offset requested start offset. -* \param len requested number of bytes. -* \param eof whether there is no more data to return. -* \param data private data. -* \return number of written bytes. -* -* No-op. */ -int drm_mem_info (char *buf,char **start,off_t offset, -int len,int *eof,void *data) +int drm_mem_proc_show (struct seq_file *m,void *v) {return 0 ; }
drivers/char/drm/drm_memory_debug.h +4 -19
@@ -91,18 +91,8 @@ void drm_mem_init (void) {/* drm_mem_info is called whenever a process reads /dev/drm/mem. */ -static int drm__mem_info (char *buf,char **start,off_t offset, -int request,int *eof,void *data) { +static int drm__mem_info (struct seq_file *m) {drm_mem_stats_t *pt; -int len =0 ; - -if (offset >DRM_PROC_LIMIT ) { - *eof =1 ; -return 0 ; - } - - *eof =0 ; - *start = &buf[offset];DRM_PROC_PRINT (" total counts " " | outstanding \n" );
@@ -126,19 +116,14 @@ static int drm__mem_info (char *buf, char **start, off_t offset, (long )pt->bytes_allocated - (long)pt->bytes_freed); } - -if (len > request + offset) -return request; - *eof =1 ; -return len - offset; +return 0 ; } -int drm_mem_info (char *buf,char **start,off_t offset, -int len,int *eof,void *data) { +int drm_mem_proc_show (struct seq_file *m,void *v) {int ret;spin_lock (&drm_mem_lock); - ret =drm__mem_info (buf, start, offset, len, eof, data); + ret =drm__mem_info (m);spin_unlock (&drm_mem_lock);return ret; }
drivers/char/drm/drm_proc.c +143 -168
503 lines not on this page · raw message