linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* bug in generic_access_phys (mm/memory.c) ?
@ 2013-10-29  8:44 Paolo Minazzi
  2013-10-29 10:46 ` Paolo Minazzi
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Minazzi @ 2013-10-29  8:44 UTC (permalink / raw)
  To: linux-kernel

Hi to all,
I think the function "generic_access_phys" in mm/memory.c has got a 
small bug.
THe ioremap_prot is called with the parameter size=PAGE_SIZE.
But it can happen that we need more than one page, and this will produce 
a kernel fault.

int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
                         void *buf, int len, int write)
{
         resource_size_t phys_addr;
         unsigned long prot = 0;
         void __iomem *maddr;
         int offset = addr & (PAGE_SIZE-1);

         if (follow_phys(vma, addr, write, &prot, &phys_addr))
                 return -EINVAL;

====>   maddr = ioremap_prot(phys_addr, PAGE_SIZE);

         if (write)
                 memcpy_toio(maddr + offset, buf, len);
         else
                 memcpy_fromio(buf, maddr + offset, len);
         iounmap(maddr);

         return len;
}


I think that the ioremap_prot should be changed with

maddr = ioremap_prot(phys_addr, ((phys_addr + offset + len - 1) & 
~(PAGE_SIZE-1)) -
                                 phys_addr + PAGE_SIZE);

Thanks,
Paolo Minazzi




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: bug in generic_access_phys (mm/memory.c) ?
  2013-10-29  8:44 bug in generic_access_phys (mm/memory.c) ? Paolo Minazzi
@ 2013-10-29 10:46 ` Paolo Minazzi
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Minazzi @ 2013-10-29 10:46 UTC (permalink / raw)
  To: linux-kernel

Il 29/10/2013 9.44, Paolo Minazzi ha scritto:
> Hi to all,
> I think the function "generic_access_phys" in mm/memory.c has got a 
> small bug.
> THe ioremap_prot is called with the parameter size=PAGE_SIZE.
> But it can happen that we need more than one page, and this will 
> produce a kernel fault.
>
> int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
>                         void *buf, int len, int write)
> {
>         resource_size_t phys_addr;
>         unsigned long prot = 0;
>         void __iomem *maddr;
>         int offset = addr & (PAGE_SIZE-1);
>
>         if (follow_phys(vma, addr, write, &prot, &phys_addr))
>                 return -EINVAL;
>
> ====>   maddr = ioremap_prot(phys_addr, PAGE_SIZE);
>
>         if (write)
>                 memcpy_toio(maddr + offset, buf, len);
>         else
>                 memcpy_fromio(buf, maddr + offset, len);
>         iounmap(maddr);
>
>         return len;
> }
>
>
> I think that the ioremap_prot should be changed with
>
> maddr = ioremap_prot(phys_addr, ((phys_addr + offset + len - 1) & 
> ~(PAGE_SIZE-1)) -
>                                 phys_addr + PAGE_SIZE);
>
> Thanks,
> Paolo Minazzi

This is a more simple patch in the usual diff format:

diff -r 6321bc9c43db linux-2.6.31.8/mm/memory.c
--- a/linux-2.6.31.8/mm/memory.c        Tue Oct 22 13:35:14 2013 +0200
+++ b/linux-2.6.31.8/mm/memory.c        Tue Oct 29 11:44:51 2013 +0100
@@ -3264,1 +3264,1 @@
-       maddr = ioremap_prot(phys_addr, PAGE_SIZE);
+       maddr = ioremap_prot(phys_addr, ((offset + len - 1) & 
~(PAGE_SIZE-1)) + PAGE_SIZE );

Regards,
Paolo Minazzi


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-10-29 10:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-29  8:44 bug in generic_access_phys (mm/memory.c) ? Paolo Minazzi
2013-10-29 10:46 ` Paolo Minazzi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).