Commit dcefafb6 authored by Wu Fengguang's avatar Wu Fengguang Committed by Linus Torvalds

/dev/mem: dont allow seek to last page

So as to return a uniform error -EOVERFLOW instead of a random one:

# kmem-seek 0xfffffffffffffff0
seek /dev/kmem: Device or resource busy
# kmem-seek 0xfffffffffffffff1
seek /dev/kmem: Block device required

Suggested by OGAWA Hirofumi.

Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Reviewed-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: default avatarWu Fengguang <fengguang.wu@intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2cb9a75d
...@@ -708,13 +708,20 @@ static loff_t memory_lseek(struct file * file, loff_t offset, int orig) ...@@ -708,13 +708,20 @@ static loff_t memory_lseek(struct file * file, loff_t offset, int orig)
mutex_lock(&file->f_path.dentry->d_inode->i_mutex); mutex_lock(&file->f_path.dentry->d_inode->i_mutex);
switch (orig) { switch (orig) {
case 0: case SEEK_CUR:
file->f_pos = offset; offset += file->f_pos;
ret = file->f_pos; if ((unsigned long long)offset <
force_successful_syscall_return(); (unsigned long long)file->f_pos) {
ret = -EOVERFLOW;
break; break;
case 1: }
file->f_pos += offset; case SEEK_SET:
/* to avoid userland mistaking f_pos=-9 as -EBADF=-9 */
if ((unsigned long long)offset >= ~0xFFFULL) {
ret = -EOVERFLOW;
break;
}
file->f_pos = offset;
ret = file->f_pos; ret = file->f_pos;
force_successful_syscall_return(); force_successful_syscall_return();
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment