Skip to content

Commit 194b3da

Browse files
segoonairlied
authored andcommitted
agp: fix arbitrary kernel memory writes
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>
1 parent b522f02 commit 194b3da

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎drivers/char/agp/generic.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,8 +1095,8 @@ int agp_generic_insert_memory(struct agp_memory * mem, off_t pg_start, int type)
10951095
return -EINVAL;
10961096
}
10971097

1098-
/* AK: could wrap */
1099-
if ((pg_start + mem->page_count) > num_entries)
1098+
if (((pg_start + mem->page_count) > num_entries) ||
1099+
((pg_start + mem->page_count) < pg_start))
11001100
return -EINVAL;
11011101

11021102
j = pg_start;
@@ -1130,7 +1130,7 @@ int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
11301130
{
11311131
size_t i;
11321132
struct agp_bridge_data *bridge;
1133-
int mask_type;
1133+
int mask_type, num_entries;
11341134

11351135
bridge = mem->bridge;
11361136
if (!bridge)
@@ -1142,6 +1142,11 @@ int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
11421142
if (type != mem->type)
11431143
return -EINVAL;
11441144

1145+
num_entries = agp_num_entries();
1146+
if (((pg_start + mem->page_count) > num_entries) ||
1147+
((pg_start + mem->page_count) < pg_start))
1148+
return -EINVAL;
1149+
11451150
mask_type = bridge->driver->agp_type_to_mask_type(bridge, type);
11461151
if (mask_type != 0) {
11471152
/* The generic routines know nothing of memory types */

0 commit comments

Comments
 (0)