Vulnerability: drivers/media/video/videobuf-vmalloc.c in the Linux kernel before 2.6.24 does not initialize videobuf_mapping data structures, which allows local users to trigger an incorrect count value and videobuf leak via unspecified vectors, a different vulnerability than CVE-2010-5321.
Vulnerability ID: CVE-2007-6761
CWE: CWE-119
Severity score: 6.4
Project: https://github.com/torvalds/linux
Published: 2017-04-24
File: drivers/media/video/videobuf-vmalloc.c
Commit message: V4L/DVB (6751): V4L: Memory leak!  Fix count in videobuf-vmalloc mmap

This is pretty serious bug.  map->count is never initialized after the
call to kmalloc making the count start at some random trash value.  The
end result is leaking videobufs.

Also, fix up the debug statements to print unsigned values.

Pushed to http://ifup.org/hg/v4l-dvb too

Signed-off-by: Brandon Philips <bphilips@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Commit author: Brandon Philips

Vulnerable version (before fix):
 videobuf_vm_open(struct vm_area_struct *vma) { 	struct videobuf_mapping *map = vma->vm_private_data;  	dprintk(2,"vm_open %p [count=%d,vma=%08lx-%08lx]\n",map, 		map->count,vma->vm_start,vma->vm_end);  	map->count++; videobuf_vm_close(struct vm_area_struct *vma) 	struct videobuf_queue *q = map->q; 	int i;  	dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map, 		map->count,vma->vm_start,vma->vm_end);  	map->count--; static int __videobuf_mmap_mapper(struct videobuf_queue *q, 	}  	/* create mapping + update buffer list */ 	map = q->bufs[first]->map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL); 	if (NULL == map) 		return -ENOMEM; 

Fixed version (after fix):
 videobuf_vm_open(struct vm_area_struct *vma) { 	struct videobuf_mapping *map = vma->vm_private_data;  	dprintk(2,"vm_open %p [count=%u,vma=%08lx-%08lx]\n",map, 		map->count,vma->vm_start,vma->vm_end);  	map->count++; videobuf_vm_close(struct vm_area_struct *vma) 	struct videobuf_queue *q = map->q; 	int i;  	dprintk(2,"vm_close %p [count=%u,vma=%08lx-%08lx]\n",map, 		map->count,vma->vm_start,vma->vm_end);  	map->count--; static int __videobuf_mmap_mapper(struct videobuf_queue *q, 	}  	/* create mapping + update buffer list */ 	map = q->bufs[first]->map = kzalloc(sizeof(struct videobuf_mapping),GFP_KERNEL); 	if (NULL == map) 		return -ENOMEM; 

Patch:
patch: @@ -51,7 +51,7 @@ videobuf_vm_open(struct vm_area_struct *vma)
 {
 	struct videobuf_mapping *map = vma->vm_private_data;
 
-	dprintk(2,"vm_open %p [count=%d,vma=%08lx-%08lx]\n",map,
+	dprintk(2,"vm_open %p [count=%u,vma=%08lx-%08lx]\n",map,
 		map->count,vma->vm_start,vma->vm_end);
 
 	map->count++;
@@ -64,7 +64,7 @@ videobuf_vm_close(struct vm_area_struct *vma)
 	struct videobuf_queue *q = map->q;
 	int i;
 
-	dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map,
+	dprintk(2,"vm_close %p [count=%u,vma=%08lx-%08lx]\n",map,
 		map->count,vma->vm_start,vma->vm_end);
 
 	map->count--;
@@ -221,7 +221,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
 	}
 
 	/* create mapping + update buffer list */
-	map = q->bufs[first]->map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
+	map = q->bufs[first]->map = kzalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
 	if (NULL == map)
 		return -ENOMEM;
path: drivers/media/video/videobuf-vmalloc.c