Skip to contentSkip to conversation

mm: make apply_to_page_range more robust

PATCH Superseded Mika Penttilä 3 participants 3 messages Jan 15, 2016 – Jan 19, 2016

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: make apply_to_page_range more robust

Recent changes (4.4.0+) in module loader triggered oops on ARM. While loading a module, size in :

apply_to_page_range(struct mm_struct *mm, unsigned long addr, unsigned
long size, pte_fn_t fn, void *data);

can be 0 triggering the bug BUG_ON(addr >= end);.

Fix by letting call with zero size succeed.

--Mika

Signed-off-by [email protected]

---

mm/memory.c +0 -0
index c387430..c3d1a2e 100644
@@ -1884,6 +1884,9 @@ int apply_to_page_range(struct mm_struct *mm,

unsigned long addr,

        unsigned long end = addr + size;
        int err;

+ if (!size)
+ return 0;
+

        BUG_ON(addr >= end);
        pgd = pgd_offset(mm, addr);
        do {

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Mika Penttilä

Recent changes (4.4.0+) in module loader triggered oops on ARM. While loading a module, size in :

apply_to_page_range(struct mm_struct *mm, unsigned long addr, unsigned
long size, pte_fn_t fn, void *data);

Quoted 7 lines

can be 0 triggering the bug BUG_ON(addr >= end);.

Fix by letting call with zero size succeed.

--Mika

Signed-off-by [email protected]

We could also replace that BUG_ON() with a WARN_ON() and return -EINVAL.

Quoted 18 lines

---

mm/memory.c +3 -0
index c387430..c3d1a2e 100644
@@ -1884,6 +1884,9 @@ int apply_to_page_range(struct mm_struct *mm,
 unsigned long addr,
        unsigned long end = addr + size;
        int err;
 
+       if (!size)
+               return 0;
+
        BUG_ON(addr >= end);
        pgd = pgd_offset(mm, addr);
        do {
Quoted 5 lines

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
In reply to Mika Penttilä
Quoted 29 lines · Mika PenttilA?

Recent changes (4.4.0+) in module loader triggered oops on ARM. While loading a module, size in :

apply_to_page_range(struct mm_struct *mm, unsigned long addr, unsigned
long size, pte_fn_t fn, void *data);

can be 0 triggering the bug BUG_ON(addr >= end);.

Fix by letting call with zero size succeed.

--Mika

Signed-off-by [email protected]

---

mm/memory.c +3 -0
index c387430..c3d1a2e 100644
@@ -1884,6 +1884,9 @@ int apply_to_page_range(struct mm_struct *mm,
 unsigned long addr,
        unsigned long end = addr + size;
        int err;
 
+       if (!size)
+               return 0;
+
        BUG_ON(addr >= end);
        pgd = pgd_offset(mm, addr);
Quoted 1 line
        do {

What is calling apply_to_page_range() with size == 0? I'm not sure we should be adding "robust"ness here and that size == 0 is actually an indication of a bug somewhere else that we want to know about.

Btw, your patch is line-wrapped and your sign-off-line doesn't include your full name.