Skip to content

Commit 2dc705a

Browse files
keestorvalds
authored andcommitted
fbdev: color map copying bounds checking
Copying color maps to userspace doesn't check the value of to->start, which will cause kernel heap buffer OOB read due to signedness wraps. CVE-2016-8405 Link: http://lkml.kernel.org/r/20170105224249.GA50925@beast Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Kees Cook <keescook@chromium.org> Reported-by: Peter Pi (@heisecode) of Trend Micro Cc: Min Chong <mchong@google.com> Cc: Dan Carpenter <dan.carpenter@oracle.com> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com> Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 545d58f commit 2dc705a

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

‎drivers/video/fbdev/core/fbcmap.c‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,18 @@ void fb_dealloc_cmap(struct fb_cmap *cmap)
163163

164164
int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to)
165165
{
166-
int tooff = 0, fromoff = 0;
167-
int size;
166+
unsigned int tooff = 0, fromoff = 0;
167+
size_t size;
168168

169169
if (to->start > from->start)
170170
fromoff = to->start - from->start;
171171
else
172172
tooff = from->start - to->start;
173-
size = to->len - tooff;
174-
if (size > (int) (from->len - fromoff))
175-
size = from->len - fromoff;
176-
if (size <= 0)
173+
if (fromoff >= from->len || tooff >= to->len)
174+
return -EINVAL;
175+
176+
size = min_t(size_t, to->len - tooff, from->len - fromoff);
177+
if (size == 0)
177178
return -EINVAL;
178179
size *= sizeof(u16);
179180

@@ -187,17 +188,18 @@ int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to)
187188

188189
int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to)
189190
{
190-
int tooff = 0, fromoff = 0;
191-
int size;
191+
unsigned int tooff = 0, fromoff = 0;
192+
size_t size;
192193

193194
if (to->start > from->start)
194195
fromoff = to->start - from->start;
195196
else
196197
tooff = from->start - to->start;
197-
size = to->len - tooff;
198-
if (size > (int) (from->len - fromoff))
199-
size = from->len - fromoff;
200-
if (size <= 0)
198+
if (fromoff >= from->len || tooff >= to->len)
199+
return -EINVAL;
200+
201+
size = min_t(size_t, to->len - tooff, from->len - fromoff);
202+
if (size == 0)
201203
return -EINVAL;
202204
size *= sizeof(u16);
203205

0 commit comments

Comments
 (0)