/dev/mem: handle out-of-bounds read/write
authorPetr Tesarik <ptesarik@suse.cz>
Thu, 30 Jan 2014 08:48:02 +0000 (09:48 +0100)
committerJiri Slaby <jslaby@suse.cz>
Fri, 25 Apr 2014 16:40:45 +0000 (18:40 +0200)
commit3566e03b5bc9c06855b07423ab4c6e2710aa21e4
treea35a8928643b828670e58b973cabf2672890cd3b
parentde0b7b0dd1b625c8b4730869ae3d651e9189617c
/dev/mem: handle out-of-bounds read/write

commit 08d2d00b291ed4eb91530050274e67a761c1901d upstream.

The loff_t type may be wider than phys_addr_t (e.g. on 32-bit systems).
Consequently, the file offset may be truncated in the assignment.
Currently, /dev/mem wraps around, which may cause applications to read
or write incorrect regions of memory by accident.

Let's follow POSIX file semantics here and return 0 when reading from
and -EFBIG when writing to an offset that cannot be represented by a
phys_addr_t.

Note that the conditional is optimized out by the compiler if loff_t
has the same size as phys_addr_t.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
drivers/char/mem.c