Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4966397ybi; Tue, 30 Jul 2019 11:17:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqz64Xw70c0sdjxWYeq/nX4g1RrzL/cTxuN3KZT1U4J4wyxm/b3tykeEErf9906/TH21Zcac X-Received: by 2002:a17:90a:7d09:: with SMTP id g9mr3696628pjl.38.1564510624189; Tue, 30 Jul 2019 11:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564510624; cv=none; d=google.com; s=arc-20160816; b=M6M1lCMk1f+g6LNBSJ2gRgKBwejvVpLaQIh+HS0MrZY2ZYQsFkLMGPDxlNVe8NnOeh jqK2o3jdXuN3e4yiVD8ReZg+iWME6PmIwnLpJ5nD7Bd2qqNbTtukSQZRkf1aND137/YA VmLAskPg4FxDF7b7eD2V2iP52F1lPXkrkDEKQWDOGh84CH8FsuImYPDDNUPj/ayaKX1I g6U5vHCqy9DGZgikQLjRc2+HrjiCOmacJqgbq9DGOyDt0/tBhylT4dMWxDy20m9i/DcH Y1j4QXcgVwwcXmJKwldlmU4ixGJdlrU/KzBvDseQcwABw+320jregpZz3OtFYTrWiqN6 Co/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature; bh=zeF8/xIVDStEv2ZBDCCfoWWJXwtYX94jXKiOmwg+z8o=; b=biqg9VpkyyxHLurwE7EIsSFYCI0XsGfnmxRBZuFDTt1n9XUWWOvFavjsA6R4nTryCk TdLvi2BxuB202udjegcr1TrKcKeJk+z9I7OhLJGFgyGmztsFswyIjgaHR5D/hu51KbP8 X58XWaCB7XDISnurg37dXOpEfMc4LXqBOhGOzXGl73LYO8z13L4N+n6858jQTjNdoFHR PsqeY4QTJDIi+qU0YZ++r3+rzI3fYVgRhP/q+YsGL68xXgA/ezWouyJJP1M+VhtGP2e2 slRGfm8zDN2HSIkOkcCafiegkvdp75M+BdYmPkKqkd8BZoIM8asqQlpK4pOTp25y/aHP xxdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=GSBRgNvp; dkim=pass header.i=@codeaurora.org header.s=default header.b=HhkLI3mn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1si26997435plr.405.2019.07.30.11.16.49; Tue, 30 Jul 2019 11:17:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=GSBRgNvp; dkim=pass header.i=@codeaurora.org header.s=default header.b=HhkLI3mn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731798AbfG3RyX (ORCPT + 99 others); Tue, 30 Jul 2019 13:54:23 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:58972 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387450AbfG3RyW (ORCPT ); Tue, 30 Jul 2019 13:54:22 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 18C1660735; Tue, 30 Jul 2019 17:54:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1564509261; bh=SiHOslm33TKp3uM0b2CsOrfbOok3Z7O03LFNxQsXv/M=; h=From:To:Cc:Subject:Date:From; b=GSBRgNvpCIyCxN55XaPtvtff/kLeu4W3oYvjPtFdbS8ojNyO5XbaucHuwWQgg9Rt+ GyKh2zM6uHvFWkUk2vAKXRAc8oQHDWxUZ4PAA99UmU+MNRIIRVgjSdZD80pNzjZvXe 9j1lpOFee2Ivi2O7lZBD+bgT6c/Xxs+jkicD/uyQ= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED,SPF_NONE autolearn=no autolearn_force=no version=3.4.0 Received: from isaacm-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: isaacm@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id F3F9C60364; Tue, 30 Jul 2019 17:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1564509260; bh=SiHOslm33TKp3uM0b2CsOrfbOok3Z7O03LFNxQsXv/M=; h=From:To:Cc:Subject:Date:From; b=HhkLI3mnLCUAvo6B+gyuVgHIEoUFryU4bKpFS+qp4AwVZ3Ac7QNXZRSylqSO8lK/A eLdYQt8nc/CJHzTfrqDVNiWy31besAPLEAzMofVSM3pmOcpq8yuyZHvmdrrfe/nYEd g2Obgc+iVNjkBmpW/KOjhrJEY0XM3t+pA7ZtTxKk= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org F3F9C60364 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=isaacm@codeaurora.org From: "Isaac J. Manjarres" To: keescook@chromium.org, crecklin@redhat.com Cc: "Isaac J. Manjarres" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, psodagud@codeaurora.org, tsoni@codeaurora.org, eberman@codeaurora.org, stable@vger.kernel.org Subject: [PATCH] mm/usercopy: Use memory range to be accessed for wraparound check Date: Tue, 30 Jul 2019 10:54:13 -0700 Message-Id: <1564509253-23287-1-git-send-email-isaacm@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, when checking to see if accessing n bytes starting at address "ptr" will cause a wraparound in the memory addresses, the check in check_bogus_address() adds an extra byte, which is incorrect, as the range of addresses that will be accessed is [ptr, ptr + (n - 1)]. This can lead to incorrectly detecting a wraparound in the memory address, when trying to read 4 KB from memory that is mapped to the the last possible page in the virtual address space, when in fact, accessing that range of memory would not cause a wraparound to occur. Use the memory range that will actually be accessed when considering if accessing a certain amount of bytes will cause the memory address to wrap around. Fixes: f5509cc18daa ("mm: Hardened usercopy") Co-developed-by: Prasad Sodagudi Signed-off-by: Prasad Sodagudi Signed-off-by: Isaac J. Manjarres Cc: stable@vger.kernel.org Reviewed-by: William Kucharski Acked-by: Kees Cook --- mm/usercopy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/usercopy.c b/mm/usercopy.c index 2a09796..98e92486 100644 --- a/mm/usercopy.c +++ b/mm/usercopy.c @@ -147,7 +147,7 @@ static inline void check_bogus_address(const unsigned long ptr, unsigned long n, bool to_user) { /* Reject if object wraps past end of memory. */ - if (ptr + n < ptr) + if (ptr + (n - 1) < ptr) usercopy_abort("wrapped address", NULL, to_user, 0, ptr + n); /* Reject if NULL or ZERO-allocation. */ -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project