Skip to contentSkip to conversation

amd64-agp: fix arbitrary kernel memory writes

PATCH In review Young Xiao 2 participants 3 messages May 29, 2019 Agpgart driver

lore
Share & tools
lore

Young Xiao

author
#0 lore raw

PATCH 1/1 amd64-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.

See commit 194b3da873fd ("agp: fix arbitrary kernel memory writes") for details.

---
 drivers/char/agp/amd64-agp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/char/agp/amd64-agp.c +2 -1
index c69e39f..5daa0e3 100644
@@ -60,7 +60,8 @@ static int amd64_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
 
 	/* Make sure we can fit the range in the gatt table. */
 	/* FIXME: could wrap */
-	if (((unsigned long)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;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 20 lines · Young Xiao

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.

See commit 194b3da873fd ("agp: fix arbitrary kernel memory writes") for details.

---
 drivers/char/agp/amd64-agp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/char/agp/amd64-agp.c +0 -0
index c69e39f..5daa0e3 100644

drivers/char/agp/amd64-agp.c static int amd64_insert_memory(struct agp_memory *mem, off_t pg_start, int type) · line 64

Quoted 6 lines
drivers/char/agp/amd64-agp.c +2 -1
@@ -60,7 +60,8 @@ static int amd64_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
 
 	/* Make sure we can fit the range in the gatt table. */
 	/* FIXME: could wrap */
-	if (((unsigned long)pg_start + mem->page_count) > num_entries)
+	if (((pg_start + mem->page_count) > num_entries) ||
+	    ((pg_start + mem->page_count) < pg_start))

Why did you take off the cast for the first test?

And if this really does fix this issue, should you remove the FIXME line?

thanks,

greg k-h

author
#2 lore raw

I am not so sure about taking off the cast, just to be in line with patch in 194b3da873fd.
The comment can be deleted.

Quoted 37 lines · Greg KH
Quoted 20 lines · Young Xiao

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.

See commit 194b3da873fd ("agp: fix arbitrary kernel memory writes") for details.

---
 drivers/char/agp/amd64-agp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/char/agp/amd64-agp.c +0 -0
index c69e39f..5daa0e3 100644

drivers/char/agp/amd64-agp.c static int amd64_insert_memory(struct agp_memory *mem, off_t pg_start, int type) · line 64

Quoted 6 lines
drivers/char/agp/amd64-agp.c +2 -1
@@ -60,7 +60,8 @@ static int amd64_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
 
      /* Make sure we can fit the range in the gatt table. */
      /* FIXME: could wrap */
-     if (((unsigned long)pg_start + mem->page_count) > num_entries)
+     if (((pg_start + mem->page_count) > num_entries) ||
+         ((pg_start + mem->page_count) < pg_start))

Why did you take off the cast for the first test?

And if this really does fix this issue, should you remove the FIXME line?

thanks,

greg k-h

Signature · 4 lines
Best regards!

Young
-----------------------------------------------------------