[PATCH] ncpfs mmap #2 (vm_pgoff overflow) (was Re: [PATCH] fbmem.c ... )

Petr Vandrovec (vandrove@vc.cvut.cz)
Wed, 3 Nov 1999 22:52:14 +0100


On Wed, Nov 03, 1999 at 02:42:18PM -0500, Mordechai T. Abzug wrote:
> On Wed, Nov 03, 1999 at 02:19:04PM -0500, kernel@kvack.org wrote:
> > On Wed, 3 Nov 1999, Mordechai T. Abzug wrote:
> > > - if (vma->vm_offset >= len) {
> > > + if (vma->vm_pgoff << PAGE_SHIFT >= len) {
> > This is better, but still wrong. What happens when shifting vm_pgoff
> > overflows the unsigned long? This will be possible -- it's why the
> > changes were done in the first place.
> Ah, thanks for the explanation. In that case, why was this shifting
> done elsewhere in patch-2.3.25? Ie. in linux/drivers/char/mem.c,
> linux/fs/ncpfs/mmap.c, and others? linux/drivers/char/mem.c involves
> an unsigned long, linux/fs/ncpfs/mmap.c involves an int. Is this a
> bug in those places, or is there some reason why this was not a
> problem over there?
Hi Linus,
sorry for bothering you again so quickly with ncpfs. Could you apply
this patch to 2.3.25? It limits mmap() to 4GB, because of ncpfs does
not support bigger files. Otherwise I have to check whether
vm_pgoff << PAGE_SHIFT overflows in nopage... This seems clearer to me.
BTW, it looks to me like that now vm_start and vm_end are both
page aligned. Is it true? There is check in ncpfs_nopage which is able to
handle (vm_end & ~PAGE_MASK) != 0. Can I remove it without any bad effects?
(is there planned move from bytes to page units in vm_start/vm_end or
not?)
I do not know, whether -EFBIG is correct (it is not listed on mmap()
man page), but it looks right to me (other alternative is -EINVAL).
Thanks,
Petr Vandrovec
vandrove@vc.cvut.cz

P.S.: Please, apply it even if you are not going to remove 4GB limit on
filesize from ia32 anytime soon. You can get above 4GB limit on 64bit archs
without this patch and it is not correct.

diff -urdN linux/fs/ncpfs/mmap.c linux/fs/ncpfs/mmap.c
--- linux/fs/ncpfs/mmap.c Fri Oct 29 17:53:32 1999
+++ linux/fs/ncpfs/mmap.c Wed Nov 3 21:07:02 1999
@@ -119,6 +119,11 @@
return -EINVAL;
if (!inode->i_sb || !S_ISREG(inode->i_mode))
return -EACCES;
+ /* we do not support files bigger than 4GB... We
+ supports just 4GB... */
+ if (((vma->vm_end - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff
+ > (1U << (32 - PAGE_SHIFT)))
+ return -EFBIG;
if (!IS_RDONLY(inode)) {
inode->i_atime = CURRENT_TIME;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/