Skip to contentSkip to conversation

+ pagemap-fix-buffer-overflow-in-add_page_map.patch added to -mm tree

PATCH [email protected] 1 participant 1 message Aug 12, 2013

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

Subject: + pagemap-fix-buffer-overflow-in-add_page_map.patch added to -mm tree
To: [email protected]
From: [email protected]
Date: Mon, 12 Aug 2013 16:05:45 -0700

The patch titled
Subject: fs/proc/task_mmu.c: fix buffer overflow in add_page_map()
has been added to the -mm tree. Its filename is
pagemap-fix-buffer-overflow-in-add_page_map.patch

This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/pagemap-fix-buffer-overflow-in-add_page_map.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/pagemap-fix-buffer-overflow-in-add_page_map.patch

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

The -mm tree is included into linux-next and is updated there every 3-4 working days

------------------------------------------------------
From: yonghua zheng <[email protected]>
Subject: fs/proc/task_mmu.c: fix buffer overflow in add_page_map()

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.

---

 fs/proc/task_mmu.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/proc/task_mmu.c renamed from fs/proc/task_mmu.c~pagemap-fix-buffer-overflow-in-add_page_map +2 -2
diff -puN fs/proc/task_mmu.c~pagemap-fix-buffer-overflow-in-add_page_map fs/proc/task_mmu.c
@@ -1127,8 +1127,8 @@ static ssize_t pagemap_read(struct file
 		goto out_task;
 
 	pm.v2 = soft_dirty_cleared;
-	pm.len = PM_ENTRY_BYTES * (PAGEMAP_WALK_SIZE >> PAGE_SHIFT);
-	pm.buffer = kmalloc(pm.len, GFP_TEMPORARY);
+	pm.len = (PAGEMAP_WALK_SIZE >> PAGE_SHIFT);
+	pm.buffer = kmalloc(pm.len * PM_ENTRY_BYTES, GFP_TEMPORARY);
 	ret = -ENOMEM;
 	if (!pm.buffer)
 		goto out_task;

_

Patches currently in -mm which might be from [email protected] are

pagemap-fix-buffer-overflow-in-add_page_map.patch pagemap-fix-buffer-overflow-in-add_page_map-fix.patch