All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] amd64-agp: fix arbitrary kernel memory writes
@ 2019-05-29  4:52 Young Xiao
  2019-05-29  8:34 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Young Xiao @ 2019-05-29  4:52 UTC (permalink / raw)
  To: airlied, arnd, gregkh, linux-kernel; +Cc: 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.

Signed-off-by: Young Xiao <92siuyang@gmail.com>
---
 drivers/char/agp/amd64-agp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index c69e39f..5daa0e3 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -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;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] amd64-agp: fix arbitrary kernel memory writes
  2019-05-29  4:52 [PATCH] amd64-agp: fix arbitrary kernel memory writes Young Xiao
@ 2019-05-29  8:34 ` Greg KH
  2019-05-29 15:14   ` Yang Xiao
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2019-05-29  8:34 UTC (permalink / raw)
  To: Young Xiao; +Cc: airlied, arnd, linux-kernel

On Wed, May 29, 2019 at 12:52:01PM +0800, Young Xiao wrote:
> 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.
> 
> Signed-off-by: Young Xiao <92siuyang@gmail.com>
> ---
>  drivers/char/agp/amd64-agp.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
> index c69e39f..5daa0e3 100644
> --- a/drivers/char/agp/amd64-agp.c
> +++ b/drivers/char/agp/amd64-agp.c
> @@ -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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] amd64-agp: fix arbitrary kernel memory writes
  2019-05-29  8:34 ` Greg KH
@ 2019-05-29 15:14   ` Yang Xiao
  0 siblings, 0 replies; 3+ messages in thread
From: Yang Xiao @ 2019-05-29 15:14 UTC (permalink / raw)
  To: Greg KH; +Cc: airlied, arnd, LKML

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

On Wed, May 29, 2019 at 4:35 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Wed, May 29, 2019 at 12:52:01PM +0800, Young Xiao wrote:
> > 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.
> >
> > Signed-off-by: Young Xiao <92siuyang@gmail.com>
> > ---
> >  drivers/char/agp/amd64-agp.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
> > index c69e39f..5daa0e3 100644
> > --- a/drivers/char/agp/amd64-agp.c
> > +++ b/drivers/char/agp/amd64-agp.c
> > @@ -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



-- 
Best regards!

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-29 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-29  4:52 [PATCH] amd64-agp: fix arbitrary kernel memory writes Young Xiao
2019-05-29  8:34 ` Greg KH
2019-05-29 15:14   ` Yang Xiao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.