diff mbox

[hardy,maverick,CVE,1/1] agp: fix arbitrary kernel memory writes

Message ID 1306425029-30649-2-git-send-email-apw@canonical.com
State New
Headers show

Commit Message

Andy Whitcroft May 26, 2011, 3:50 p.m. UTC
From: Vasiliy Kulikov <segoon@openwall.com>

pg_start is copied from userspace on AGPIOC_BIND and AGPIOC_UNBIND ioctl
cmds of agp_ioctl() and passed to agpioc_bind_wrap().  As said in the
comment, (pg_start + mem->page_count) may wrap in case of AGPIOC_BIND,
and it is not checked at all in case of AGPIOC_UNBIND.  As a result, user
with sufficient privileges (usually "video" group) may generate either
local DoS or privilege escalation.

Signed-off-by: Vasiliy Kulikov <segoon@openwall.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>

CVE-1011-2022
BugLink: http://bugs.launchpad.net/bugs/788684
(cherry picked from commit 194b3da873fd334ef183806db751473512af29ce)
Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 drivers/char/agp/generic.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

Comments

Leann Ogasawara May 26, 2011, 4:13 p.m. UTC | #1
On Thu, 2011-05-26 at 16:50 +0100, Andy Whitcroft wrote:
> From: Vasiliy Kulikov <segoon@openwall.com>
> 
> pg_start is copied from userspace on AGPIOC_BIND and AGPIOC_UNBIND ioctl
> cmds of agp_ioctl() and passed to agpioc_bind_wrap().  As said in the
> comment, (pg_start + mem->page_count) may wrap in case of AGPIOC_BIND,
> and it is not checked at all in case of AGPIOC_UNBIND.  As a result, user
> with sufficient privileges (usually "video" group) may generate either
> local DoS or privilege escalation.
> 
> Signed-off-by: Vasiliy Kulikov <segoon@openwall.com>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> 
> CVE-1011-2022
> BugLink: http://bugs.launchpad.net/bugs/788684
> (cherry picked from commit 194b3da873fd334ef183806db751473512af29ce)
> Signed-off-by: Andy Whitcroft <apw@canonical.com>

Acked-by: Leann Ogasawara <leann.ogasawara@canonical.com>

> ---
>  drivers/char/agp/generic.c |   11 ++++++++---
>  1 files changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
> index d2abf51..7858016 100644
> --- a/drivers/char/agp/generic.c
> +++ b/drivers/char/agp/generic.c
> @@ -1122,8 +1122,8 @@ int agp_generic_insert_memory(struct agp_memory * mem, off_t pg_start, int type)
>  		return -EINVAL;
>  	}
>  
> -	/* AK: could wrap */
> -	if ((pg_start + mem->page_count) > num_entries)
> +	if (((pg_start + mem->page_count) > num_entries) ||
> +	    ((pg_start + mem->page_count) < pg_start))
>  		return -EINVAL;
>  
>  	j = pg_start;
> @@ -1157,7 +1157,7 @@ int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
>  {
>  	size_t i;
>  	struct agp_bridge_data *bridge;
> -	int mask_type;
> +	int mask_type, num_entries;
>  
>  	bridge = mem->bridge;
>  	if (!bridge)
> @@ -1169,6 +1169,11 @@ int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
>  	if (type != mem->type)
>  		return -EINVAL;
>  
> +	num_entries = agp_num_entries();
> +	if (((pg_start + mem->page_count) > num_entries) ||
> +	    ((pg_start + mem->page_count) < pg_start))
> +		return -EINVAL;
> +
>  	mask_type = bridge->driver->agp_type_to_mask_type(bridge, type);
>  	if (mask_type != 0) {
>  		/* The generic routines know nothing of memory types */
> -- 
> 1.7.4.1
> 
>
diff mbox

Patch

diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index d2abf51..7858016 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -1122,8 +1122,8 @@  int agp_generic_insert_memory(struct agp_memory * mem, off_t pg_start, int type)
 		return -EINVAL;
 	}
 
-	/* AK: could wrap */
-	if ((pg_start + mem->page_count) > num_entries)
+	if (((pg_start + mem->page_count) > num_entries) ||
+	    ((pg_start + mem->page_count) < pg_start))
 		return -EINVAL;
 
 	j = pg_start;
@@ -1157,7 +1157,7 @@  int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
 {
 	size_t i;
 	struct agp_bridge_data *bridge;
-	int mask_type;
+	int mask_type, num_entries;
 
 	bridge = mem->bridge;
 	if (!bridge)
@@ -1169,6 +1169,11 @@  int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
 	if (type != mem->type)
 		return -EINVAL;
 
+	num_entries = agp_num_entries();
+	if (((pg_start + mem->page_count) > num_entries) ||
+	    ((pg_start + mem->page_count) < pg_start))
+		return -EINVAL;
+
 	mask_type = bridge->driver->agp_type_to_mask_type(bridge, type);
 	if (mask_type != 0) {
 		/* The generic routines know nothing of memory types */