public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Ivajlo Dimitrov <ivo.g.dimitrov.75@gmail.com>
To: Dan Carpenter <dan.carpenter@oracle.com>, Pavel Machek <pavel@ucw.cz>
Cc: "Pali Rohá" <pali.rohar@gmail.com>,
	"Greg KH" <gregkh@linuxfoundation.org>,
	"Ивайло Д" <freemangordon@abv.bg>,
	sre@ring0.de, omar.ramirez@copitl.com, tony@atomide.com,
	felipe.contreras@gmail.com, s-anna@ti.com, nm@ti.com,
	ohad@wizery.com, stable@vger.kernel.org,
	linux-kernel@vger.kernel.org, nico@ngolde.de
Subject: Re: [patch] Staging: tidspbridge: make mmap root-only so it is not a security problem
Date: Sun, 01 Dec 2013 20:14:37 +0200	[thread overview]
Message-ID: <529B7C8D.7060101@gmail.com> (raw)
In-Reply-To: <20131201122756.GH5443@mwanda>


On 01.12.2013 14:27, Dan Carpenter wrote:
> On Sun, Dec 01, 2013 at 01:10:06PM +0100, Pavel Machek wrote:
>> diff --git a/drivers/staging/tidspbridge/rmgr/drv_interface.c b/drivers/staging/tidspbridge/rmgr/drv_interface.c
>> index 1aa4a3f..a8e86cf 100644
>> --- a/drivers/staging/tidspbridge/rmgr/drv_interface.c
>> +++ b/drivers/staging/tidspbridge/rmgr/drv_interface.c
>> @@ -258,7 +258,17 @@ err:
>>   /* This function maps kernel space memory to user space memory. */
>>   static int bridge_mmap(struct file *filp, struct vm_area_struct *vma)
>>   {
>> -	u32 status;
>> +	int status;
>> +	struct omap_dsp_platform_data *pdata =
>> +	    omap_dspbridge_dev->dev.platform_data;
>> +	unsigned long start = vma->vm_pgoff << PAGE_SHIFT;
>> +		
>> +	if (start < pdata->phys_mempool_base)
>> +		return -EINVAL;
>> +
>> +	if (vma->vm_end - vma->vm_start + (start - pdata->phys_mempool_base)
>> +	    > pdata->phys_mempool_size)
> This test is vulnerable to integer overflows if you pick a very high
> value for start.  Consider using the vm_iomap_memory() helper function
> instead of calling remap_pfn_range() directly.  Commit 7314e613d5ff
> ('Fix a few incorrectly checked [io_]remap_pfn_range() calls') has an
> example of how the conversion works.
>
> regards,
> dan carpenter
>
Dan,

If that one looks fine, I'll send a correctly formatted patch.

Pavel - feel free you to do it, I don't want to "steal" your bug :) .

Patch tested with Maemo5 on n900:

diff --git a/drivers/staging/tidspbridge/rmgr/drv_interface.c 
b/drivers/staging/tidspbridge/rmgr/drv_interface.c
index 1aa4a3f..2d500ea 100644
--- a/drivers/staging/tidspbridge/rmgr/drv_interface.c
+++ b/drivers/staging/tidspbridge/rmgr/drv_interface.c
@@ -258,8 +258,9 @@ err:
  /* This function maps kernel space memory to user space memory. */
  static int bridge_mmap(struct file *filp, struct vm_area_struct *vma)
  {
-    u32 status;
-
+    struct omap_dsp_platform_data *pdata =
+        omap_dspbridge_dev->dev.platform_data;
+
      /* VM_IO | VM_DONTEXPAND | VM_DONTDUMP are set by remap_pfn_range() */
      vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);

@@ -268,13 +269,9 @@ static int bridge_mmap(struct file *filp, struct 
vm_area_struct *vma)
          vma->vm_start, vma->vm_end, vma->vm_page_prot,
          vma->vm_flags);

-    status = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
-                 vma->vm_end - vma->vm_start,
-                 vma->vm_page_prot);
-    if (status != 0)
-        status = -EAGAIN;
-
-    return status;
+    return vm_iomap_memory(vma,
+                   pdata->phys_mempool_base,
+                   pdata->phys_mempool_size);
  }

  static const struct file_operations bridge_fops = {






  reply	other threads:[~2013-12-01 18:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-30  9:58 Staging: tidspbridge: disable driver Ivajlo Dimitrov
2013-11-30 16:20 ` Greg KH
2013-11-30 17:27   ` Tony Lindgren
2013-11-30 19:19 ` Pavel Machek
2013-11-30 19:49   ` Dan Carpenter
2013-11-30 20:42     ` [patch] Staging: tidspbridge: make mmap root-only so it is not a security problem Pavel Machek
2013-11-30 22:05       ` Greg KH
2013-11-30 22:58         ` Pavel Machek
2013-12-01  3:45           ` Greg KH
2013-12-01  9:47             ` Pali Rohár
2013-12-01 11:26             ` Pavel Machek
2013-12-01 11:33               ` Pali Rohár
2013-12-01  9:41           ` Pali Rohár
2013-12-01  9:58             ` Ивайло Димитров
2013-12-01 12:10               ` Pavel Machek
2013-12-01 12:27                 ` Dan Carpenter
2013-12-01 18:14                   ` Ivajlo Dimitrov [this message]
2013-12-01 18:57                     ` Pavel Machek
2013-12-01 19:28                     ` Dan Carpenter

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=529B7C8D.7060101@gmail.com \
    --to=ivo.g.dimitrov.75@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=felipe.contreras@gmail.com \
    --cc=freemangordon@abv.bg \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nico@ngolde.de \
    --cc=nm@ti.com \
    --cc=ohad@wizery.com \
    --cc=omar.ramirez@copitl.com \
    --cc=pali.rohar@gmail.com \
    --cc=pavel@ucw.cz \
    --cc=s-anna@ti.com \
    --cc=sre@ring0.de \
    --cc=stable@vger.kernel.org \
    --cc=tony@atomide.com \
    /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