]> git.ipfire.org Git - thirdparty/linux.git/commit
fbdev: core: Fix pointer desynchronization in fb_io_read()
authorMingyu Wang <25181214217@stu.xidian.edu.cn>
Tue, 21 Jul 2026 08:19:42 +0000 (16:19 +0800)
committerHelge Deller <deller@gmx.de>
Sat, 8 Aug 2026 06:08:58 +0000 (08:08 +0200)
commit81cc73be40c6f028f1ee3f438ace46afe666dbae
tree4f0fc2b8ddd7926e3dd0aede0f9c36a20193a8aa
parent061db6b7a910b8378f3b2df64f8c0a3ddc6e85f2
fbdev: core: Fix pointer desynchronization in fb_io_read()

In fb_io_read(), if copy_to_user() performs a partial copy (e.g., due to
a faulty user buffer), the loop adjusts the chunk size 'c' and updates
the remaining 'count'. However, the hardware 'src' pointer has already
been eagerly advanced by the original chunk size.

If the loop is allowed to continue, the read will resume from an
incorrect, over-advanced offset. Since the remaining 'count' was only
decremented by the successful bytes, this desynchronization causes the
next iterations to execute more hardware reads than originally bounded,
eventually leading to out-of-bounds I/O reads.

Fix this by breaking out of the loop immediately upon a partial
copy_to_user(). A partial copy indicates a faulty user buffer, making
subsequent read attempts futile. Breaking out ensures we return the
number of successfully read bytes without risking out-of-bounds hardware
accesses in subsequent mismatched iterations.

Fixes: 6121cd9ef911 ("fbdev: Move I/O read and write code into helper functions")
Cc: stable@vger.kernel.org
Signed-off-by: Mingyu Wang <25181214217@stu.xidian.edu.cn>
Signed-off-by: Helge Deller <deller@gmx.de>
drivers/video/fbdev/core/fb_io_fops.c