Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3019090pxu; Sat, 19 Dec 2020 09:08:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVea6VetuoiABQOWTDnL2UZN3hnhivp1gMUzMfdC8LY8u9LZ/2X8jsAW/tu5xWjxQL7SmH X-Received: by 2002:a17:906:a181:: with SMTP id s1mr9325486ejy.60.1608397697670; Sat, 19 Dec 2020 09:08:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608397697; cv=none; d=google.com; s=arc-20160816; b=UHICLuZLk5znYKuiDojZqDAcJz4cypV0GzZrL9RwdpmeYPzCKA2zYA3pGwlC4kpznP 6Xfbq9gmNqFsDAo1v5IdoAKO3gHuQbqf11upyStl08G10lkot3tRZCr4K8H6EOsi+Wvl 2GmJdtjtjrc8A2zR5SPb6xFXXhxW+/igg1j0mZHUaotSPjdjh27X37zex1oyWn1vKoAq X3nL3UASG6EaoiceOuKESth4G6IpWJzkMTuhG05ODFuTJl70/hQXK3I1OOReYIuFuaHJ 5lZufpWiGJUxb+nbqD+XEWLSVzktKLoLYq6Tbssptc9EEn8gjWzk8TPuRgd0R2xLMgam QkpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:cc:from:subject:mime-version:message-id:date :sender:dkim-signature; bh=vRLuXOIA8ra1QfYJtJa6fHDyAv5QMA5uNL7Qfw/l2xY=; b=FMN/BUc704Bsmdhl5T0/L+R1yuWqHFEv9pJI/cUDtBgcQ+WQu559qvLWfUt344zSMW R2jQnarMAyqK6WZEAmv4CT7sLdAg1rfIVmojPYP81+npaz6/10Fwpy9UuzYCE+0b9D8H sWCwsZ6NfPj5n48V3ZT8K/JFUudqgkdDE2L/JheJFE041sgqH4v/z65Ol+xlt+LBgObe hCeSvOkccveYeS7MJIAi/6kWvDQmj/7fJVwkcilLhvD6MyX62DwMo6tGWnf3YUxOXebz /u5HCDoVEzdR9uXYUlu0SJI8XCTFgDHYrI2kRZ6G3zVRwuc/t0HCCoWo9vY/zu3Hba8V UUrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HWimkrBO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lw15si6492957ejb.535.2020.12.19.09.07.55; Sat, 19 Dec 2020 09:08:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HWimkrBO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727086AbgLSRFv (ORCPT + 99 others); Sat, 19 Dec 2020 12:05:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726985AbgLSRFv (ORCPT ); Sat, 19 Dec 2020 12:05:51 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BBDAC0613CF for ; Sat, 19 Dec 2020 09:05:11 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id k7so8032471ybm.13 for ; Sat, 19 Dec 2020 09:05:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:cc; bh=vRLuXOIA8ra1QfYJtJa6fHDyAv5QMA5uNL7Qfw/l2xY=; b=HWimkrBOC8ZIriK9HG74tC08/J66mjh16qNL2u/hX9z4DtBTOI3PLS/VmIBgtHgm9+ oYOWiJCYs+V4J7ubKHvfBqo71hOpbfn4DiycoDKwTvIMnHjIiFmojmbOqYoVM348ILAa r0rE4NQvpACZFo/ZvJbqEazXPskml7zeyzemvEMNIsFtA3bzK0Ybs+BMzf/DksqTnGnF jwIf8UEnZ1A0sOhQTBhAg48XKATfgXZGk54r9+/IqMTjQjJcvSKPFHgZuYUKteGas+7x gxdKbWiHvF+h76pCj18NzcKdblvSJq0+cgFGNZSvusbXw5aQbjQyp3madF2aEfaFT8rX v1Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :cc; bh=vRLuXOIA8ra1QfYJtJa6fHDyAv5QMA5uNL7Qfw/l2xY=; b=fM/YaDBtYwzmuCIAbT4wW1nz50C+2ErcQ/DiG2H0+7x+O8+gh6cLYb+PoulHtjNZ/w CIhSk3nW1br8gRZap/vXqI90gfgIaQ/lRqn/UxzkQ76XuamcMmQ0emBQZFjcnUCwUGJk nBv+IbWCKk5Kpziomp0VQKgDmj19Zvoa83KyLT6WQ8W2n5Cy/IUKOmWeC/9DUGrZ9X7X u6nSKnH3q2bPUk9Qfs3EmgKVNqbFZVjiNvIqaz07OEFVBLUL217iK2uVSbC4aq+x6sYH h0BsJdP9GjRGKxd3T/FklWdF2S455F/HED5+RWnO2AN6mGsC7kbIsKfSQU2+zVsok2rh D/AA== X-Gm-Message-State: AOAM533K7O+jKLq2gMXybU1EXwc9HcsBu7rj60Q5YqO+yr2W1X0uN88I vwMZzgNwZHlOMaf4CzRxs5XdRJIsRfaLojDOQw== Sender: "kaleshsingh via sendgmr" X-Received: from kaleshsingh.c.googlers.com ([fda3:e722:ac3:10:14:4d90:c0a8:2145]) (user=kaleshsingh job=sendgmr) by 2002:a5b:812:: with SMTP id x18mr13542220ybp.334.1608397510135; Sat, 19 Dec 2020 09:05:10 -0800 (PST) Date: Sat, 19 Dec 2020 17:04:33 +0000 Message-Id: <20201219170433.2418867-1-kaleshsingh@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [PATCH] mm: mremap - Fix extent calculation From: Kalesh Singh Cc: surenb@google.com, minchan@kernel.org, joelaf@google.com, lokeshgidra@google.com, kaleshsingh@google.com, kernel-team@android.com, linux@roeck-us.net, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When `next < old_addr`, `next - old_addr` arithmetic underflows causing `extent` to be incorrect. Make `extent` the smaller of `next - old_addr` or `old_end - old_addr`. Reported-by: Guenter Roeck Signed-off-by: Kalesh Singh --- mm/mremap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index c5590afe7165..f554320281cc 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -358,7 +358,9 @@ static unsigned long get_extent(enum pgt_entry entry, unsigned long old_addr, next = (old_addr + size) & mask; /* even if next overflowed, extent below will be ok */ - extent = (next > old_end) ? old_end - old_addr : next - old_addr; + extent = next - old_addr; + if (extent > old_end - old_addr) + extent = old_end - old_addr; next = (new_addr + size) & mask; if (extent > next - new_addr) extent = next - new_addr; -- 2.29.2.729.g45daf8777d-goog