Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6068339imu; Tue, 13 Nov 2018 16:52:54 -0800 (PST) X-Google-Smtp-Source: AJdET5eKGIeauk9jjPpPLSSFwnxiTU2QY+O3bAwbKBgMxHRL47emJKBaxjyF+nCY67IA9ePpsmZo X-Received: by 2002:a62:e219:: with SMTP id a25-v6mr4488438pfi.75.1542156774396; Tue, 13 Nov 2018 16:52:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542156774; cv=none; d=google.com; s=arc-20160816; b=U870QCugiz6XlIdvLRrJfDJd+5+MTbjcugR6lfBn157KaLOpWhJhSZ157nJD8htng9 96ubqKNfgjEOVEZmoj7WTro0l56Ke4gbt7/jHvx68kckVrQdggxh6T1BygSQyCiUDQ7h 6KMT9iuUh988ghMaTEZj/f3Q83TJhaDFNbBxbpMr8giuPWoRsF9Su3R2fUbZYqztp5Hz LsuAUlfJ0yEP/0LaMNbQE7emmJ62EP2aI/l5GYftt46VBD3Euq7QjC1IHQJvfmtDsU2F 8UQrK2aNwR+z2x3AxGkUsbbVjhzVFAdCbhcyZ2lRyoYs2VW5ipx6YZqcnfBlQ1gpYvE4 1flA== 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=gYXGwcKJV7aoa4QH1PY4xPcQdgWLLJQLxzz6sUl+JTw=; b=Bvr7aPQy+JTlXX2/ze1REVhrimzl67GJfO7GHVSYVBfD1l7zyAh+Sh7Ep8VZJZmUEf NLTzTJd3NO00oyWZK7WamtWBDrUv6DDLGckMbJGD7pATOpPGjQZXDfPtKbG0wyHqlqME Dxd1L1CPx4z61+OWwN4poken/wv3bJ/y0vgo5uaP0LwADf1O5ppoyYo7BVk2QoeYzSxv h+1wHK7PLvMGxJrbC88qYY/lHzbhu2gpPhtJkqfISCe7Z9e4xs+mZefBYI8wLRQKlcBc HioQEGGyc9iCMQwyAwGLkqagrLrWWF+gxQWaxplHxktWiyqCwe7o4ky/2mBfcns4D420 Winw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=MxSVb+tn; dkim=pass header.i=@codeaurora.org header.s=default header.b=MxSVb+tn; 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 g9-v6si21927993plo.328.2018.11.13.16.52.35; Tue, 13 Nov 2018 16:52:54 -0800 (PST) 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=MxSVb+tn; dkim=pass header.i=@codeaurora.org header.s=default header.b=MxSVb+tn; 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 S1731745AbeKNKwj (ORCPT + 99 others); Wed, 14 Nov 2018 05:52:39 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:43052 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726193AbeKNKwi (ORCPT ); Wed, 14 Nov 2018 05:52:38 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id B3DD3606DD; Wed, 14 Nov 2018 00:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1542156708; bh=ol9scosW61WusJViQsEkbLleT7CRNA63lOg1Ieicw0k=; h=From:To:Cc:Subject:Date:From; b=MxSVb+tn6Y6TXgNhTrUxyvuARXznpXEL8xmKQoaEl2bWtDFfcDvW0XJi44rflpaZg dcdTHBKQG/bE+dEGDVcc//Iq/O0S6/TVNuGofbIYsBuFCz3vu8wyYLWYNyFFDZLY3M HSjfNCoVAK+394CqyKF9KkBNPZYcAqDBrKCY7Zm8= 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 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 A79AB60452; Wed, 14 Nov 2018 00:51:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1542156708; bh=ol9scosW61WusJViQsEkbLleT7CRNA63lOg1Ieicw0k=; h=From:To:Cc:Subject:Date:From; b=MxSVb+tn6Y6TXgNhTrUxyvuARXznpXEL8xmKQoaEl2bWtDFfcDvW0XJi44rflpaZg dcdTHBKQG/bE+dEGDVcc//Iq/O0S6/TVNuGofbIYsBuFCz3vu8wyYLWYNyFFDZLY3M HSjfNCoVAK+394CqyKF9KkBNPZYcAqDBrKCY7Zm8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org A79AB60452 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, psodagud@codeaurora.org, tsoni@codeaurora.org, stable@vger.kernel.org Subject: [PATCH] mm/usercopy: Use memory range to be accessed for wraparound check Date: Tue, 13 Nov 2018 16:51:26 -0800 Message-Id: <1542156686-12253-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. Change-Id: I2563a5988e41122727ede17180f365e999b953e6 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 --- mm/usercopy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/usercopy.c b/mm/usercopy.c index 852eb4e..0293645 100644 --- a/mm/usercopy.c +++ b/mm/usercopy.c @@ -151,7 +151,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