aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Piggin <npiggin@suse.de>2008-02-01 21:08:53 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-02-04 10:55:38 -0500
commit2f98735c9c24ea1f0d40a364d4e63611b689b795 (patch)
treea42b3802449af474d36cda3b6f9fb190a717defb
parentfe2528b96b02173395f5a75e37714c07f3e25e73 (diff)
vm audit: add VM_DONTEXPAND to mmap for drivers that need it
Drivers that register a ->fault handler, but do not range-check the offset argument, must set VM_DONTEXPAND in the vm_flags in order to prevent an expanding mremap from overflowing the resource. I've audited the tree and attempted to fix these problems (usually by adding VM_DONTEXPAND where it is not obvious). Signed-off-by: Nick Piggin <npiggin@suse.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/char/drm/drm_vm.c2
-rw-r--r--drivers/char/mspec.c2
-rw-r--r--fs/ncpfs/mmap.c4
-rw-r--r--kernel/relay.c1
-rw-r--r--mm/mmap.c2
-rw-r--r--sound/oss/via82cxxx_audio.c14
-rw-r--r--sound/usb/usx2y/usX2Yhwdep.c2
-rw-r--r--sound/usb/usx2y/usx2yhwdeppcm.c2
8 files changed, 13 insertions, 16 deletions
diff --git a/drivers/char/drm/drm_vm.c b/drivers/char/drm/drm_vm.c
index e8d50af58201..ef5e6b130c48 100644
--- a/drivers/char/drm/drm_vm.c
+++ b/drivers/char/drm/drm_vm.c
@@ -506,6 +506,7 @@ static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
506 vma->vm_ops = &drm_vm_dma_ops; 506 vma->vm_ops = &drm_vm_dma_ops;
507 507
508 vma->vm_flags |= VM_RESERVED; /* Don't swap */ 508 vma->vm_flags |= VM_RESERVED; /* Don't swap */
509 vma->vm_flags |= VM_DONTEXPAND;
509 510
510 vma->vm_file = filp; /* Needed for drm_vm_open() */ 511 vma->vm_file = filp; /* Needed for drm_vm_open() */
511 drm_vm_open_locked(vma); 512 drm_vm_open_locked(vma);
@@ -655,6 +656,7 @@ static int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma)
655 return -EINVAL; /* This should never happen. */ 656 return -EINVAL; /* This should never happen. */
656 } 657 }
657 vma->vm_flags |= VM_RESERVED; /* Don't swap */ 658 vma->vm_flags |= VM_RESERVED; /* Don't swap */
659 vma->vm_flags |= VM_DONTEXPAND;
658 660
659 vma->vm_file = filp; /* Needed for drm_vm_open() */ 661 vma->vm_file = filp; /* Needed for drm_vm_open() */
660 drm_vm_open_locked(vma); 662 drm_vm_open_locked(vma);
diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c
index 82f2e27dca7d..ff146c2b08fd 100644
--- a/drivers/char/mspec.c
+++ b/drivers/char/mspec.c
@@ -283,7 +283,7 @@ mspec_mmap(struct file *file, struct vm_area_struct *vma,
283 vdata->refcnt = ATOMIC_INIT(1); 283 vdata->refcnt = ATOMIC_INIT(1);
284 vma->vm_private_data = vdata; 284 vma->vm_private_data = vdata;
285 285
286 vma->vm_flags |= (VM_IO | VM_RESERVED | VM_PFNMAP); 286 vma->vm_flags |= (VM_IO | VM_RESERVED | VM_PFNMAP | VM_DONTEXPAND);
287 if (vdata->type == MSPEC_FETCHOP || vdata->type == MSPEC_UNCACHED) 287 if (vdata->type == MSPEC_FETCHOP || vdata->type == MSPEC_UNCACHED)
288 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 288 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
289 vma->vm_ops = &mspec_vm_ops; 289 vma->vm_ops = &mspec_vm_ops;
diff --git a/fs/ncpfs/mmap.c b/fs/ncpfs/mmap.c
index a94473d3072c..5d8dcb9ee326 100644
--- a/fs/ncpfs/mmap.c
+++ b/fs/ncpfs/mmap.c
@@ -50,10 +50,6 @@ static int ncp_file_mmap_fault(struct vm_area_struct *area,
50 pos = vmf->pgoff << PAGE_SHIFT; 50 pos = vmf->pgoff << PAGE_SHIFT;
51 51
52 count = PAGE_SIZE; 52 count = PAGE_SIZE;
53 if ((unsigned long)vmf->virtual_address + PAGE_SIZE > area->vm_end) {
54 WARN_ON(1); /* shouldn't happen? */
55 count = area->vm_end - (unsigned long)vmf->virtual_address;
56 }
57 /* what we can read in one go */ 53 /* what we can read in one go */
58 bufsize = NCP_SERVER(inode)->buffer_size; 54 bufsize = NCP_SERVER(inode)->buffer_size;
59 55
diff --git a/kernel/relay.c b/kernel/relay.c
index 61134eb7a0c8..7c0373322f18 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -92,6 +92,7 @@ static int relay_mmap_buf(struct rchan_buf *buf, struct vm_area_struct *vma)
92 return -EINVAL; 92 return -EINVAL;
93 93
94 vma->vm_ops = &relay_file_mmap_ops; 94 vma->vm_ops = &relay_file_mmap_ops;
95 vma->vm_flags |= VM_DONTEXPAND;
95 vma->vm_private_data = buf; 96 vma->vm_private_data = buf;
96 buf->chan->cb->buf_mapped(buf, filp); 97 buf->chan->cb->buf_mapped(buf, filp);
97 98
diff --git a/mm/mmap.c b/mm/mmap.c
index d2b6d44962b7..8295577a83b2 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2216,7 +2216,7 @@ int install_special_mapping(struct mm_struct *mm,
2216 vma->vm_start = addr; 2216 vma->vm_start = addr;
2217 vma->vm_end = addr + len; 2217 vma->vm_end = addr + len;
2218 2218
2219 vma->vm_flags = vm_flags | mm->def_flags; 2219 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
2220 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); 2220 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2221 2221
2222 vma->vm_ops = &special_mapping_vmops; 2222 vma->vm_ops = &special_mapping_vmops;
diff --git a/sound/oss/via82cxxx_audio.c b/sound/oss/via82cxxx_audio.c
index 5d3c0372df32..f95aa0946758 100644
--- a/sound/oss/via82cxxx_audio.c
+++ b/sound/oss/via82cxxx_audio.c
@@ -2104,6 +2104,7 @@ static struct page * via_mm_nopage (struct vm_area_struct * vma,
2104{ 2104{
2105 struct via_info *card = vma->vm_private_data; 2105 struct via_info *card = vma->vm_private_data;
2106 struct via_channel *chan = &card->ch_out; 2106 struct via_channel *chan = &card->ch_out;
2107 unsigned long max_bufs;
2107 struct page *dmapage; 2108 struct page *dmapage;
2108 unsigned long pgoff; 2109 unsigned long pgoff;
2109 int rd, wr; 2110 int rd, wr;
@@ -2127,14 +2128,11 @@ static struct page * via_mm_nopage (struct vm_area_struct * vma,
2127 rd = card->ch_in.is_mapped; 2128 rd = card->ch_in.is_mapped;
2128 wr = card->ch_out.is_mapped; 2129 wr = card->ch_out.is_mapped;
2129 2130
2130#ifndef VIA_NDEBUG 2131 max_bufs = chan->frag_number;
2131 { 2132 if (rd && wr)
2132 unsigned long max_bufs = chan->frag_number; 2133 max_bufs *= 2;
2133 if (rd && wr) max_bufs *= 2; 2134 if (pgoff >= max_bufs)
2134 /* via_dsp_mmap() should ensure this */ 2135 return NOPAGE_SIGBUS;
2135 assert (pgoff < max_bufs);
2136 }
2137#endif
2138 2136
2139 /* if full-duplex (read+write) and we have two sets of bufs, 2137 /* if full-duplex (read+write) and we have two sets of bufs,
2140 * then the playback buffers come first, sez soundcard.c */ 2138 * then the playback buffers come first, sez soundcard.c */
diff --git a/sound/usb/usx2y/usX2Yhwdep.c b/sound/usb/usx2y/usX2Yhwdep.c
index 6495534e5bf6..1558a5c4094f 100644
--- a/sound/usb/usx2y/usX2Yhwdep.c
+++ b/sound/usb/usx2y/usX2Yhwdep.c
@@ -84,7 +84,7 @@ static int snd_us428ctls_mmap(struct snd_hwdep * hw, struct file *filp, struct v
84 us428->us428ctls_sharedmem->CtlSnapShotLast = -2; 84 us428->us428ctls_sharedmem->CtlSnapShotLast = -2;
85 } 85 }
86 area->vm_ops = &us428ctls_vm_ops; 86 area->vm_ops = &us428ctls_vm_ops;
87 area->vm_flags |= VM_RESERVED; 87 area->vm_flags |= VM_RESERVED | VM_DONTEXPAND;
88 area->vm_private_data = hw->private_data; 88 area->vm_private_data = hw->private_data;
89 return 0; 89 return 0;
90} 90}
diff --git a/sound/usb/usx2y/usx2yhwdeppcm.c b/sound/usb/usx2y/usx2yhwdeppcm.c
index 800b5cecfc80..117946f2debb 100644
--- a/sound/usb/usx2y/usx2yhwdeppcm.c
+++ b/sound/usb/usx2y/usx2yhwdeppcm.c
@@ -722,7 +722,7 @@ static int snd_usX2Y_hwdep_pcm_mmap(struct snd_hwdep * hw, struct file *filp, st
722 return -ENODEV; 722 return -ENODEV;
723 } 723 }
724 area->vm_ops = &snd_usX2Y_hwdep_pcm_vm_ops; 724 area->vm_ops = &snd_usX2Y_hwdep_pcm_vm_ops;
725 area->vm_flags |= VM_RESERVED; 725 area->vm_flags |= VM_RESERVED | VM_DONTEXPAND;
726 area->vm_private_data = hw->private_data; 726 area->vm_private_data = hw->private_data;
727 return 0; 727 return 0;
728} 728}