From: Wu Fengguang <fengguang.wu@intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Wu Fengguang <fengguang.wu@intel.com>,
LKML <linux-kernel@vger.kernel.org>,
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: <linux-fsdevel@vger.kernel.org>
Subject: [PATCH 5/5] devmem: dont allow seek to last page
Date: Sat, 30 Jan 2010 17:45:20 +0800 [thread overview]
Message-ID: <20100130094958.141191239@intel.com> (raw)
In-Reply-To: 20100130094515.475881280@intel.com
[-- Attachment #1: mem-seek-fix --]
[-- Type: text/plain, Size: 1378 bytes --]
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: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
drivers/char/mem.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
--- linux-mm.orig/drivers/char/mem.c 2010-01-30 17:41:51.000000000 +0800
+++ linux-mm/drivers/char/mem.c 2010-01-30 17:42:29.000000000 +0800
@@ -721,16 +721,23 @@ static loff_t memory_lseek(struct file *
mutex_lock(&file->f_path.dentry->d_inode->i_mutex);
switch (orig) {
- case 0:
+ case SEEK_CUR:
+ offset += file->f_pos;
+ if ((unsigned long long)offset <
+ (unsigned long long)file->f_pos) {
+ ret = -EOVERFLOW;
+ break;
+ }
+ 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;
force_successful_syscall_return();
break;
- case 1:
- file->f_pos += offset;
- ret = file->f_pos;
- force_successful_syscall_return();
- break;
default:
ret = -EINVAL;
}
prev parent reply other threads:[~2010-01-30 9:45 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-30 9:45 [PATCH 0/5] [RESEND] FMODE_NONOTIFY and FMODE_NEG_OFFSET bits Wu Fengguang
2010-01-30 9:45 ` [PATCH 1/5] fanotify: fix FMODE_NONOTIFY bit number Wu Fengguang
2010-02-01 20:44 ` Andrew Morton
2010-01-30 9:45 ` [PATCH 2/5] bitops: compile time optimization for hweight_long(CONSTANT) Wu Fengguang
2010-02-01 20:48 ` Andrew Morton
2010-02-03 13:39 ` Wu Fengguang
2010-02-03 15:08 ` Andrew Morton
2010-02-03 15:15 ` Peter Zijlstra
2010-02-03 15:42 ` Andrew Morton
2010-02-03 15:47 ` Peter Zijlstra
2010-02-03 17:11 ` H. Peter Anvin
2010-02-03 18:14 ` Borislav Petkov
2010-02-03 18:47 ` Peter Zijlstra
2010-02-03 19:49 ` H. Peter Anvin
2010-02-04 15:10 ` Borislav Petkov
2010-02-04 15:13 ` Peter Zijlstra
2010-02-04 15:54 ` Borislav Petkov
2010-02-04 16:04 ` Peter Zijlstra
2010-02-05 12:11 ` Borislav Petkov
2010-02-05 12:14 ` Peter Zijlstra
2010-02-05 21:54 ` H. Peter Anvin
2010-02-06 9:36 ` Borislav Petkov
2010-02-07 1:55 ` H. Peter Anvin
2010-02-08 9:28 ` Borislav Petkov
2010-02-08 9:35 ` H. Peter Anvin
2010-02-08 9:59 ` Borislav Petkov
2010-02-11 17:24 ` Borislav Petkov
2010-02-11 17:33 ` H. Peter Anvin
2010-02-12 17:06 ` Borislav Petkov
2010-02-12 17:28 ` H. Peter Anvin
2010-02-12 17:47 ` Borislav Petkov
2010-02-12 19:05 ` H. Peter Anvin
2010-02-17 13:57 ` Michal Marek
2010-02-17 17:20 ` Borislav Petkov
2010-02-17 17:31 ` Michal Marek
2010-02-17 17:34 ` Borislav Petkov
2010-02-17 17:39 ` Michal Marek
2010-02-18 6:19 ` Borislav Petkov
2010-02-19 14:22 ` [PATCH] x86: Add optimized popcnt variants Borislav Petkov
2010-02-19 16:06 ` H. Peter Anvin
2010-02-19 16:45 ` Borislav Petkov
2010-02-19 16:53 ` H. Peter Anvin
2010-02-22 14:17 ` Borislav Petkov
2010-02-22 17:21 ` H. Peter Anvin
2010-02-22 18:49 ` Borislav Petkov
2010-02-22 19:55 ` H. Peter Anvin
2010-02-23 6:37 ` Borislav Petkov
2010-02-23 15:58 ` Borislav Petkov
2010-02-23 17:34 ` H. Peter Anvin
2010-02-23 17:54 ` Borislav Petkov
2010-02-23 18:17 ` H. Peter Anvin
2010-02-23 19:06 ` Borislav Petkov
2010-02-26 5:27 ` H. Peter Anvin
2010-02-26 7:47 ` Borislav Petkov
2010-02-26 17:48 ` H. Peter Anvin
2010-02-27 8:28 ` Borislav Petkov
2010-02-27 20:00 ` H. Peter Anvin
2010-03-09 15:36 ` Borislav Petkov
2010-03-09 15:50 ` Peter Zijlstra
2010-03-09 16:23 ` Borislav Petkov
2010-03-09 16:32 ` Peter Zijlstra
2010-03-09 17:32 ` Borislav Petkov
2010-03-09 17:37 ` Peter Zijlstra
2010-03-18 11:17 ` Borislav Petkov
2010-03-18 11:19 ` [PATCH 1/2] bitops: Optimize hweight() by making use of compile-time evaluation Borislav Petkov
2010-03-18 11:20 ` [PATCH 2/2] x86: Add optimized popcnt variants Borislav Petkov
2010-02-18 10:51 ` [PATCH 2/5] bitops: compile time optimization for hweight_long(CONSTANT) Peter Zijlstra
2010-02-18 11:51 ` Borislav Petkov
2010-02-14 10:12 ` Peter Zijlstra
2010-02-14 11:24 ` Borislav Petkov
2010-02-14 12:23 ` Peter Zijlstra
2010-02-14 14:19 ` Borislav Petkov
2010-02-14 18:36 ` H. Peter Anvin
2010-02-14 20:28 ` Borislav Petkov
2010-02-14 22:13 ` H. Peter Anvin
2010-02-04 15:16 ` H. Peter Anvin
2010-02-04 15:39 ` Brian Gerst
2010-02-03 17:10 ` H. Peter Anvin
2010-01-30 9:45 ` [PATCH 3/5] vfs: O_* bit numbers uniqueness check Wu Fengguang
2010-01-30 9:45 ` [PATCH 4/5] vfs: introduce FMODE_NEG_OFFSET for allowing negative f_pos Wu Fengguang
2010-01-30 9:45 ` Wu Fengguang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100130094958.141191239@intel.com \
--to=fengguang.wu@intel.com \
--cc=akpm@linux-foundation.org \
--cc=hirofumi@mail.parknet.co.jp \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).