From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754079AbbGAXFC (ORCPT ); Wed, 1 Jul 2015 19:05:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47245 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753880AbbGAXEj (ORCPT ); Wed, 1 Jul 2015 19:04:39 -0400 Date: Thu, 2 Jul 2015 01:03:14 +0200 From: Oleg Nesterov To: Andrew Morton Cc: Benjamin LaHaise , David Rientjes , Hugh Dickins , Jeff Moyer , Kirill Shutemov , Pavel Emelyanov , linux-kernel@vger.kernel.org Subject: [PATCH v2 5/5] mremap: simplify the "overlap" check in mremap_to() Message-ID: <20150701230314.GA18043@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150701230244.GA18003@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Minor, but this check is overcomplicated. Two half-intervals do NOT overlap if END1 <= START2 || END2 <= START1, mremap_to() just needs to negate this check. Signed-off-by: Oleg Nesterov Acked-by: David Rientjes --- mm/mremap.c | 9 ++------- 1 files changed, 2 insertions(+), 7 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index d3f42be..5a71cce 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -407,13 +407,8 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len, if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len) goto out; - /* Check if the location we're moving into overlaps the - * old location at all, and fail if it does. - */ - if ((new_addr <= addr) && (new_addr+new_len) > addr) - goto out; - - if ((addr <= new_addr) && (addr+old_len) > new_addr) + /* Ensure the old/new locations do not overlap */ + if (addr + old_len > new_addr && new_addr + new_len > addr) goto out; ret = do_munmap(mm, new_addr, new_len); -- 1.5.5.1