--- linux-2.4.22-oM3-orig/mm/mremap.c Tue Mar 30 15:37:18 2004 +++ linux-2.4.22-oM3-mod/mm/mremap.c Tue Mar 30 16:35:01 2004 @@ -255,6 +255,13 @@ if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len) goto out; + /* + * Allow new_len == 0 only if new_addr == addr + * to preserve truncation in place (that was working + * safe and some app may depend on it). + */ + if (unlikely(!new_len && new_addr != addr)) + goto out; /* Check if the location we're moving into overlaps the * old location at all, and fail if it does. @@ -265,7 +272,9 @@ if ((addr <= new_addr) && (addr+old_len) > new_addr) goto out; - do_munmap(current->mm, new_addr, new_len, 1); + ret = do_munmap(current->mm, new_addr, new_len, 1); + if (ret && new_len) + goto out; } /* @@ -273,9 +282,11 @@ * the unnecessary pages.. * do_munmap does all the needed commit accounting */ - ret = addr; if (old_len >= new_len) { - do_munmap(current->mm, addr+new_len, old_len - new_len, 1); + ret = do_munmap(current->mm, addr+new_len, old_len - new_len, 1); + if (ret && old_len != new_len) + goto out; + ret = addr; if (!(flags & MREMAP_FIXED) || (new_addr == addr)) goto out; }