linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write
@ 2022-09-20  6:02 Dan Carpenter
  2022-09-20  6:13 ` Dan Carpenter
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2022-09-20  6:02 UTC (permalink / raw)
  To: Hyunwoo Kim, deller, linux-fbdev, Masami Ichikawa, cip-dev,
	Harshit Mogalapalli

On Mon, Jun 20, 2022 at 07:00:10AM -0700, Hyunwoo Kim wrote:
> In pxa3xx_gcu_write, a count parameter of
> type size_t is passed to words of type int.
> Then, copy_from_user may cause a heap overflow because
> it is used as the third argument of copy_from_user.
> 
> Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
> ---
>  drivers/video/fbdev/pxa3xx-gcu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c
> index 043cc8f9ef1c..c3cd1e1cc01b 100644
> --- a/drivers/video/fbdev/pxa3xx-gcu.c
> +++ b/drivers/video/fbdev/pxa3xx-gcu.c
> @@ -381,7 +381,7 @@ pxa3xx_gcu_write(struct file *file, const char *buff,
>  	struct pxa3xx_gcu_batch	*buffer;
>  	struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);
> 
> -	int words = count / 4;
> +	size_t words = count / 4;

The count variable is actually capped at MAX_RW_COUNT in vfs_write()
so "words" cannot be negative.  This patch helps clean up the code but
it does not affect run time.

This is CVE-2022-39842.

regards,
dan carpenter

PS:  The other relavant code for people looking for integer overflows in
read/write functions is in rw_verify_area().  That function prevents a
lot of suspicious looking driver code from being exploitable.



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

* Re: [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write
  2022-09-20  6:02 [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write Dan Carpenter
@ 2022-09-20  6:13 ` Dan Carpenter
  2022-09-20  6:22   ` Hyunwoo Kim
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2022-09-20  6:13 UTC (permalink / raw)
  To: Hyunwoo Kim, deller, linux-fbdev, Masami Ichikawa, cip-dev,
	Harshit Mogalapalli

On Tue, Sep 20, 2022 at 09:02:34AM +0300, Dan Carpenter wrote:
> On Mon, Jun 20, 2022 at 07:00:10AM -0700, Hyunwoo Kim wrote:
> > In pxa3xx_gcu_write, a count parameter of
> > type size_t is passed to words of type int.
> > Then, copy_from_user may cause a heap overflow because
> > it is used as the third argument of copy_from_user.
> > 
> > Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
> > ---
> >  drivers/video/fbdev/pxa3xx-gcu.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c
> > index 043cc8f9ef1c..c3cd1e1cc01b 100644
> > --- a/drivers/video/fbdev/pxa3xx-gcu.c
> > +++ b/drivers/video/fbdev/pxa3xx-gcu.c
> > @@ -381,7 +381,7 @@ pxa3xx_gcu_write(struct file *file, const char *buff,
> >  	struct pxa3xx_gcu_batch	*buffer;
> >  	struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);
> > 
> > -	int words = count / 4;
> > +	size_t words = count / 4;
> 
> The count variable is actually capped at MAX_RW_COUNT in vfs_write()
> so "words" cannot be negative.  This patch helps clean up the code but
> it does not affect run time.

Btw, the other thing which prevents this from being expliotable is that
if you pass a negative value to copy_from_user() it will not copy
anything because of the check in check_copy_size().  See commit
6d13de1489b6 ("uaccess: disallow > INT_MAX copy sizes").

Linus has sort of gotten annoyed with me before for pointing this stuff
out because it seemed like maybe I wasn't properly grateful to people
auditing the code and fixing bugs.  I am grateful.  This patch is
totally the correct thing to do.  It's just that it's not really
exploitable as described in the commit message.

regards,
dan carpenter

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

* Re: [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write
  2022-09-20  6:13 ` Dan Carpenter
@ 2022-09-20  6:22   ` Hyunwoo Kim
  2022-09-20  7:12     ` Dan Carpenter
  0 siblings, 1 reply; 9+ messages in thread
From: Hyunwoo Kim @ 2022-09-20  6:22 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: deller, linux-fbdev, Masami Ichikawa, cip-dev, Harshit Mogalapalli

On Tue, Sep 20, 2022 at 09:13:31AM +0300, Dan Carpenter wrote:
> On Tue, Sep 20, 2022 at 09:02:34AM +0300, Dan Carpenter wrote:
> > On Mon, Jun 20, 2022 at 07:00:10AM -0700, Hyunwoo Kim wrote:
> > > In pxa3xx_gcu_write, a count parameter of
> > > type size_t is passed to words of type int.
> > > Then, copy_from_user may cause a heap overflow because
> > > it is used as the third argument of copy_from_user.
> > > 
> > > Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
> > > ---
> > >  drivers/video/fbdev/pxa3xx-gcu.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c
> > > index 043cc8f9ef1c..c3cd1e1cc01b 100644
> > > --- a/drivers/video/fbdev/pxa3xx-gcu.c
> > > +++ b/drivers/video/fbdev/pxa3xx-gcu.c
> > > @@ -381,7 +381,7 @@ pxa3xx_gcu_write(struct file *file, const char *buff,
> > >  	struct pxa3xx_gcu_batch	*buffer;
> > >  	struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);
> > > 
> > > -	int words = count / 4;
> > > +	size_t words = count / 4;
> > 
> > The count variable is actually capped at MAX_RW_COUNT in vfs_write()
> > so "words" cannot be negative.  This patch helps clean up the code but
> > it does not affect run time.
> 
> Btw, the other thing which prevents this from being expliotable is that
> if you pass a negative value to copy_from_user() it will not copy
> anything because of the check in check_copy_size().  See commit
> 6d13de1489b6 ("uaccess: disallow > INT_MAX copy sizes").
> 
> Linus has sort of gotten annoyed with me before for pointing this stuff
> out because it seemed like maybe I wasn't properly grateful to people
> auditing the code and fixing bugs.  I am grateful.  This patch is
> totally the correct thing to do.  It's just that it's not really
> exploitable as described in the commit message.

I found the code that might have the vulnerability, and submitted a patch without actually debugging it.
This is entirely my fault. sorry.

Should I submit a fix patch that fixes the commit message?

Sorry again.


Regards,
Hyunwoo Kim.

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

* Re: [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write
  2022-09-20  6:22   ` Hyunwoo Kim
@ 2022-09-20  7:12     ` Dan Carpenter
  0 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2022-09-20  7:12 UTC (permalink / raw)
  To: Hyunwoo Kim
  Cc: deller, linux-fbdev, Masami Ichikawa, cip-dev, Harshit Mogalapalli

On Mon, Sep 19, 2022 at 11:22:41PM -0700, Hyunwoo Kim wrote:
> On Tue, Sep 20, 2022 at 09:13:31AM +0300, Dan Carpenter wrote:
> > On Tue, Sep 20, 2022 at 09:02:34AM +0300, Dan Carpenter wrote:
> > > On Mon, Jun 20, 2022 at 07:00:10AM -0700, Hyunwoo Kim wrote:
> > > > In pxa3xx_gcu_write, a count parameter of
> > > > type size_t is passed to words of type int.
> > > > Then, copy_from_user may cause a heap overflow because
> > > > it is used as the third argument of copy_from_user.
> > > > 
> > > > Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
> > > > ---
> > > >  drivers/video/fbdev/pxa3xx-gcu.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c
> > > > index 043cc8f9ef1c..c3cd1e1cc01b 100644
> > > > --- a/drivers/video/fbdev/pxa3xx-gcu.c
> > > > +++ b/drivers/video/fbdev/pxa3xx-gcu.c
> > > > @@ -381,7 +381,7 @@ pxa3xx_gcu_write(struct file *file, const char *buff,
> > > >  	struct pxa3xx_gcu_batch	*buffer;
> > > >  	struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);
> > > > 
> > > > -	int words = count / 4;
> > > > +	size_t words = count / 4;
> > > 
> > > The count variable is actually capped at MAX_RW_COUNT in vfs_write()
> > > so "words" cannot be negative.  This patch helps clean up the code but
> > > it does not affect run time.
> > 
> > Btw, the other thing which prevents this from being expliotable is that
> > if you pass a negative value to copy_from_user() it will not copy
> > anything because of the check in check_copy_size().  See commit
> > 6d13de1489b6 ("uaccess: disallow > INT_MAX copy sizes").
> > 
> > Linus has sort of gotten annoyed with me before for pointing this stuff
> > out because it seemed like maybe I wasn't properly grateful to people
> > auditing the code and fixing bugs.  I am grateful.  This patch is
> > totally the correct thing to do.  It's just that it's not really
> > exploitable as described in the commit message.
> 
> I found the code that might have the vulnerability, and submitted a patch without actually debugging it.
> This is entirely my fault. sorry.
> 
> Should I submit a fix patch that fixes the commit message?
> 
> Sorry again.


No no.  No need to appologize or resend anything.  This is just
information to help in future research.

regards,
dan carpenter


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

* Re: [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write
  2022-06-20 18:13     ` Helge Deller
@ 2022-06-20 18:16       ` Hyunwoo Kim
  0 siblings, 0 replies; 9+ messages in thread
From: Hyunwoo Kim @ 2022-06-20 18:16 UTC (permalink / raw)
  To: Helge Deller; +Cc: linux-fbdev

Thanks for your feedback. :)

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

* Re: [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write
  2022-06-20 14:17   ` Hyunwoo Kim
@ 2022-06-20 18:13     ` Helge Deller
  2022-06-20 18:16       ` Hyunwoo Kim
  0 siblings, 1 reply; 9+ messages in thread
From: Helge Deller @ 2022-06-20 18:13 UTC (permalink / raw)
  To: Hyunwoo Kim; +Cc: linux-fbdev

On 6/20/22 16:17, Hyunwoo Kim wrote:
> From 1c55d1e084071caf02e7739e71e65f52206e872c Mon Sep 17 00:00:00 2001
> From: Hyunwoo Kim <imv4bel@gmail.com>
> Date: Mon, 20 Jun 2022 07:00:10 -0700
> Subject: [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write
>
> In pxa3xx_gcu_write, a count parameter of
> type size_t is passed to words of type int.
> Then, copy_from_user may cause a heap overflow because
> it is used as the third argument of copy_from_user.
>
> Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>

applied.

Thanks!
Helge

> ---
>  drivers/video/fbdev/pxa3xx-gcu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c
> index 043cc8f9ef1c..c3cd1e1cc01b 100644
> --- a/drivers/video/fbdev/pxa3xx-gcu.c
> +++ b/drivers/video/fbdev/pxa3xx-gcu.c
> @@ -381,7 +381,7 @@ pxa3xx_gcu_write(struct file *file, const char *buff,
>  	struct pxa3xx_gcu_batch	*buffer;
>  	struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);
>
> -	int words = count / 4;
> +	size_t words = count / 4;
>
>  	/* Does not need to be atomic. There's a lock in user space,
>  	 * but anyhow, this is just for statistics. */
> --
> 2.25.1
>
> Hello Helge,
>
> Fixed the patch as requested.
>
> Regards,
> Hyunwoo Kim


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

* Re: [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write
  2022-06-20 12:50 ` Helge Deller
@ 2022-06-20 14:17   ` Hyunwoo Kim
  2022-06-20 18:13     ` Helge Deller
  0 siblings, 1 reply; 9+ messages in thread
From: Hyunwoo Kim @ 2022-06-20 14:17 UTC (permalink / raw)
  To: Helge Deller; +Cc: linux-fbdev

From 1c55d1e084071caf02e7739e71e65f52206e872c Mon Sep 17 00:00:00 2001
From: Hyunwoo Kim <imv4bel@gmail.com>
Date: Mon, 20 Jun 2022 07:00:10 -0700
Subject: [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write

In pxa3xx_gcu_write, a count parameter of
type size_t is passed to words of type int.
Then, copy_from_user may cause a heap overflow because
it is used as the third argument of copy_from_user.

Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
---
 drivers/video/fbdev/pxa3xx-gcu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c
index 043cc8f9ef1c..c3cd1e1cc01b 100644
--- a/drivers/video/fbdev/pxa3xx-gcu.c
+++ b/drivers/video/fbdev/pxa3xx-gcu.c
@@ -381,7 +381,7 @@ pxa3xx_gcu_write(struct file *file, const char *buff,
 	struct pxa3xx_gcu_batch	*buffer;
 	struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);

-	int words = count / 4;
+	size_t words = count / 4;

 	/* Does not need to be atomic. There's a lock in user space,
 	 * but anyhow, this is just for statistics. */
--
2.25.1

Hello Helge,

Fixed the patch as requested.

Regards,
Hyunwoo Kim

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

* Re: [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write
  2022-06-11 19:28 Hyunwoo Kim
@ 2022-06-20 12:50 ` Helge Deller
  2022-06-20 14:17   ` Hyunwoo Kim
  0 siblings, 1 reply; 9+ messages in thread
From: Helge Deller @ 2022-06-20 12:50 UTC (permalink / raw)
  To: Hyunwoo Kim, linux-fbdev

Hi Hyunwoo,

On 6/11/22 21:28, Hyunwoo Kim wrote:
> In pxa3xx_gcu_write, a count parameter of
> type size_t is passed to words of type int.
> Then, copy_from_user may cause a heap overflow because
> it is used as the third argument of copy_from_user.

I suggest to simply change the type of "words" a few lines above:
Instead of
        int words = count / 4;
use
        size_t words = count / 4;

count is already of type size_t and then you don't need to check against < 0.

Can you resend such a patch?

Helge

>
> Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
> ---
>  drivers/video/fbdev/pxa3xx-gcu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c
> index 043cc8f9ef1c..5ca6d37e365f 100644
> --- a/drivers/video/fbdev/pxa3xx-gcu.c
> +++ b/drivers/video/fbdev/pxa3xx-gcu.c
> @@ -389,7 +389,7 @@ pxa3xx_gcu_write(struct file *file, const char *buff,
>  	priv->shared->num_words += words;
>
>  	/* Last word reserved for batch buffer end command */
> -	if (words >= PXA3XX_GCU_BATCH_WORDS)
> +	if (words >= PXA3XX_GCU_BATCH_WORDS || words < 0)
>  		return -E2BIG;
>
>  	/* Wait for a free buffer */


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

* [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write
@ 2022-06-11 19:28 Hyunwoo Kim
  2022-06-20 12:50 ` Helge Deller
  0 siblings, 1 reply; 9+ messages in thread
From: Hyunwoo Kim @ 2022-06-11 19:28 UTC (permalink / raw)
  To: deller, linux-fbdev

In pxa3xx_gcu_write, a count parameter of
type size_t is passed to words of type int.
Then, copy_from_user may cause a heap overflow because
it is used as the third argument of copy_from_user.

Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
---
 drivers/video/fbdev/pxa3xx-gcu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c
index 043cc8f9ef1c..5ca6d37e365f 100644
--- a/drivers/video/fbdev/pxa3xx-gcu.c
+++ b/drivers/video/fbdev/pxa3xx-gcu.c
@@ -389,7 +389,7 @@ pxa3xx_gcu_write(struct file *file, const char *buff,
 	priv->shared->num_words += words;
 
 	/* Last word reserved for batch buffer end command */
-	if (words >= PXA3XX_GCU_BATCH_WORDS)
+	if (words >= PXA3XX_GCU_BATCH_WORDS || words < 0)
 		return -E2BIG;
 
 	/* Wait for a free buffer */
-- 
2.25.1


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

end of thread, other threads:[~2022-09-20  7:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20  6:02 [PATCH] pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write Dan Carpenter
2022-09-20  6:13 ` Dan Carpenter
2022-09-20  6:22   ` Hyunwoo Kim
2022-09-20  7:12     ` Dan Carpenter
  -- strict thread matches above, loose matches on Subject: below --
2022-06-11 19:28 Hyunwoo Kim
2022-06-20 12:50 ` Helge Deller
2022-06-20 14:17   ` Hyunwoo Kim
2022-06-20 18:13     ` Helge Deller
2022-06-20 18:16       ` Hyunwoo Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).