All of lore.kernel.org
 help / color / mirror / Atom feed
* stm class: Prevent user-controllable allocations
@ 2019-05-07 12:41 Pavel Machek
  2019-05-07 12:50 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Machek @ 2019-05-07 12:41 UTC (permalink / raw)
  To: alexander.shishkin, security, sasha.levin, gregkh, kernel list,
	Andrew Morton, trivial

[-- Attachment #1: Type: text/plain, Size: 778 bytes --]


It seems to me that we still allow overflow if count == ~0. We'll then
allocate 0 bytes but copy ~0 bytes. That does not sound healthy.

Fixes: f08b18266c7116e2ec6885dd53a928f580060a71

Signed-off-by: Pavel Machek <pavel@denx.de>

diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index c7ba8ac..8846fca 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -631,7 +631,7 @@ static ssize_t stm_char_write(struct file *file, const char __user *buf,
 	char *kbuf;
 	int err;
 
-	if (count + 1 > PAGE_SIZE)
+	if (count > PAGE_SIZE - 1)
 		count = PAGE_SIZE - 1;
 
 	/*

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: stm class: Prevent user-controllable allocations
  2019-05-07 12:41 stm class: Prevent user-controllable allocations Pavel Machek
@ 2019-05-07 12:50 ` Dan Carpenter
  2019-05-07 15:11   ` Pavel Machek
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2019-05-07 12:50 UTC (permalink / raw)
  To: Pavel Machek
  Cc: alexander.shishkin, security, sasha.levin, gregkh, kernel list,
	Andrew Morton, trivial

On Tue, May 07, 2019 at 02:41:13PM +0200, Pavel Machek wrote:
> 
> It seems to me that we still allow overflow if count == ~0. We'll then
> allocate 0 bytes but copy ~0 bytes. That does not sound healthy.
> 
> Fixes: f08b18266c7116e2ec6885dd53a928f580060a71
> 
> Signed-off-by: Pavel Machek <pavel@denx.de>
> 
> diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
> index c7ba8ac..8846fca 100644
> --- a/drivers/hwtracing/stm/core.c
> +++ b/drivers/hwtracing/stm/core.c
> @@ -631,7 +631,7 @@ static ssize_t stm_char_write(struct file *file, const char __user *buf,
>  	char *kbuf;
>  	int err;
>  
> -	if (count + 1 > PAGE_SIZE)
> +	if (count > PAGE_SIZE - 1)
>  		count = PAGE_SIZE - 1;

The "count" variable should all be checked in vfs_write().  count + off
is checked in rw_verify_area() and count is capped at MAX_RW_COUNT.

#define MAX_RW_COUNT (INT_MAX & PAGE_MASK)

regards,
dan carpenter


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

* Re: stm class: Prevent user-controllable allocations
  2019-05-07 12:50 ` Dan Carpenter
@ 2019-05-07 15:11   ` Pavel Machek
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Machek @ 2019-05-07 15:11 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Pavel Machek, alexander.shishkin, security, sasha.levin, gregkh,
	kernel list, Andrew Morton, trivial

[-- Attachment #1: Type: text/plain, Size: 1300 bytes --]

On Tue 2019-05-07 15:50:27, Dan Carpenter wrote:
> On Tue, May 07, 2019 at 02:41:13PM +0200, Pavel Machek wrote:
> > 
> > It seems to me that we still allow overflow if count == ~0. We'll then
> > allocate 0 bytes but copy ~0 bytes. That does not sound healthy.
> > 
> > Fixes: f08b18266c7116e2ec6885dd53a928f580060a71
> > 
> > Signed-off-by: Pavel Machek <pavel@denx.de>
> > 
> > diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
> > index c7ba8ac..8846fca 100644
> > --- a/drivers/hwtracing/stm/core.c
> > +++ b/drivers/hwtracing/stm/core.c
> > @@ -631,7 +631,7 @@ static ssize_t stm_char_write(struct file *file, const char __user *buf,
> >  	char *kbuf;
> >  	int err;
> >  
> > -	if (count + 1 > PAGE_SIZE)
> > +	if (count > PAGE_SIZE - 1)
> >  		count = PAGE_SIZE - 1;
> 
> The "count" variable should all be checked in vfs_write().  count + off
> is checked in rw_verify_area() and count is capped at MAX_RW_COUNT.
> 
> #define MAX_RW_COUNT (INT_MAX & PAGE_MASK)

Ok, so overflow is checked elsewhere. I'd still like patch to be
applied as it makes code more obvious.

Thanks,
								Pavel
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-07 12:41 stm class: Prevent user-controllable allocations Pavel Machek
2019-05-07 12:50 ` Dan Carpenter
2019-05-07 15:11   ` Pavel Machek

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.