video: fbdev: sm712fb: Fix crash in smtcfb_read()
commit bd771cf5c4254511cc4abb88f3dab3bd58bdf8e8 upstream. Zheyu Ma reported this crash in the sm712fb driver when reading three bytes from the framebuffer: BUG: unable to handle page fault for address: ffffc90001ffffff RIP: 0010:smtcfb_read+0x230/0x3e0 Call Trace: vfs_read+0x198/0xa00 ? do_sys_openat2+0x27d/0x350 ? __fget_light+0x54/0x340 ksys_read+0xce/0x190 do_syscall_64+0x43/0x90 Fix it by removing the open-coded endianess fixup-code and by moving the pointer post decrement out the fb_readl() function. Reported-by: Zheyu Ma <zheyuma97@gmail.com> Signed-off-by: Helge Deller <deller@gmx.de> Tested-by: Zheyu Ma <zheyuma97@gmail.com> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
ba09b04173
commit
72af881092
@@ -1047,7 +1047,7 @@ static ssize_t smtcfb_read(struct fb_info *info, char __user *buf,
|
|||||||
if (count + p > total_size)
|
if (count + p > total_size)
|
||||||
count = total_size - p;
|
count = total_size - p;
|
||||||
|
|
||||||
buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL);
|
buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@@ -1059,24 +1059,13 @@ static ssize_t smtcfb_read(struct fb_info *info, char __user *buf,
|
|||||||
while (count) {
|
while (count) {
|
||||||
c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
|
c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
|
||||||
dst = buffer;
|
dst = buffer;
|
||||||
for (i = c >> 2; i--;) {
|
for (i = (c + 3) >> 2; i--;) {
|
||||||
*dst = fb_readl(src++);
|
u32 val;
|
||||||
*dst = big_swap(*dst);
|
|
||||||
dst++;
|
|
||||||
}
|
|
||||||
if (c & 3) {
|
|
||||||
u8 *dst8 = (u8 *)dst;
|
|
||||||
u8 __iomem *src8 = (u8 __iomem *)src;
|
|
||||||
|
|
||||||
for (i = c & 3; i--;) {
|
val = fb_readl(src);
|
||||||
if (i & 1) {
|
*dst = big_swap(val);
|
||||||
*dst8++ = fb_readb(++src8);
|
src++;
|
||||||
} else {
|
dst++;
|
||||||
*dst8++ = fb_readb(--src8);
|
|
||||||
src8 += 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
src = (u32 __iomem *)src8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copy_to_user(buf, buffer, c)) {
|
if (copy_to_user(buf, buffer, c)) {
|
||||||
|
Reference in New Issue
Block a user