From patchwork Wed Nov 14 00:51:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Isaac J. Manjarres" X-Patchwork-Id: 10681757 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4CC7139B for ; Wed, 14 Nov 2018 00:51:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25BA32B78F for ; Wed, 14 Nov 2018 00:51:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1986C2B7CE; Wed, 14 Nov 2018 00:51:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB2A12B7C3 for ; Wed, 14 Nov 2018 00:51:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A37376B0006; Tue, 13 Nov 2018 19:51:50 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9E6276B0008; Tue, 13 Nov 2018 19:51:50 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 888C46B000A; Tue, 13 Nov 2018 19:51:50 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 434836B0006 for ; Tue, 13 Nov 2018 19:51:50 -0500 (EST) Received: by mail-pg1-f200.google.com with SMTP id l131so9489971pga.2 for ; Tue, 13 Nov 2018 16:51:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:dkim-signature:dmarc-filter:from :to:cc:subject:date:message-id; bh=gYXGwcKJV7aoa4QH1PY4xPcQdgWLLJQLxzz6sUl+JTw=; b=ezUNfJn4x0cY2G2na4+W3smfKmGZgXQEKrCibPLE10+cSMCYf+IQL105Ex25hISD4Q 2hI/2kHiJxl5adWOPjiPIfdVGb5PDayG/o6XYM/vyvqnm699o5gudJGU59/z8Cjz2ElF EPYL2/Vp97b332X7lObHqN6dAhq7TreGGzHHNp8+FBtIsy747g41VvYEQD+OyR0AvvZR tXY2X20B6y2/XdyglBRVrnblCny8FBo8uU0T5xea1ciJw6oddWAzjG+hTC22zSBjUDY/ wO0X8+bU2JraXqxEeh2PgagO4v/tuUZGvMdMdeTTrubVh+ZnSWzJgEN4cgoSFl5TiWTN FlhQ== X-Gm-Message-State: AGRZ1gIaKgJC8PCh76u69u3XPgL6YQ3XHZQgYCtFEc9LDCzWcJTvBxwM 7TdQF9T4lJB0UmlotGVFCO/O3Ien6aAUzYu0e58R0PYFGU4MEUwx4OKL9lPQGOHArNAQHtOoQ5r qPdekwQmJr5cgQUHx3FczzFEXbjA4l0IuDponbg9VtbgpHzlMJg6ajgwJ/YtxjEtypQ== X-Received: by 2002:a62:5c41:: with SMTP id q62-v6mr7565750pfb.171.1542156709804; Tue, 13 Nov 2018 16:51:49 -0800 (PST) X-Google-Smtp-Source: AJdET5dqhBCulZixlMGxtbhbJMiXl2rTrBne38lKjF8mJdTuc7P6eLh2qf8K1HVljcnFib0Vs0Es X-Received: by 2002:a62:5c41:: with SMTP id q62-v6mr7565712pfb.171.1542156709042; Tue, 13 Nov 2018 16:51:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542156709; cv=none; d=google.com; s=arc-20160816; b=YTdlqsBhbWWIq6VGkx1E8fDQIfAr2Mmw2//F64ci40z5j8xtj2mp9bq9fBrLkRoUTN ltI8diCZyDNlZouxZZ4TARSO1d3OJ5HrEKlhYTK0MRmDcbevbDi4PI25gGEM0tQgWhkm sdHdwFLpwqAz1CwG8ADzmP6eRxdWW9AeGNsV8J/OAmv8LDSUDgHmcgopZGFe1/iXWNyE eTxI9kZzdDhTPxCW5Utvx4gWumMeW0sIs7kYlDJiX9ELM7cI4RrFPF+1O5Rn/gOvZug5 odlLl17AwNm3Dd/uMrrghGMtT8SfZccdhyIRjaRKCFAwoelSp+D7nBYCmuZWc98IoIkA +gyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dmarc-filter:dkim-signature :dkim-signature; bh=gYXGwcKJV7aoa4QH1PY4xPcQdgWLLJQLxzz6sUl+JTw=; b=S4p0heD7yU4zhBsOCObuby7fpxc64uJQWPwoqO4UFTyBim8UKa+lSq0rkQwIDQkQrx 5sat0fK0MKB99TG++CEoJUGTfNFUF4HcmGBXaLdLjLLeSfUn5ysM64/GKdTiIXiYItdz UO+F+Q4/O90MEwdwXzMfcPGA7ngm+/A7E7aJL1qaxPTpPxPQ6MZ9zIv0XfVmCKhEkjhX 7imv3P87UO+j4kSITz64SwSAjr/CW/JTLgxVgPMEk5NQfAz1WfzsurKkaxBkA5VT5F9K mLI3d0OqjvfV9KojgKvs+0jqrWFSd209WBC6YfO6shyAHmSMtZYPhQSbShBd3nZyc7g3 F9yQ== 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: domain of isaacm@codeaurora.org designates 198.145.29.96 as permitted sender) smtp.mailfrom=isaacm@codeaurora.org Received: from smtp.codeaurora.org (smtp.codeaurora.org. [198.145.29.96]) by mx.google.com with ESMTPS id x15-v6si21980538pll.41.2018.11.13.16.51.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Nov 2018 16:51:49 -0800 (PST) Received-SPF: pass (google.com: domain of isaacm@codeaurora.org designates 198.145.29.96 as permitted sender) client-ip=198.145.29.96; 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: domain of isaacm@codeaurora.org designates 198.145.29.96 as permitted sender) smtp.mailfrom=isaacm@codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 8F2176071B; 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= 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 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 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. */