diff options
author | yonghua zheng <younghua.zheng@gmail.com> | 2013-08-13 19:01:03 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-08-20 11:43:02 -0400 |
commit | f30d87b004dcb4b260dcb2667d5ef6998f4aac1f (patch) | |
tree | 047816d8caaa3557c6e18ae0f2bf789207457c92 /fs/proc | |
parent | f6c19e2f7d9204bca6576f03a117bec4eaaa9b5b (diff) |
fs/proc/task_mmu.c: fix buffer overflow in add_page_map()
commit 8c8296223f3abb142be8fc31711b18a704c0e7d8 upstream.
Recently we met quite a lot of random kernel panic issues after enabling
CONFIG_PROC_PAGE_MONITOR. After debuggind we found this has something
to do with following bug in pagemap:
In struct pagemapread:
struct pagemapread {
int pos, len;
pagemap_entry_t *buffer;
bool v2;
};
pos is number of PM_ENTRY_BYTES in buffer, but len is the size of
buffer, it is a mistake to compare pos and len in add_page_map() for
checking buffer is full or not, and this can lead to buffer overflow and
random kernel panic issue.
Correct len to be total number of PM_ENTRY_BYTES in buffer.
[akpm@linux-foundation.org: document pagemapread.pos and .len units, fix PM_ENTRY_BYTES definition]
Signed-off-by: Yonghua Zheng <younghua.zheng@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/proc')
-rw-r--r-- | fs/proc/task_mmu.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 3e636d864d56..65fc60a07c47 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c | |||
@@ -792,14 +792,14 @@ typedef struct { | |||
792 | } pagemap_entry_t; | 792 | } pagemap_entry_t; |
793 | 793 | ||
794 | struct pagemapread { | 794 | struct pagemapread { |
795 | int pos, len; | 795 | int pos, len; /* units: PM_ENTRY_BYTES, not bytes */ |
796 | pagemap_entry_t *buffer; | 796 | pagemap_entry_t *buffer; |
797 | }; | 797 | }; |
798 | 798 | ||
799 | #define PAGEMAP_WALK_SIZE (PMD_SIZE) | 799 | #define PAGEMAP_WALK_SIZE (PMD_SIZE) |
800 | #define PAGEMAP_WALK_MASK (PMD_MASK) | 800 | #define PAGEMAP_WALK_MASK (PMD_MASK) |
801 | 801 | ||
802 | #define PM_ENTRY_BYTES sizeof(u64) | 802 | #define PM_ENTRY_BYTES sizeof(pagemap_entry_t) |
803 | #define PM_STATUS_BITS 3 | 803 | #define PM_STATUS_BITS 3 |
804 | #define PM_STATUS_OFFSET (64 - PM_STATUS_BITS) | 804 | #define PM_STATUS_OFFSET (64 - PM_STATUS_BITS) |
805 | #define PM_STATUS_MASK (((1LL << PM_STATUS_BITS) - 1) << PM_STATUS_OFFSET) | 805 | #define PM_STATUS_MASK (((1LL << PM_STATUS_BITS) - 1) << PM_STATUS_OFFSET) |
@@ -1038,8 +1038,8 @@ static ssize_t pagemap_read(struct file *file, char __user *buf, | |||
1038 | if (!count) | 1038 | if (!count) |
1039 | goto out_task; | 1039 | goto out_task; |
1040 | 1040 | ||
1041 | pm.len = PM_ENTRY_BYTES * (PAGEMAP_WALK_SIZE >> PAGE_SHIFT); | 1041 | pm.len = (PAGEMAP_WALK_SIZE >> PAGE_SHIFT); |
1042 | pm.buffer = kmalloc(pm.len, GFP_TEMPORARY); | 1042 | pm.buffer = kmalloc(pm.len * PM_ENTRY_BYTES, GFP_TEMPORARY); |
1043 | ret = -ENOMEM; | 1043 | ret = -ENOMEM; |
1044 | if (!pm.buffer) | 1044 | if (!pm.buffer) |
1045 | goto out_task; | 1045 | goto out_task; |