Skip to contentSkip to conversation

stm class: Prevent user-controllable allocations

PATCH Pavel Machek 2 participants 3 messages May 7, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
drivers/hwtracing/stm/core.c +1 -1
index c7ba8ac..8846fca 100644
@@ -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;
 
 	/*
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#1 lore raw
Quoted 13 lines · Pavel Machek

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
drivers/hwtracing/stm/core.c +0 -0
index c7ba8ac..8846fca 100644

drivers/hwtracing/stm/core.c static ssize_t stm_char_write(struct file *file, const char __user *buf, · line 635

Quoted 6 lines
drivers/hwtracing/stm/core.c +1 -1
@@ -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

#2 lore raw
Quoted 17 lines · Dan Carpenter
Quoted 16 lines · Pavel Machek

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
drivers/hwtracing/stm/core.c +0 -0
index c7ba8ac..8846fca 100644
@@ -631,7 +631,7 @@ static ssize_t stm_char_write(struct file *file, const char __user *buf,
 	char *kbuf;
 	int err;
 
Quoted 8 lines

drivers/hwtracing/stm/core.c static ssize_t stm_char_write(struct file *file, const char __user *buf, · line 635

Quoted 3 lines
drivers/hwtracing/stm/core.c +1 -1
-	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

Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany