Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1525228ybl; Thu, 22 Aug 2019 16:25:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyR0JYjcEgTp7s1NLfs9md+cj28brVxmjbrnEzsUy2xGUV67R6QuCZRloNNmIg6+8as+3ql X-Received: by 2002:a63:e48:: with SMTP id 8mr1374752pgo.389.1566516343775; Thu, 22 Aug 2019 16:25:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566516343; cv=none; d=google.com; s=arc-20160816; b=Z6ish+qZpbB1HLhYzQG3ol59IwcwKvNfSw4gkNHwCwj5jnD1zAbuGZ0qhtPDtuw71J O9ZdR4n1b5fpeN5E4yiG7qAqA7Pdihc5uYLPbdcDrcgzZTs8rZNqVbM6HWmchMTzxUk6 OERChHBRXDXR7MN4DHzBUIYhJ45FDAafuC3WhO9V9UdwrdcHFVbjRTFsJy31JvzwlQvw 5y2Wsm8z+zak3RN9MksEWlBEg3aqpCIQJKIfBVgSRoeFmRfPwQi54mY8eHjc5ADM2lLt buvQHhIUsCUKVHMY1wrQdRciiDvuuyA0szYXfZoW0ZGUoNkReNVMCsKRH+AIx9ttbKLd UKCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HRaZ18VTSABXJDo/gfAkWEaZkk5GuWK7Nv8pqibpZmg=; b=gV4v+h3D5pn+SjoE296DopO08WnN6KKHRRDNRfRYTxNFftD8Ol7qG/r/IWlXrW5SlB 5VpX9E3MQlo/DnT2kX3xmiz0AQIGOHRdaxblTnyaOlfN3U8exwV7JsOMvnnhvuLEAZDR nr3ugvCPzrPk9W5ZO7h7F2SXtXvBAmPxf4PuYR/mm15GGaouWzrS/7zoLQdBkSShZ4DY TTT2bDl1Wfspe6ABaXzNDYP+AOaLX8ZqdjN3CNJHFh9sgM8gu5SKXUaYsF2XovfVF78E mE4q4PfoOUdu8pGBfJBr1HBoDBwuyqMReMmqGDuxPYhHGoKqdsMlJxSq/Ucc+G65Ef/j I7PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UHAlcFdS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d24si778722plr.187.2019.08.22.16.25.28; Thu, 22 Aug 2019 16:25:43 -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=@kernel.org header.s=default header.b=UHAlcFdS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389743AbfHVRSD (ORCPT + 99 others); Thu, 22 Aug 2019 13:18:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:57750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390269AbfHVRIU (ORCPT ); Thu, 22 Aug 2019 13:08:20 -0400 Received: from sasha-vm.mshome.net (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D89F823404; Thu, 22 Aug 2019 17:08:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493700; bh=VsA1tRE7LS3MYwuj23vcDHayJKy/yZnl8/Iot3W2XJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UHAlcFdSi6ydMBSIkDFrXsfAftRxZkwF+uERuKLzOXWBaKRqoC11Ii4AqbbYp9hhE OiuF+ptu+tEBMeKLJrQbv31WAPJ0s+KbV0tOR0l5dAiRyKMIiYSBfmU0IOYisTT5dm RgJwKGhTmpdq+KcVvvqfpr+3Q+OzeUZ2usuzR6y0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Isaac J. Manjarres" , Prasad Sodagudi , William Kucharski , Kees Cook , Greg Kroah-Hartman , Trilok Soni , Andrew Morton , Linus Torvalds Subject: [PATCH 5.2 010/135] mm/usercopy: use memory range to be accessed for wraparound check Date: Thu, 22 Aug 2019 13:06:06 -0400 Message-Id: <20190822170811.13303-11-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822170811.13303-1-sashal@kernel.org> References: <20190822170811.13303-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.2.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.2.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.2.10-rc1 X-KernelTest-Deadline: 2019-08-24T17:07+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Isaac J. Manjarres" commit 951531691c4bcaa59f56a316e018bc2ff1ddf855 upstream. 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. Link: http://lkml.kernel.org/r/1564509253-23287-1-git-send-email-isaacm@codeaurora.org Fixes: f5509cc18daa ("mm: Hardened usercopy") Signed-off-by: Prasad Sodagudi Signed-off-by: Isaac J. Manjarres Co-developed-by: Prasad Sodagudi Reviewed-by: William Kucharski Acked-by: Kees Cook Cc: Greg Kroah-Hartman Cc: Trilok Soni Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/usercopy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/usercopy.c b/mm/usercopy.c index 2a09796edef8d..98e924864554c 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. */ -- 2.20.1