public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paolo Minazzi <Paolo.Minazzi@mitrol.it>
To: linux-kernel@vger.kernel.org
Subject: bug in generic_access_phys (mm/memory.c) ?
Date: Tue, 29 Oct 2013 09:44:24 +0100	[thread overview]
Message-ID: <526F7568.2050300@mitrol.it> (raw)

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




             reply	other threads:[~2013-10-29  8:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-29  8:44 Paolo Minazzi [this message]
2013-10-29 10:46 ` bug in generic_access_phys (mm/memory.c) ? Paolo Minazzi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=526F7568.2050300@mitrol.it \
    --to=paolo.minazzi@mitrol.it \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox